asynq icon indicating copy to clipboard operation
asynq copied to clipboard

[BUG] tasks before 8 AM are being counted towards the previous day

Open xmwilldo opened this issue 1 year ago • 11 comments

Describe the bug My scheduler program runs in the Asia/Shanghai time zone, and the asynq server also runs in the Asia/Shanghai environment. However, when I start it, I can see that the timestamps in the logs are not in the Asia/Shanghai time zone. I'm not sure if this is causing a problem: the scheduled tasks before 8 AM are being counted towards the previous day, which is not what I want to see.

To Reproduce Steps to reproduce the behavior (Code snippets if applicable):

  1. To start the scheduler in the Asia/Shanghai time zone
  2. Start the server
  3. Run a scheduled task before 8 AM
  4. View the statistical results on the web UI.

Expected behavior The task statistics after 8 AM are for the current day.

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • OS: Linux
  • Version of asynq package v0.22.1

Additional context Add any other context about the problem here.

xmwilldo avatar Jun 20 '23 06:06 xmwilldo

Do you have reproducible code and screenshots?

ghosx avatar Jun 26 '23 05:06 ghosx

I have same problem.

naisev avatar Jun 30 '23 09:06 naisev

@xmwilldo thanks for reporting an issue.

Did you specify your timezone via SchedulerOpts.Location?

If so, would you mind providing some code snippets to help me investigate further?

hibiken avatar Jul 03 '23 21:07 hibiken

@hibiken Yes, I tried but it didn't work.

loc, _ := time.LoadLocation("Asia/Shanghai")
	mgr, err := asynq.NewPeriodicTaskManager(
		asynq.PeriodicTaskManagerOpts{
			PeriodicTaskConfigProvider: &TrainPeriodicTaskProvider{
				ctx:    l.ctx,
				svcCtx: l.svcCtx,
			},
			RedisConnOpt: asynq.RedisClientOpt{
				Addr:     l.svcCtx.Config.Redis.Host,
				Password: l.svcCtx.Config.Redis.Pass,
				DB:       10,
			},
			SchedulerOpts: &asynq.SchedulerOpts{
				Location: loc,
			},
			SyncInterval: 10 * time.Second,
		},
	)
	if err != nil {
		log.Fatalf("could new PeriodicTaskManager: %v", err)
	}

xmwilldo avatar Jul 04 '23 01:07 xmwilldo

uTools_1688435614105 I have these scheduled tasks, each task executes at least ten sub-tasks, but the statistical results are as follows: uTools_1688435992847

xmwilldo avatar Jul 04 '23 02:07 xmwilldo

It's probably related to this one? https://github.com/hibiken/asynqmon/issues/295

UI shows everything in UTC so I think we need to open a FR to support different timezone in the UI.

hibiken avatar Jul 04 '23 03:07 hibiken

This doesn't seem to matter, because the ui just shows the data in redis, and the data recorded in redis itself is wrong

xmwilldo avatar Jul 04 '23 07:07 xmwilldo

uTools_1688454744529 like this

xmwilldo avatar Jul 04 '23 07:07 xmwilldo

I see. We need to update these helpers to be timezone aware (currently always use UTC):

https://github.com/hibiken/asynq/blob/fde294be326a252f6fcb1d942c11c055bebeecfb/internal/base/base.go#L169-L172

https://github.com/hibiken/asynq/blob/fde294be326a252f6fcb1d942c11c055bebeecfb/internal/base/base.go#L174-L177

This may be a good first issue for someone's who's looking to contribute.

hibiken avatar Jul 08 '23 03:07 hibiken

I would also like to participate, but this PR#683 already exists. Thanks!

xmwilldo avatar Jul 10 '23 02:07 xmwilldo

is there any progress ?

xmwilldo avatar Jan 11 '24 07:01 xmwilldo