It is currently not possible to schedule a command using schedule_uuid that was previously cancelled:
iex> Scheduler.schedule_once(seat_id, %TimeoutSeatReservation{...}, ~N[2020-01-01 12:00:00])
:ok
iex> Scheduler.cancel_schedule(seat_id)
:ok
iex> Scheduler.schedule_once(seat_id, %TimeoutSeatReservation{...}, ~N[2020-01-01 14:00:00])
{:error, :already_scheduled}
This is because command handlers for scheduling are allowed only when the schedule aggregate instance does not exist yet:
def execute(%Schedule{schedule_uuid: nil} = schedule, %ScheduleOnce{} = once) do
...
end
def execute(%Schedule{}, %ScheduleOnce{}), do: {:error, :already_scheduled}
https://github.com/commanded/commanded-scheduler/blob/master/lib/commanded/scheduler/schedule/schedule.ex#L27
This means that if we need rescheduling, we need to generate a new random schedule_uuid for each new schedule and track it client side. This makes it a bit more difficult and doesn't guarantee schedule uniqueness (in the example above that we have a single active schedule per single seat), e.g.:
iex> Scheduler.schedule_once(seat_id, %TimeoutSeatReservation{...}, ~N[2020-01-01 12:00:00])
:ok
iex> Scheduler.cancel_schedule(seat_id)
:ok
iex> Scheduler.schedule_once(seat_id, %TimeoutSeatReservation{...}, ~N[2020-01-01 14:00:00])
:ok
iex> Scheduler.schedule_once(seat_id, %TimeoutSeatReservation{...}, ~N[2020-01-01 16:00:00])
{:error, :already_scheduled}
I believe it might also be useful to have some kind of rescheduling of a command, something like:
Scheduler.reschedule(seat_id, ~N[2020-01-01 14:00:00])
It is currently not possible to schedule a command using
schedule_uuidthat was previously cancelled:This is because command handlers for scheduling are allowed only when the schedule aggregate instance does not exist yet:
https://github.com/commanded/commanded-scheduler/blob/master/lib/commanded/scheduler/schedule/schedule.ex#L27
This means that if we need rescheduling, we need to generate a new random
schedule_uuidfor each new schedule and track it client side. This makes it a bit more difficult and doesn't guarantee schedule uniqueness (in the example above that we have a single active schedule per single seat), e.g.:I believe it might also be useful to have some kind of rescheduling of a command, something like: