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

Cron style scheduling #115

Open
davejlong opened this issue Jun 23, 2017 · 3 comments
Open

Cron style scheduling #115

davejlong opened this issue Jun 23, 2017 · 3 comments

Comments

@davejlong
Copy link
Member

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
Copy link
Member

zorbash commented Jun 28, 2017

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
Copy link
Member Author

davejlong commented Jun 29, 2017 via email

@zorbash
Copy link
Member

zorbash commented Jul 4, 2017

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

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

No branches or pull requests

2 participants