kittoframework / kitto

Kitto is a framework for interactive dashboards written in Elixir
http://kitto.io/dashboards/sample
MIT License
955 stars 58 forks source link

Cron style scheduling #115

Open davejlong opened 7 years ago

davejlong commented 7 years ago

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.

zorbash commented 7 years ago

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.

davejlong commented 7 years ago

Oooo that's a cool syntax for it!

On Wed, Jun 28, 2017 at 6:53 PM Dimitrios Zorbas notifications@github.com 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 .

zorbash commented 7 years ago

@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.