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

Ability to express cron schedule using fugit natural language parser #439

Closed
jgrau opened this issue Oct 29, 2021 · 1 comment · Fixed by #441
Closed

Ability to express cron schedule using fugit natural language parser #439

jgrau opened this issue Oct 29, 2021 · 1 comment · Fixed by #441

Comments

@jgrau
Copy link
Contributor

jgrau commented Oct 29, 2021

Hi Ben

First of all thank you for good_job 🙏 It's been running rock solid and I've recently migrated all my Kubernetes cron-jobs to good_job recurring tasks.

Question: Would you accept a pull request that made it possible to use the fugit natural language parser? Without having given it a lot of thought we could check in next_at whether cron is already an instance of Fugit::Cron. That way, in the schedule configuration you could do:

config.good_job.cron = {
  # Every 15 minutes, enqueue `ExampleJob.set(priority: -10).perform_later(42, name: "Alice")`
  frequent_task: { # each recurring job must have a unique key
    cron: Fugit::Nat.parse('every day at five'),
    class: "ExampleJob", # reference the Job class with a string
    args: [42, { name: "Alice" }], # arguments to pass; can also be a proc e.g. `-> { { when: Time.now } }`
    set: { priority: -10 }, # additional ActiveJob properties; can also be a lambda/proc e.g. `-> { { priority: [1,2].sample } }`
    description: "Something helpful", # optional description that appears in Dashboard (coming soon!)
  },
  another_task: {
    cron: "0 0,12 * * *",
    class: "AnotherJob",
  },
  # etc.
}

I realise it would couple the gem more tightly to fugit so I can totally understand if you feel the benefits are not worth it. :)

@bensheldon
Copy link
Owner

@jgrau yay! I'm really happy to know GoodJob is working out for you! 🎉

Would you accept a pull request that made it possible to use the fugit natural language parser? Without having given it a lot of thought we could check in next_at whether cron is already an instance of Fugit::Cron.

That sounds good to me 👍 I think it would involve two changes:

  1. Updating this method:
    def next_at
    fugit = Fugit::Cron.parse(cron)
    fugit.next_time.to_t
    end
  2. The logic to display the cron param in the Dashboard (maybe a #display_cron method)

(I could also imagine the cron param taking any object that responds to #next_time but let's consider that YAGNI for now)

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

Successfully merging a pull request may close this issue.

2 participants