Hourglass.Worker.WorkflowTypeResolver (hourglass v0.1.0)

Copy Markdown View Source

Maps a Temporal Core WorkflowActivation to the Elixir workflow module that should evaluate it.

Two-tier lookup, in order:

  1. Structural resolution from the activation's initialize_workflow job. Every fresh start, and every replay-from-history delivery to a worker that doesn't yet have the workflow cached, includes an InitializeWorkflow job whose workflow_type field is the module's stringified atom (e.g. "Elixir.Hourglass.Workflows.IngestSource"). We recover the module atom via String.to_existing_atom/1 and verify it is a loaded Hourglass workflow by checking for the __workflow_input_type__/0 marker injected by use Hourglass.Workflow. No registration or module list is required — the type name IS the module.

  2. From the cached Workflow.State. Subsequent incremental activations (e.g. just a resolve_activity job) don't repeat the workflow type. By the time we receive one, the prior activation has already populated state.workflow_module via Hourglass.Workflow.Evaluator.evaluate/3. We look up WorkflowStateCache.fetch(task_queue, run_id) and return the stored module.

Both tiers fall through if exhausted; the function raises a clear error rather than guessing.

Summary

Functions

Resolve the workflow module for an activation.

Functions

resolve(activation, task_queue)

@spec resolve(Coresdk.WorkflowActivation.WorkflowActivation.t(), String.t()) ::
  module()

Resolve the workflow module for an activation.

See moduledoc for lookup order. Raises with a descriptive message when neither tier yields a module — that case indicates either an unknown/unloaded workflow type or a Core/cache invariant violation (e.g. an incremental activation arriving before any initialize_workflow ever populated the state cache).