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

Copy Markdown View Source

Adds a dormancy workflow to a resource

Generates a dormancy resource that moves to :dormant once its last_activity_at is older than --dormant-after, and back to :active when it is reactivated. The subject gains has_one :dormancy, a dormant? calculation, and a changes block that runs the generated Changes.StartDormancy on every create, so each new subject gets a dormancy. Subjects created before the task ran need a backfill. When the subject does not exist, it is created with mix ash.gen.resource first.

The application decides what counts as activity, by adding the generated Changes.RecordActivity to subject actions or by calling the dormancy's record_activity action.

Nobody may create a dormancy directly or reactivate one until the application defines who can, in the generated Checks.CanCreate and Checks.CanReactivate modules. Changes.StartDormancy does not consult Checks.CanCreate.

Example

mix ash_workflow.gen.dormancy MyApp.Accounts.Account --dormant-after 90d --archive-after 180d

Options

  • --dormant-after - moves a dormancy to :dormant once last_activity_at is this old, given as 30m, 12h, 2d or 2w. A duration under a minute needs AshWorkflow.Scheduler.Precise. Required.
  • --archive-after - moves a dormancy to :archived once it has been :dormant this long. Without it, no :archived step is generated. A duration under a minute needs AshWorkflow.Scheduler.Precise.
  • --module - the dormancy resource's module name. Defaults to the subject's name with Dormancy appended.
  • --domain - the domain for a subject the task creates. Required only when the subject does not exist.
  • --transition-log - also generates a transition log for the dormancy with mix ash_workflow.gen.transition_log. Defaults to true.