Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rescheduling commands #11

Open
gornik opened this issue Jul 19, 2019 · 3 comments
Open

Rescheduling commands #11

gornik opened this issue Jul 19, 2019 · 3 comments

Comments

@gornik
Copy link

gornik commented Jul 19, 2019

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])
@slashdotdash
Copy link
Member

slashdotdash commented Jul 22, 2019

As you've discovered the current behaviour is by design (a command or batch may only be scheduled once), but it could be changed. I'm happy to accept a PR to add a Scheduler.reschedule function.

@gornik
Copy link
Author

gornik commented Jul 22, 2019

Thank you! I'll try to prepare a PR with support for rescheduling.

Regarding allowing a schedule to be scheduled again after cancellation: I think if we have rescheduling implemented, this would no longer be necessary, but still worth adding. Let me know what you prefer.

@slashdotdash
Copy link
Member

My preference would be to only allow rescheduling when the schedule is active.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants