Laravel Task Scheduling has options like, everyMinute() which will run a command every minute. I want to know what is the time it actually starts executing. Is it when I run the server or any specific second of the minute?
I am trying to run a function depending on the time difference. Here's a pseudocode
Run myCustomFunction() if diffInMin(now, customTime) <= 1
I thought it will run 1 time but it ran twice every time.
The scheduler usually runs every minute right around the zero secound mark based on the server's current time as #apokryfos mentioned.
Assuming the customTime is a fixed DateTime, what makes you think the code you wrote will only run once?
When now() === customTime the diffInMin() would be zero so the
condition diffInMin(now, customTime) <= 1 will evaluate to true.
The next minute, the diffInMin() would be 1, so the
condition diffInMin(now, customTime) <= 1 will still evaluate to true.
Related
I saw this question online from an interview:
Suppose you have this code:
void myFunction(){
int time = clcTime();
while (clcTime()-time!=3600);
}
When clcTime() is a method that returns the seconds that passed since 00:00 of today.
(1). Find what this code snippet does.
(2). Some QA tester said this code fails at specific case. What's that case and how can you solve that issue?
(3). Another QA tester that during the day this code worked fine, but when he got to sleep - something went wrong. What can possibly be the problem and how can you solve it?
My attempt:
For (1), I think this function just suppose to run in a loop for an hour.
For (3), I think the problem is when the time variable get its value when the current hour of the day is in the range [23:00:00,23:59:59]. And that's because on that case, the value of time will be in the range [23*3600,23*3600 + 3599] and clcTime() can't return a matching value in the range [24*3600, 24*3600 + 3599]. So in that case, we know that the condition 'clcTime()-time' will never get a value of 3600 and we will get an infinite loop.
My suggestion for solving it is replacing the while line with those lines:
int measure = clcTime() - time;
int measureModulo = measure % 3600;
while (measure==0 || measureModulo!=0){
measure = clcTime() - time;
measureModulo = measure % 3600;
}
The only problem I still have is that I can't figure out (2) - I don't find any other problem with this code.
Do you have any idea what else can be problematic with this code?
Also, please feel free to correct me if I was wrong with what I wrote for (1) and (3).
Another problem with this code, and your fix, is that it checks clcTime() for an exactly matching value. If the system is busy and the loop doesn't get to run for more than a second, then it will miss the matching second and continue waiting for at least another hour.
Also there will be problems when the user changes the system clock or system time zone, when daylight savings time comes into or out of effect, when the clock is automatically adjusted for leap seconds, etc.
My Oracle DBA have setup a task with following repeat_interval:
Start Date :"30/JAN/20 08:00AM"
Repeat_interval: "FREQ=DAILY; INTERVAL=0; BYMINUTE=15"
Can I ask what is "Interval=0" means?
Does it means this task will run daily from 8AM, and will repeat every 15 mins until success?
I tried to get the answer from Google, but what I find is what is Interval=1, but nothing for 0.
So would be great if anyone can share me some light here.
Thanks in advance!
INTERVAL is the number of increments of the FREQ value between executions. I believe in this case that a value of 0 or 1 would be the same. The schedule as shown would execute once per day (FREQ=DAILY), at approximately 15 minutes past a random hour (BYMINUTE=15, but BYHOUR and BYSECOND are not set).
Schedule has nothing to do with whether or not the previous execution succeeded or not. Start Date is only the date at which the job was enabled, not when it actually starts processing.
If you want it to run every 15 minutes from the moment you enable it, you should set as follows:
FREQ=MINUTELY; INTERVAL=15
If you want it to run exactly on the quarter hour, then this:
FREQ=MINUTELY; BYMINUTE=0,15,30,45; BYSECOND=0
If you want it to run every day at 8am, then this:
FREQ=DAILY; BYHOUR=8; BYMINUTE=0; BYSECOND=0
How can I execute a function every 20us for example?
I aim to log the busy/free state on a CSMA channel using ns3::CsmaChannel::IsBusy (is that the best way to do it?) I have to call it at regular time interval to log each returned value and time.
You can use
simulator:: schedule function
to schedule function on a regular time interval
Simulator:: Schedule (Seconds(20.0), &function name, parameter1, parameter 2)
This is the syntax for scheduling an event for every 20 seconds
Can't get the max_failures idea. From the documentation:
This attribute specifies the number of times a job can fail on consecutive scheduled runs before it is automatically disabled.
So, let's suppose I have a schedule. Its running count is 100. Its failure count is 18. Its max failures is 20.
Current run has finished successfully.
I expect: if I will break it - it will run exactly 20 times on state FAILED after which it will be changed to BROKEN
What I get: it runs 2 times so failure count is 20 and despite the fact it were just 2 consecutive runs the schedule is changed to state BROKEN.
What have I missed?
I think "consecutive scheduled runs" means exactly that. If it succeeds, the failure count should be reset to 0.
EDIT
Guess I was wrong, sorry.
Reading up: http://download.oracle.com/docs/cd/E11882_01/server.112/e17120/schedadmin004.htm
As per Gary's comment - looks like you need to reset the failure count manually.
Greetings, your friendly neighborhood Quartz.NET n00b is back!
I have a Windows Service running iStatefulJob instances on a Quartz.NET CronTrigger based schedule scheme... The CRON String used to schedule the job: "0 0/1 * * * ? *"
Everything works great. However, if I have a job that is set to run, say, at the X:00 mark of every minute, and that job happens to run for MORE than a minute, I notice that the subsequent job runs IMMEDIATELY after the job is finished executing, rather than waiting until its next scheduled run, effectively "queuing" up instead of merely skipping the job till it's next scheduled run.
I put in the trigger a CronTrigger MisfireInstruction of DONOTHING, but the exact same thing happens when a job overruns its next scheduled execution schedule.
How do I get an iStatefulJob instance to merely SKIP a scheduled execution trigger if it is currently running, rather than have it delay it until the first execution completes?
I explicitly set the trigger.MisfireInstruction = MisfireInstruction.CronTrigger.DoNothing;
...But instead of "doing nothing", for a job scheduled to run every minute that takes 90 seconds to complete, I experience the following execution log:
Job runs at 9:00:00am, finishes at 9:01:30am <- job runs for 1:30
Job runs at 9:01:30am, finishes at 9:03:00am <- subsequent job that should have run at 9:01:00
Job runs at 9:04:00am, finishes at 9:05:30am <- shouldn't this one have run at 9:03:00?
Job runs at 9:05:30am, finishes at 9:07:00am <- subsequent job that should have run at 9:05:00
Job runs at 9:08:00am, finishes at 9:09:30am <- shouldn't this have run at 9:07:00?
... it seems like it runs correctly the first time, on the minute... delays for 30 seconds as the 90 second job execution time expires, and then, instead of waiting till the NEXT full minute, EXECUTES IMMEDIATELY at the 30 second mark... Doubly odd, is that it then finishes the SECOND job on the minute mark, but waits till the NEXT minute mark to execute instead of running it back-2-back...
Pretty much seems like it works correctly EVERY OTHER RUN, when it is not running on the :30 marks...
What's the best way to get a job not to delay/queue, but to just SKIP until it is idle and the next schedule matures?
EDIT: I tried going back to iJobs instead of iStatefulJobs using the same DONOTHING trigger misfire instruction, but the job executes EVERY MINUTE despite the prior execution being still active. I can't seem to get it to skip a scheduled run if it is currently running with either iJob or iStatefulJob...
EDIT#2: I think that my triggers are NEVER misfiring, which is why DoNothing as a misfire instruction is useless... Given that's the case, I guess I need another mechanism to detect if a job instance of a schedule is running to ensure the job SKIPS its next execution until its following scheduled time rather than delaying it until first instance completion...
EDIT3: I tried adding an element to the iStatefulJob jobdatamap called "IsRunning"... I set it to TRUE when the execute sequence starts, and then return it to false after job completion. Before executing, it checks the element, which is apparently persisted between jobs, and prematurely quits the execution (logging "JOB SKIPPED!") if it detects it to be true... This unfortunately doesn't work, for probably obvious reasons: If the jobs are running following the bulleted schedule above, then the job is never SIMULTANEOUSLY running along with itself, as it is delaying the run till the job ends, so this check is useless. According to documentation, returning to iJob from iStatefulJob would not help here as the jobdatamap is only persisted between jobs in the Stateful job type...
I still haven't solved how to SKIP a scheduled job instead of delaying it till it's current iteration completes... If anyone has ideas, you're a lifesaver! :)
It should be caused by misfireThreshold of RAMJobStore (http://quartznet.sourceforge.net/apidoc/topic2722.html).
The time span by which a trigger must
have missed its next-fire-time, in
order for it to be considered
"misfired" and thus have its misfire
instruction applied.
It is 60 seconds by default. So job isn't considered as "misfired" until it is late for more than misfiredThreshold value.
To resolve the problem just decrease this threshold (below code sets to 1 ms):
...
properties["quartz.jobStore.misfireThreshold"] = "1";
...
schedulerFactory = new StdSchedulerFactory(properties);
It should resolve the issue.