Durable.Helpers (Durable v0.1.0-rc)
View SourceHelper functions for working with workflow data in the pipeline model.
These functions provide a convenient, pipe-friendly API for updating the data that flows through workflow steps.
Usage
use Durable.HelpersThis imports all helper functions into your workflow module.
Examples
step :process, fn data ->
{:ok, data
|> assign(:status, :processing)
|> assign(%{started_at: DateTime.utc_now()})
|> increment(:step_count)}
end
Summary
Functions
Injects helper functions into the calling module.
Appends a value to a list in the data.
Merges a map into the data.
Assigns a value to a key in the data map.
Deletes a key from the data.
Gets a value from the data.
Gets a value from the data with a default.
Checks if a key exists in the data.
Increments a numeric value in the data.
Updates an existing value in the data using a function.
Updates a value in the data using a function.
Functions
Injects helper functions into the calling module.
Appends a value to a list in the data.
If the key doesn't exist, creates a new list with the value.
Examples
append(data, :items, new_item)
append(data, :events, %{type: :clicked, time: DateTime.utc_now()})
Merges a map into the data.
Examples
assign(data, %{order_id: 123, status: :pending})
Assigns a value to a key in the data map.
Examples
assign(data, :order_id, 123)
assign(data, "order_id", 123)
Deletes a key from the data.
Examples
delete(data, :temporary_value)
Gets a value from the data.
Returns nil if the key doesn't exist.
Examples
order_id = get(data, :order_id)
Gets a value from the data with a default.
Examples
count = get(data, :retry_count, 0)
Checks if a key exists in the data.
Examples
if has_key?(data, :order_id) do
# ...
end
Increments a numeric value in the data.
If the key doesn't exist, starts from 0.
Examples
increment(data, :retry_count)
increment(data, :total, 100)
Updates an existing value in the data using a function.
Raises if the key doesn't exist.
Examples
update(data, :count, &(&1 + 1))
Updates a value in the data using a function.
If the key doesn't exist, uses the default value.
Examples
update(data, :count, 0, &(&1 + 1))
update(data, :items, [], &[new_item | &1])