0

I want to execute a cron after creation of some entity every 2 minutes and I should be able to stop it through code only. Is it possible ?

2
  • 1
    Have you looked at whenever? github.com/javan/whenever
    – sebkkom
    Commented Mar 16, 2015 at 17:20
  • 1
    Welcome to Stack Overflow. "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." Commented Mar 16, 2015 at 18:55

2 Answers 2

1

For the simplest way that I can think of right now that you can do what @tlehman said and add a "checking flag" in the code. (maybe just a simple variable inside a filename)

so before the cron started, it should check for a file with X variable with value true/false.

if true then it should run the code, if false then exit.

(you could then write another code to modify that "check file" to enable/disable the cron)

1
  • Thanks Firman. Can you please tell me how can i schedule a cron job in after_create filter of any model ??
    – Pankhuri
    Commented Mar 16, 2015 at 17:44
0

That sounds like a job for the whenever gem, you can use it's simple DSL like so:

every 2.minutes do
  runner "SomeRubyCommand.do_work"
end
2
  • how can i schedule a cron after creation of an entity and how can i stop it ? I don't want the process to remain forever.
    – Pankhuri
    Commented Mar 16, 2015 at 17:28
  • @firman-gautama has a solution, make the code depend on some flag, you could set the flag in your database.
    – tlehman
    Commented Mar 16, 2015 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.