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

Copy Markdown View Source

Adds an expiry workflow to a resource

Generates an expiry resource that moves to :expired once its expires_at passes, and back to :active when it is renewed. The subject gains has_one :expiry, an expired? calculation and a :set_expiry update action. When the subject does not exist, it is created with mix ash.gen.resource first.

A subject with no expiry never expires. :set_expiry creates the subject's expiry, or renews the one it has, through the generated Changes.SetExpiry change. Add that change with an expires_in: option to another subject action to start the clock there. --default-expiry adds it to every create of the subject.

Nobody may create or renew an expiry until the application defines who can, in the generated Checks.CanCreate and Checks.CanRenew modules.

Example

mix ash_workflow.gen.expiry MyApp.Contracts.Contract --notice-period 30d

Options

  • --module - the expiry resource's module name. Defaults to the subject's name with Expiry appended.
  • --domain - the domain for a subject the task creates. Required only when the subject does not exist.
  • --notice-period - moves an expiry to :expiring this long before expires_at, given as 10s, 30m, 12h, 2d or 2w. Without it, no :expiring step is generated.
  • --default-expiry - starts every new subject's expiry this long after it is created, given as 10s, 30m, 12h, 2d or 2w. The task adds change {Changes.SetExpiry, expires_in: ...}, on: [:create] to the subject's changes block. SetExpiry creates the expiry with the subject create's actor, so Checks.CanCreate must let that actor through, or the subject create fails. A subject create run with authorize?: false creates its expiry with authorize?: false too. Without the flag, nothing is added to the subject's create.
  • --transition-log - also generates a transition log for the expiry with mix ash_workflow.gen.transition_log. Defaults to true.