Module: Attr::Gather::Workflow::Callable Private

Included in:
Attr::Gather::Workflow
Defined in:
lib/attr/gather/workflow/callable.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#call(input) ⇒ Concurrent::Promise<Hash>

Note:

For more information, check out https://dry-rb.org/gems/dry-monads/1.0/result

Execute a workflow

When executing the workflow, tasks are processed in dependant order, with the outputs of each batch being fed as inputs to the next batch. This means the you can enhance the data as the task moves through a workflow, so later tasks can use the enhanced input data.

Examples:

enhancer = MyEnhancingWorkflow.new
enhancer.call(user_id: 1).value! # => {user_id: 1, email: '[email protected]}

Parameters:

  • input (Hash)

Returns:

  • (Concurrent::Promise<Hash>)


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/attr/gather/workflow/callable.rb', line 28

def call(input)
  task_promises = {}

  final_results = self.class.tasks.to_a.map do |task|
    task_promises[task] = execute_task(input, task, task_promises)
  end

  Concurrent::Promise.zip(*final_results).then do |results|
    aggregator.call(input, results)
  end
end