Rails enqueue jobs and execute after x time from previous - ruby-on-rails

I have a rails api app where receives a bunch of requests and then, for each, it executes a job, but I want to prevent it job being called immediately, I need it delay 2 seconds. So for that I have MyAwesomeJob.perform_in(2.seconds, stuff). So looking to sidekiq it goes right after 2 seconds. But next request goes right away.
What I need is: having 10 requests in 1 second it should enqueue 10 jobs and execute it one after other. (first gonna be in 2 seconds, next should wait last finish and go, so 4 seconds, 6seconds etc....)
Thanks!

Related

How to catch a signal multiple times in BonitaSoft?

I'm calling from Signal5 to Signal2 until the number of calls is 10 (XOR Gateway).
But the problem is that Signal3 call Signal4 two times and the process is lost.
I think that the first pool is waiting for some action or the signals can be called only once.
As there is no action running in parallel maybe a design with a call activity (Step 3 on my diagram below) might answer what you want to achieve:

Quartz scheduling queues up missed scheduled jobs

I have a quartz job schedule like so:
_scheduler.ScheduleJob(job,
TriggerBuilder.Create().ForJob(job)
.WithSimpleSchedule(x =>
x.WithIntervalInSeconds(requeryTime.ToInt32())
.RepeatForever()
.WithMisfireHandlingInstructionNowWithRemainingCount()
)
.StartNow()
.Build())
To test I have the schedule run every 10 seconds. If I pause the service and then resume, I can still see all the jobs being called one after another. I want Quartz to ignore (do not queue) the jobs and just resume the schedule.
e.g. If the job runs every 10 secs and I pause the service for 1 minute, I get 6 jobs run in quick succession.
How do I go about ensuring Quartz ignores those jobs?
Short answer is to change the misfireThreshold in the configuration:
<add key="quartz.jobStore.misfireThreshold" value="60000" />
The default is 60000 milliseconds (60 seconds).
org.quartz.jobStore.misfireThreshold
The the number of milliseconds the scheduler will 'tolerate' a trigger
to pass its next-fire-time by, before being considered "misfired". The
default value (if you don't make an entry of this property in your
configuration) is 60000 (60 seconds).
Since your trigger runs every 10 seconds you can reduce the threshold to 9 seconds and it should work as you expect.
If you want to learn more about the strategies involved you can read this article and this one as well.
A similar question has been asked recenlty and Circular Reference gave a really good answer.

dart timer periodic documentation is confusing

I have a long running task and I would like to schedule a new run a fixed interval after the run ends and I found this. What does the following mean? In particular the last paragraph.
Timer.periodic(Duration duration, Function void callback(Timer timer))
Creates a new repeating timer.
The callback is invoked repeatedly with duration intervals until
canceled with the cancel function.
The exact timing depends on the underlying timer implementation. No
more than n callbacks will be made in duration * n time, but the time
between two consecutive callbacks can be shorter and longer than
duration.
In particular, an implementation may schedule the next callback, e.g.,
a duration after either when the previous callback ended, when the
previous callback started, or when the previous callback was scheduled
for - even if the actual callback was delayed.
Let's say you set a timer to run every 30 seconds. If the second time the callback is called it takes 10 seconds to complete, the third call to the callback could be:
30 seconds after the second call started
30 seconds after the second call ended (which is 40s after the second call started, since it took 10 secs)
30 seconds after the second call was scheduled to run (which based on the above, could have been delayed, eg. by the duration of the first call)
Timer's duration is delay. Timer.periodic's duration is period.

Windows Phone 8.1 - GeofenceState.Exited

I want to ask how is GeofenceState.Exited intended?
When I have a background task with GeofenceState.Entered, when I move inside the circle, I get IBackgroundTask.Run() run every 2 minutes (why 2 minutes?)
But with GeofenceState.Exited, I can walk miles, but it never gets triggered. Is there some bug, or is that intended differently than I suppose? I guess it should work this way: when the check is done after 2 minutes, when I'm outside of the circle, the method Run is called.
I have a parameter 50 and dwell time 1 sec.
Thanks

NSTimer to control a series of events

Can NSTimer be used to fire a series of events. For instance for effect:
Its kick off Click start to toss
create random number
wait 5 seconds show result
wait 3 seconds start the match?
You can use it to repeat at a given interval, but not a variable one. If you really wanted to wait 5 seconds and then then wait another 3 seconds you'd probably want to chain timers. So, when the first timer fires and calls a message, that message creates a second timer with a different time interval.
This is actually a case where the Prototype Pattern would apply: make an NSTimer and set it up with all the properties you want, and then clone that object each time you need to make another. Or you could just make a factory. Objective C does not have a clone, but the NSCoding protocol is actually a workable and proper way of doing cloning (unlike Java's broken (and abandoned) clone interface).

Resources