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

Question: Runtime jobs performed at the same time #336

Closed
mertkahyaoglu opened this issue Apr 2, 2018 · 6 comments
Closed

Question: Runtime jobs performed at the same time #336

mertkahyaoglu opened this issue Apr 2, 2018 · 6 comments
Labels

Comments

@mertkahyaoglu
Copy link

Hello everyone,

In my project, I'm adding a new job that runs every 10 seconds for every POST requests. Although these jobs are added in different times, they are executed at the same. The newly added ones are waiting for the first one to execute altogether. How can I make these jobs run independent from each other? I apologize if there is already an easy solution for this that I missed.

Here is the code that I'm using from the docs;

Notifi.Scheduler.new_job()
      |> Quantum.Job.set_name(:crawler)
      |> Quantum.Job.set_schedule(~e[*/10 * * * * *]e)
      |> Quantum.Job.set_task(fn -> IO.puts "tick:" <> params["id"] end)
      |> Notifi.Scheduler.add_job()
@c-rack c-rack added the question label Apr 2, 2018
@mertkahyaoglu mertkahyaoglu changed the title Problem: Runtime jobs performed at the same time Question: Runtime jobs performed at the same time Apr 2, 2018
@c-rack
Copy link
Member

c-rack commented Apr 2, 2018

Have you tried to give your job distinct names?

@mertkahyaoglu
Copy link
Author

@c-rack Yes, I did but it didn't work.

Quantum.Job.set_name(params["id"] |> String.to_atom)

@maennchen
Copy link
Member

@mertkahyaoglu What do you mean when you say that they are waiting for the first one?

They should all be executed at the same time (always at full 10 seconds (00, 10, 20, 30, 40, 50).

@mertkahyaoglu
Copy link
Author

mertkahyaoglu commented Apr 4, 2018

They should all be executed at the same time (always at full 10 seconds (00, 10, 20, 30, 40, 50).

@maennchen I don't want them to be executed at the same time. For example I add a job which is meant to run for every 10 seconds. After 5 seconds I add another job. I expect to see the last job to be executed 10 seconds after it is created but it is executed after 5 seconds together with the first one.

How can these jobs be executed independently?

@maennchen
Copy link
Member

maennchen commented Apr 4, 2018

@mertkahyaoglu The schedule ~e[*/10 * * * * *]e means something like At every 10th second.

There is no easy way to schedule something every 10 seconds after it was scheduled.

This is also why we opened the issue #268.

If you really want to use it this way, you could implement it via a little hack (pseudo code, not tested):

Edit: Corrected Code

%{second: second} = NaiveDateTime.utc_now()
second_remainder = rem(second, 10)
seconds = [
  second_remainder,
  second_remainder + 10,
  second_remainder + 20,
  second_remainder + 30,
  second_remainder + 40,
  second_remainder + 50
]
schedule = Crontab.CronExpression.Parser.parse!(Enum.join(seconds, ","), true)

Notifi.Scheduler.new_job()
|> Quantum.Job.set_name(:crawler)
|> Quantum.Job.set_schedule(schedule)
|> Quantum.Job.set_task(fn -> IO.puts "tick:" <> params["id"] end)
|> Notifi.Scheduler.add_job()

@maennchen
Copy link
Member

@mertkahyaoglu Since this is already covered by #268, I'll close the issue.

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

No branches or pull requests

3 participants