Skip to content

Rescheduling commands #11

Open
Open
@gornik

Description

@gornik

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])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions