mix ash_workflow.gen.sync (AshWorkflow v0.12.0)

Copy Markdown View Source

Adds a sync workflow to a resource

Generates a sync resource whose :syncing step runs a :push action, retries it on failure, and moves to :synced or :failed. A resync returns a synced or failed record to :syncing. The subject gains has_one :sync and a synced? calculation. When the subject does not exist, it is created with mix ash.gen.resource first.

Each subject create starts a sync through the generated Changes.StartSync. Each subject update requests a resync through the generated Changes.RequestSync, which stamps resync_requested_at on the sync. A timeout on :synced and :failed fires on that stamp, so a request made during a push runs once the push settles.

The generated :push action only stamps last_synced_at. Add the change that calls the external system to it. Nobody may create a sync directly or resync one until the application defines who can, in the generated Checks.CanCreate and Checks.CanResync modules.

Example

mix ash_workflow.gen.sync MyApp.Sales.Customer --max-attempts 5 --backoff 30s

Options

  • --module - the sync resource's module name. Defaults to the subject's name with Sync appended.
  • --domain - the domain for a subject the task creates. Required only when the subject does not exist.
  • --max-attempts - how many times :push runs before the sync moves to :failed. Defaults to 5.
  • --backoff - the delay between attempts, given as 10s, 30m, 12h, 2d, 2w or exponential. Defaults to exponential.
  • --fields - the subject fields whose change requests a resync, such as title,body. Defaults to every update requesting one.
  • --transition-log - also generates a transition log for the sync with mix ash_workflow.gen.transition_log. Defaults to true.