Schedule batch commands API
slashdotdash opened this issue · 0 comments
slashdotdash commented
Batch commands can be scheduled using the following Commanded.Scheduler.batch/2
function:
alias Commanded.Scheduler
Scheduler.batch(reservation_id, fn batch ->
batch
|> Scheduler.schedule_once(%TimeoutReservation{..}, timeout_due_at, name: "timeout")
|> Scheduler.schedule_once(%ReleaseSeat{..}, release_due_at, name: "release")
end)
Rather than require an anonymous function be used to configure the batch, it might be simpler to add a new Scheduler.Batch
module to construct the batch of scheduled commands:
alias Commanded.Scheduler
alias Commanded.Scheduler.Batch
batch =
reservation_id
|> Batch.new()
|> Batch.schedule_once(%TimeoutReservation{..}, timeout_due_at, name: "timeout")
|> Batch.schedule_once(%ReleaseSeat{..}, release_due_at, name: "release")
This could then be scheduled after construction:
Scheduler.schedule_batch(batch)