SchedulesModule
PackageFCQRS.Workflows
Schedules that start a registered workflow at each due time. A schedule is created, changed,
paused, resumed and deleted while the application runs, and is stored in the journal as an
aggregate named "fcqrs-schedule". The run for a due time is a workflow instance whose ID is the
schedule's ID, "@", and the due time in UTC in ISO 8601 ("O") form. A run starts at least once
per accepted due time, and a repeated start with its ID stores nothing.
Summary
| Name | Signature | Synopsis |
|---|---|---|
| MaxIdLength | MaxIdLength | The longest schedule ID, in characters: a run ID adds "@" and 28 characters of due time, the correlation IDs of a run's commands add up to 8 more, and a correlation ID holds at most 255. |
| MaxPersistenceIdLength | MaxPersistenceIdLength | The longest persistence ID: 255 characters, the size of the journal's column on PostgreSQL. |
| register | register api runs | Registers the schedule aggregate and starts this actor system's dispatcher, which may start the listed workflows. |
| create | create handle id workflow input rule catchUp | Creates the schedule `id`, which starts the workflow named `workflow` with `input` at each due time of `rule`, with `catchUp` deciding which missed due times run (`createLatest` uses the default, `CatchUp.Latest`). |
| createLatest | createLatest handle id workflow input rule | `create` with `CatchUp.Latest`, the default policy: after downtime, the schedule starts one run, for the most recent missed due time. |
| change | change handle id workflow input rule catchUp | Replaces the schedule's workflow, input, rule and catch-up policy. |
| pause | pause handle id | Stops the schedule from starting runs. |
| resume | resume handle id | Lets a paused schedule start runs again, from the first due time after the resume: due times inside the pause never run. |
| delete | delete handle id | Ends the schedule. |
| state | state handle id | The schedule as the dispatcher's index knows it, or nothing when the index has not read it. |
The longest schedule ID, in characters: a run ID adds "@" and 28 characters of due time, the
correlation IDs of a run's commands add up to 8 more, and a correlation ID holds at most 255.
The persistence IDs must fit too (see `MaxPersistenceIdLength`), and Akka escapes their
parts as `Uri.EscapeDataString` does, so `create` and `change` also require the escaped
workflow name and the escaped schedule ID to be at most 205 characters together. A
non-ASCII character escapes to 6 to 12 characters.
Returns
int
The longest persistence ID: 255 characters, the size of the journal's column on PostgreSQL.
A run journals as "<escaped workflow name>/default-shard/<escaped run ID>", which is 50
characters besides the escaped workflow name and schedule ID, and a schedule as
"fcqrs-schedule/default-shard/<escaped schedule ID>".
Returns
int
Registers the schedule aggregate and starts this actor system's dispatcher, which may start
the listed workflows. Register each workflow with `Workflows.register` first. Raises
`InvalidOperationException` when the actor system has a dispatcher already, and
`Akka.Configuration.ConfigurationException` when `akka.fcqrs.schedule-check-interval` is not
positive. A schedule whose workflow is not listed starts no run, and the dispatcher logs an
error at each of its due times, until a later start lists the workflow again.
The schedule aggregate, like every aggregate, waits for the actor system's saga starters
before it stores an event, and terminates the process when they are not wired within
`akka.fcqrs.saga-start-timeout`. Wire them with `Fcqrs.wireSagaStarters` after registering
every aggregate and saga, this one included. Until they are wired the dispatcher fires
nothing, and every function of this module that sends a command raises
`InvalidOperationException`.
The dispatcher keeps its index in the table `fcqrs_schedule_index`, which it creates on first
use in the journal's database and schema, with one row per schedule. A start reads the rows
and the schedule events stored since, so it does not read the schedules' whole history again.
The first start on a journal without the table reads that history once and fills the table.
Raises `ArgumentException` when Akka's query journal and write journal differ in connection
string, schema, table, or columns, because the table must live in the journal it reads.
Parameters
| Name | Type | Description |
|---|---|---|
| api | IActor | |
| runs | ScheduledWorkflow list |
Returns
ScheduleHandle
Creates the schedule `id`, which starts the workflow named `workflow` with `input` at each
due time of `rule`, with `catchUp` deciding which missed due times run (`createLatest` uses
the default, `CatchUp.Latest`). Returns once the schedule is stored. Raises
`ArgumentException` for a rule that `ScheduleRule.validate` rejects, a missing rule or policy,
or an ID that is blank, contains '~', or is too long (see `MaxIdLength`). Raises
`InvalidOperationException` when
the saga starters are not wired, when the workflow is not registered with the dispatcher or
takes another input, and when the schedule refuses: a schedule with this ID exists with a
different content, or was deleted. A repeat with the same content is accepted and stores
nothing; a weekly rule's days are sorted and their repeats removed before the comparison.
Parameters
| Name | Type | Description |
|---|---|---|
| handle | ScheduleHandle | |
| id | string | |
| workflow | string | |
| input | 'Input | |
| rule | ScheduleRule | |
| catchUp | CatchUp |
Returns
Async<unit>
`create` with `CatchUp.Latest`, the default policy: after downtime, the schedule starts one
run, for the most recent missed due time. Raises as `create` does. C#'s `CreateAsync` without
a policy calls it.
Parameters
| Name | Type | Description |
|---|---|---|
| handle | ScheduleHandle | |
| id | string | |
| workflow | string | |
| input | 'Input | |
| rule | ScheduleRule |
Returns
Async<unit>
Replaces the schedule's workflow, input, rule and catch-up policy. An `Every` rule counts from
the change, and no due time at or before it runs. A run decided before the change starts the
workflow, with the input, it was decided with. Raises `ArgumentException` and
`InvalidOperationException` as `create` does, and `InvalidOperationException` when the
schedule does not exist or was deleted.
Parameters
| Name | Type | Description |
|---|---|---|
| handle | ScheduleHandle | |
| id | string | |
| workflow | string | |
| input | 'Input | |
| rule | ScheduleRule | |
| catchUp | CatchUp |
Returns
Async<unit>
Stops the schedule from starting runs. A run decided before the pause still starts. Raises
`InvalidOperationException` when the schedule does not exist or was deleted.
Parameters
| Name | Type | Description |
|---|---|---|
| handle | ScheduleHandle | |
| id | string |
Returns
Async<unit>
Lets a paused schedule start runs again, from the first due time after the resume: due
times inside the pause never run. Raises `InvalidOperationException` when the schedule does
not exist, was deleted, or is not paused.
Parameters
| Name | Type | Description |
|---|---|---|
| handle | ScheduleHandle | |
| id | string |
Returns
Async<unit>
Ends the schedule. A run decided before the delete still starts. The ID cannot be used for a
new schedule. Raises `InvalidOperationException` when the schedule does not exist.
Parameters
| Name | Type | Description |
|---|---|---|
| handle | ScheduleHandle | |
| id | string |
Returns
Async<unit>
The schedule as the dispatcher's index knows it, or nothing when the index has not read it. A
deleted schedule leaves the index once no run decided before the delete waits to start.
The index lags the schedule by one projection pass, so a change that just returned may not
show yet.
Parameters
| Name | Type | Description |
|---|---|---|
| handle | ScheduleHandle | |
| id | string |
Returns
ScheduleView option