kitto icon indicating copy to clipboard operation
kitto copied to clipboard

Cron style scheduling

Open davejlong opened this issue 8 years ago • 3 comments

Feature request for the ability to schedule jobs in a cron style schedule.

Example Use Case

Schedule to post a message in a Text widget every day:

job :scrum, when: "30 9 * * 1-5", for: {15, :minutes} do
  broadcast! :scrum, %{text: "Time for scrum!"}
end

The expected functionality would be that at 9:30 on Monday through Friday the message "Time for scrum!" would be broadcasted to the :scrum event. The for key in the job setup would build a second job that would run 15 minutes later (9:45 Monday through Friday) that would clear the event from the cache allowing the text widget to go back to it's default value.

davejlong avatar Jun 23 '17 19:06 davejlong

We can support a cron-like interval format. We can even re-use some code from https://github.com/c-rack/quantum-elixir to support it.

Not so sure about the for key though, seems to specific to the actual use-case you have. What about supporting a then macro?

job :notify_about_scrum, cron: "30 9 * * 1-5" do
  broadcast! :scrum, %{text: "Time for scrum!"}
end |> then after: {15, :minutes} do
  broadcast! :reset, %{text: "relax! scrum's over"}
end

We don't even have to provide an after option, it can be a simple :timer.sleep inside then.

zorbash avatar Jun 28 '17 22:06 zorbash

Oooo that's a cool syntax for it!

On Wed, Jun 28, 2017 at 6:53 PM Dimitrios Zorbas [email protected] wrote:

We can support a cron-like interval format. We can even re-use some code from https://github.com/c-rack/quantum-elixir to support it.

Not so sure about the for key though, seems to specific to the actual use-case you have. What about supporting a then macro?

job :notify_about_scrum, cron: "30 9 * * 1-5" do broadcast! :scrum, %{text: "Time for scrum!"}end |> then after: {15, :minutes} do broadcast! :reset, %{text: "relax! scrum's over"}end

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kittoframework/kitto/issues/115#issuecomment-311814423, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKs1TJNju2R35mr3H_my5cUJg8D3GAtks5sItl6gaJpZM4OD84H .

davejlong avatar Jun 29 '17 04:06 davejlong

@davejlong I was thinking about this, implementing a then macro but it might be ambiguous as it could either mean:

  1. Schedule to run after the previous job schedule
  2. Run after the previous job has completed

I also think it might be more straightforward to use https://github.com/c-rack/quantum-elixir for cron-style scheduling in conjunction with Kitto jobs:

# File: config/config.exs
config :your_app, Sample.Scheduler,
  jobs: [{"30 9 * * 1-5", {ScheduledTasks, :opsgenie, []}}]
defmodule ScheduledTasks do
  import Kitto.Notifer, only: [broadcast!: 2]

  def opsgenie do
    broadcast! :opsgenie, %{alert: "Server is down"}
  end
end

It might be worth it writing a wiki guide about this, to provide a working solution first.

zorbash avatar Jul 04 '17 08:07 zorbash