Sagents.Closures (Sagents v0.16.2)

Copy Markdown

Finds anonymous functions that the local node cannot call.

An anonymous function is a reference to a compiled module, not a copy of its code. It carries the MD5 of the module version that created it, and it can only be called on a node that has that exact version loaded. A function built on one node and sent to a node running a different build of the module raises BadFunctionError when called.

An agent's configuration carries such functions (tool functions, callbacks, middleware config), and under the :horde distribution it crosses nodes: a start may be placed on another member, and a departed node's agents are restarted on a survivor from the arguments of the original start. During a rolling deploy those nodes run different builds.

Captures of named functions (&Mod.fun/2) are resolved by name when called, so they are callable on any node that has the module and are never reported.

Summary

Functions

Returns the modules whose anonymous functions inside term cannot be called on this node, or [] when every function in term is callable.

Functions

stale_modules(term)

@spec stale_modules(term()) :: [module()]

Returns the modules whose anonymous functions inside term cannot be called on this node, or [] when every function in term is callable.

Walks lists, tuples, maps, structs, and the values each function closes over.

Examples

iex> Sagents.Closures.stale_modules(%{tools: [&String.upcase/1], name: "agent"})
[]