cron golang is running after every 24 hours but when I am trying to change the system time, it is not invoking.
code:
package main;
import(
"fmt"
"strconv"
"strings"
"gopkg.in/robfig/cron.v2"
"time"
)
func Envoke_ASSET_INFO() {
fmt.Println("Invoking Envoke_ASSET_INFO ", time.Now())
}
func main(){
C:=cron.New()
min:=strconv.Itoa(int(17))
h:=strconv.Itoa(int(16))
sep:="0"+" "+min+" "+h+" "+"*"+" "+"*"+" "+"*"
fmt.Println("SPECIFATION PASSED TO FUNCTION :", sep)
C.AddFunc(sep, Envoke_ASSET_INFO )
C.Start()
select{}
}
When I am running this program it is evoking my function. But when I change my system time (+24 hours) to check the next evoking it is not happening.
This is not how cron works. Cron won't run overdue tasks when you change system time. Think what would happen if it worked that way and you turned your machine on after 2 days with job scheduled to run every 5 minutes. If you really want to test it that way you should change the system time to a time just before your job is supposed to run and wait to see if it does.
Personally I think that it's a better idea to pass hour and minute as parameters and check if the job is running on next minute or something.
Related
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.
I have the following code snipped which schedules the job to be run after the specified seconds:
import (
"github.com/jasonlvhit/gocron"
)
// ScheduleCron schedules job running at specified JobInterval
func (cron CronJob) ScheduleCron() {
gocron.Every(uint64(120)).Second().Do(cron.run)
<-gocron.Start()
}
func (cron CronJob) run() {
fmt.Println("Cron Scheduled")
cron.job.Run()
}
This runs the job every 2 minutes. However, I want the job to only run if the previous job has finished. In other words, only 1 job should be running at a time and preferably the next scheduled job should run 2 minutes after the previous job was completed. Is there any way to do that?
The library defines MAXJOBNUM const with value 10000, would it be right to set it to 1?
This is a bit old question.Still thought of answering since I came across.
The SingletonMode() can be set for the purpose. As the comment says, the SingletonMode prevents a new job from starting if the prior job has not yet
completed it's run
In our project we need to retrieve prices from a remote ftp server. During the office hours this works fine, prices are retrieved and successfully processed. After office hours there are no new prices published on the ftp server, so as expected we don't find anything new.
Our problem is that after a few hours of not finding new prices, the poller just stops polling. No error in the logfiles (even when running on org.springframework.integration on debug level) and no exceptions. We are now using a separate TaskExecutor to isolate the issue, but still the poller just stops. In the mean time we adjusted the cron expression to match these hours, to limited the resource use, but still the poller just stops when it is supposed to run.
Any help to troubleshoot this issue is very much appreciated!
We use an #InboudChannelAdapter on a FtpStreamingMessageSource which is configured like this:
#Bean
#InboundChannelAdapter(
value = FTP_PRICES_INBOUND,
poller = [Poller(
maxMessagesPerPoll = "\${ftp.fetch.size}",
cron = "\${ftp.poll.cron}",
taskExecutor = "ftpTaskExecutor"
)],
autoStartup = "\${ftp.fetch.enabled:false}"
)
fun ftpInboundFlow(
#Value("\${ftp.remote.prices.dir}") pricesDir: String,
#Value("\${ftp.remote.prices.file.pattern}") remoteFilePattern: String,
#Value("\${ftp.fetch.size}") fetchSize: Int,
#Value("\${ftp.fetch.enabled:false}") fetchEnabled: Boolean,
clock: Clock,
remoteFileTemplate: RemoteFileTemplate<FTPFile>,
priceParseService: PriceParseService,
ftpFilterOnlyFilesFromMaxDurationAgo: FtpFilterOnlyFilesFromMaxDurationAgo
): FtpStreamingMessageSource {
val messageSource = FtpStreamingMessageSource(remoteFileTemplate, null)
messageSource.setRemoteDirectory(pricesDir)
messageSource.maxFetchSize = fetchSize
messageSource.setFilter(
inboundFilters(
remoteFilePattern,
ftpFilterOnlyFilesFromMaxDurationAgo
)
)
return messageSource;
}
The property values are:
poll.cron: "*/30 * 4-20 * * MON-FRI"
fetch.size: 10
fetch.enabled: true
We limit the poll.cron we used the retrieve every minute.
In the related DefaultFtpSessionFactory, the timeouts are set to 60 seconds to override the default value of -1 (which means no timeout at all):
sessionFactory.setDataTimeout(timeOut)
sessionFactory.setConnectTimeout(timeOut)
sessionFactory.setDefaultTimeout(timeOut)
Maybe my answer seems a bit too easy, bit is it because your cron expression states that it should schedule the job between 4 and 20 hour. After 8:00 PM it will not schedule the job anymore and it will start polling again at 4:00 AM.
It turned out that the processing took longer than the scheduled interval, so during processing a new task was already executed. So eventually multiple task were trying to accomplish the same thing.
We solved this by using a fixedDelay on the poller instead of a fixedRate.
The difference is that a fixedRate schedules on a regular interval independent if the task was finished and the fixedDelay schedules a delay after the task is finished.
I have a DBMS_jobs which is scheduled to run a procedure FINDING_PROCEDURE at 6 am evey day. Can anyone tell me how can i change the start time so that it is scheduled to run at 9 am from tomorrow. Thanks in advance.
As I already mentioned in my comment - your job doesn't run at 6 am every day, it runs every 21 hours.
As a second remark, you should seriously consider switching to DBMS_SCHEDULER - it's so much nicer than DBMS_JOB.
Anyway, to let this job run at 9am every day, this should do the trick:
DBMS_JOB.CHANGE (
job => your_job_id,
interval => 'trunc(sysdate) + 1 + 9/24');
you can use DBMS_JOB.CHANGE() to Alter your job schedule.
Click on this link for complete reference from
Oracle Documentation:DBMS_JOB
and find DBMS_JOB.CHANGE()
I have found the Resque:
https://github.com/elucid/resque-delayed
And I can see that I can schedule delayed Job. My question is, how does it check for delayed jobs? If I have 5000 delayed jobs in one month time, I hope it doesn't check every 10 seconds all delayed jobs.
So how is it being done?
It does not have to check all the delayed jobs. It maintains a sorted set in Redis, the jobs being sorted by their scheduled time. See the code at:
https://github.com/elucid/resque-delayed/blob/master/lib/resque-delayed/resque-delayed.rb
Each time the daemon awakes, only the first item of the set needs to be checked (using a ZRANGEBYSCORE command). The daemon fetches the relevant jobs one by one, until the polling query returns no result, then it sleeps again.
Performance could be further improved by fetching the jobs n by n. It could be implemented using a server-side Lua script as a polling query:
local res = redis.call('ZRANGEBYSCORE',KEYS[1], "-inf", ARGV[1], 'LIMIT', 0, 10 )
if #res > 0 then
redis.call( 'ZREMRANGEBYRANK', KEYS[1], 0, #res-1 )
return res
else
return false
end
In one roundtrip, this script gets 10 jobs (if available), and delete them from the zset. Much better than the 11 ZRANGEBYSCORE and 10 ZREM, currently required by Resque-delayed.