View Source Lightning.AdaptorRegistry (Lightning v2.10.4)

Registry process to query and maintain a list of adaptors available for writing jobs.

Currently it queries NPM for all modules in the @openfn organization and filters out modules that are known not to be adaptors.

Usage

# Starting the process
AdaptorRegistry.start_link()
# Getting a list of all adaptors
Lightning.AdaptorRegistry.AdaptorRegistry.all()

Caching

By default the results are cached to disk, and will be reused every start.

In order to disable or configure caching pass see: start_link/1.

The process uses :continue to return before the adaptors have been queried. This does mean that the first call to the process will be delayed until the handle_continue/2 has finished.

Timeouts

There is a 'general' timeout of 30s, this is used for GenServer calls like all/1 and also internally when the modules are being queried. NPM can be extremely fast to respond if the package is cached on their side, but can take a couple of seconds if not cached.

Summary

Functions

Get the current in-process list of adaptors. This call will wait behind the :continue message when the process starts up, so it may take a while the first time it is called (and the list hasn't been fetched yet).

Returns a specification to start this module under a supervisor.

Fetch a list of packages for the @openfn organisation

Get a latest version for a given module.

Destructures an NPM style package name into module name and version.

Same as resolve_package_name/1 except will throw an exception if a package name cannot be matched.

Starts the AdaptorRegistry

Get a list of versions for a given module.

Functions

Link to this function

all(server \\ __MODULE__)

View Source
@spec all(server :: GenServer.server()) :: list()

Get the current in-process list of adaptors. This call will wait behind the :continue message when the process starts up, so it may take a while the first time it is called (and the list hasn't been fetched yet).

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec fetch() :: [map()]

Fetch a list of packages for the @openfn organisation

Link to this function

latest_for(server \\ __MODULE__, module_name)

View Source
@spec latest_for(server :: GenServer.server(), module_name :: String.t()) ::
  list() | nil

Get a latest version for a given module.

Link to this function

resolve_adaptor(adaptor)

View Source
Link to this function

resolve_package_name(package_name)

View Source
@spec resolve_package_name(package_name :: nil) :: {nil, nil}
@spec resolve_package_name(package_name :: String.t()) ::
  {binary() | nil, binary() | nil}

Destructures an NPM style package name into module name and version.

Example

iex> resolve_package_name("@openfn/language-salesforce@1.2.3")
{ "@openfn/language-salesforce", "1.2.3" }
iex> resolve_package_name("@openfn/language-salesforce")
{ "@openfn/language-salesforce", nil }
Link to this function

resolve_package_name!(package_name)

View Source
@spec resolve_package_name!(package_name :: String.t()) :: {binary(), binary() | nil}

Same as resolve_package_name/1 except will throw an exception if a package name cannot be matched.

Link to this function

start_link(opts \\ [use_cache: true])

View Source
@spec start_link(opts :: [use_cache: boolean() | binary(), name: term()]) ::
  {:error, any()} | {:ok, pid()}

Starts the AdaptorRegistry

Options

  • :use_cache (defaults to false) - stores the last set of results on disk and uses the cached file for every subsequent start. It can either be a boolean, or a string - the latter being a file path to set where the cache file is located.
  • :name (defaults to AdaptorRegistry) - the name of the process, useful for testing and/or running multiple versions of the registry
Link to this function

versions_for(server \\ __MODULE__, module_name)

View Source
@spec versions_for(server :: GenServer.server(), module_name :: String.t()) ::
  list() | nil

Get a list of versions for a given module.