cron icon indicating copy to clipboard operation
cron copied to clipboard

Didn't add any delay but there is delay in job execution

Open amankaur27 opened this issue 6 years ago • 2 comments

I am using robfig V2 on golang v1.10. I have a job that is executed every 5 mins. I have around 2k jobs to be started at once. Now when it starts, I did not add any custom delay but second execution for some job (that should be done after 5-10 mins approx) occurred after 30 mins which is a big difference. Can you help me over this ?

amankaur27 avatar Jan 07 '20 04:01 amankaur27

Sorry, I'm having trouble exactly understanding the scenario. Can you provide code for me to replicate what you're doing?

robfig avatar Jan 09 '20 01:01 robfig

i hava the same question for this issue.When i deploy my cron service in docker, after i reboot the server, there is a time interval before the first cron job. I had tried to fix it by change the time zone, but didn't make it.

if anything could help me to slove the problem, please tell me, thanks a lot :)

Env:

Raspberry Pi 4B 4 CPU core 4GB RAM Linux raspbian 5.4.47-OPENFANS+20200622-v8 #1 SMP PREEMPT Mon Jun 22 21:17:56 CST 2020 aarch64 GNU/Linux

CornVersion:

github.com/robfig/cron/v3 v3.0.0

BuilderImg:

golang:1.15.1-alpine3.12

DeploymentImg:

alpine:3.12.0

Code:

import (
	......
	_ "time/tzdata"
)

func JobTimer() {
	c := cron.New()

	// when the cron service start, log the container time and timezone info
	Logger.Info("[定时器]", zap.Time("运行时间", time.Now()), zap.String("时区", c.Location().String()))

	// add a cron job, the CommitTime is a const var -> "00 7,12 * * *"
	eid, err := c.AddFunc(CommitTime, func() {
		// my custom job, i make sure nothing will block the goroutine
		go Job()
		...

		// and after the job finished, print when the next job will do
		for _, entry := range c.Entries() {
			Logger.Info("[GHC定时器]", zap.Time("下一次执行时间", entry.Schedule.Next(time.Now())))
		}
	})
	if err != nil {
		Logger.Error("[定时任务错误]", zap.Error(err))
		return
	}

	// this func will print the next job will do also
	Logger.Info("[GHC定时器]", zap.Time("下一次执行时间", c.Entry(eid).Schedule.Next(time.Now())))

	c.Run()
}

Log:

// my server will reboot at a random time before 7:00
// the docekr will start the container after reboot
// log when the next job will be do
{"L":"INFO","T":"2020-10-07T05:17:22.376+0800","C":"ghc/main.go:262","M":"[GHC定时器]","下一次执行时间":"2020-10-07T07:00:00.000+0800"}

// in fact, the next job will be do after about 45 min, and i dont know why
{"L":"INFO","T":"2020-10-07T07:45:23.196+0800","C":"ghc/main.go:332",....}

// the second job will do at 12:00
{"L":"INFO","T":"2020-10-07T07:45:23.197+0800","C":"ghc/main.go:255","M":"[GHC定时器]","下一次执行时间":"2020-10-07T12:00:00.000+0800"}


// but there is no delay before the second job
{"L":"INFO","T":"2020-10-07T12:00:00.000+0800","C":"ghc/main.go:332",....}

maybe the problem caused by reboot?

avtion avatar Oct 07 '20 07:10 avtion