Kira v0.1.1 Kira

The main public interface of this library, with the exception of the Kira.Branch module.

Link to this section Summary

Functions

Used to execute the tasks you have defined

Link to this section Functions

Link to this function run_tasks(config, tasks, timeout \\ :infinity)
run_tasks(config :: any(), tasks :: [Kira.Branch.t()], timeout :: timeout()) ::
  Kira.Util.result(map())

Used to execute the tasks you have defined.

Arguments

  • config, can be treated as common information shared between tasks. This is where you may handle dependency injection or whatever.

  • tasks, basically the stuff you care about. Pass in an array of Branch’s and the library will organise the order in which they’ll run.

  • timeout, basically a timeout in the case where no activity takes place inside the state machine used to coordinate tasks.

Example

require Kira
require Logger

task_a = %Kira.Branch{
  name: :get_a,
  apply: fn (config, deps) ->
    Logger.info(inspect(config))
    {:ok, 2}
  end,
}

task_b = %Kira.Branch{
  name: :get_b,
  apply: fn (config, deps) ->
    Logger.info(inspect(config))
    {:ok, 3}
  end,
}

task_c = %Kira.Branch{
  name: :get_c,
  dependencies: [:get_a, :get_b],
  apply: fn (config, deps) ->
    Logger.info(inspect(config))
    {:ok, deps[:get_a] + deps[:get_b]}
  end,
}

tasks = [task_a, task_b, task_c]
{:ok, results} = Kira.run_tasks(:my_config, tasks)
Logger.info(inspect(results))

# Should log
# 1: :my_config
# 2: :my_config
# 3: :my_config
# 4: %{ :get_a => 2, :get_b => 3, :get_c => 5 }