schedule

abstract fun schedule(key: String, rule: ScheduleRule, command: Any, target: AggregateRef)

Schedules command to be sent to target, this aggregate by default, as rule says: at an instant, after a delay counted from this commit, or by a cron expression. key names the schedule within this aggregate: scheduling a key again replaces it (a reschedule, or a new rule), and cancelSchedule cancels it. Within one decision the last call for a key wins.

The schedule commits with this command's events (as the system event wow.schedule.ScheduleSet), or not at all. Each time it is due the command is sent at least once, not before its time, possibly a little later (after a handover or a backlog), and decided once: its request id is the timer's id and the slot (ScheduleContext, which the target reads from Command.schedule). The target decides it on its state then; a rejection is a normal guard, not a failure. Its scope is this commit's, its causation this commit. A target of another context needs its context's Manifest.

target names its tenant too: a ref of another tenant's aggregate schedules the command into that tenant, as a saga's request names its targetTenant, but for a type of a fixed tenant, which refuses another. Which tenants a schedule may reach is the domain's to decide: build target from what the aggregate holds, or check one that comes from the command before it is scheduled.

A cron rule whose expression or time zone cannot be read, or that names no time that ever comes (0 0 0 30 2 *), is the code's mistake: the command fails and commits nothing. A rule from input is checked by the domain before it is scheduled, so that its decide function rejects it with a rejection of its own.


open fun schedule(key: String, rule: ScheduleRule, command: Any)

Schedules command for this aggregate under key as rule says; see schedule of a target.