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 withExpiryappended.--domain- the domain for a subject the task creates. Required only when the subject does not exist.--notice-period- moves an expiry to:expiringthis long beforeexpires_at, given as10s,30m,12h,2dor2w. Without it, no:expiringstep is generated.--default-expiry- starts every new subject's expiry this long after it is created, given as10s,30m,12h,2dor2w. The task addschange {Changes.SetExpiry, expires_in: ...}, on: [:create]to the subject'schangesblock.SetExpirycreates the expiry with the subject create's actor, soChecks.CanCreatemust let that actor through, or the subject create fails. A subject create run withauthorize?: falsecreates its expiry withauthorize?: falsetoo. Without the flag, nothing is added to the subject's create.--transition-log- also generates a transition log for the expiry withmix ash_workflow.gen.transition_log. Defaults totrue.