[GH-ISSUE #671] [BUG] tasks before 8 AM are being counted towards the previous day #1353

Open
opened 2026-03-07 22:08:52 +03:00 by kerem · 11 comments
Owner

Originally created by @xmwilldo on GitHub (Jun 20, 2023).
Original GitHub issue: https://github.com/hibiken/asynq/issues/671

Originally assigned to: @hibiken on GitHub.

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.

Originally created by @xmwilldo on GitHub (Jun 20, 2023). Original GitHub issue: https://github.com/hibiken/asynq/issues/671 Originally assigned to: @hibiken on GitHub. **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.
Author
Owner

@ghosx commented on GitHub (Jun 26, 2023):

Do you have reproducible code and screenshots?

<!-- gh-comment-id:1606694890 --> @ghosx commented on GitHub (Jun 26, 2023): Do you have reproducible code and screenshots?
Author
Owner

@naisev commented on GitHub (Jun 30, 2023):

I have same problem.

<!-- gh-comment-id:1614382133 --> @naisev commented on GitHub (Jun 30, 2023): I have same problem.
Author
Owner

@hibiken commented on GitHub (Jul 3, 2023):

@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?

<!-- gh-comment-id:1619186375 --> @hibiken commented on GitHub (Jul 3, 2023): @xmwilldo thanks for reporting an issue. Did you specify your timezone via [`SchedulerOpts.Location`](https://pkg.go.dev/github.com/hibiken/asynq#SchedulerOpts.Location)? If so, would you mind providing some code snippets to help me investigate further?
Author
Owner

@xmwilldo commented on GitHub (Jul 4, 2023):

@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)
	}
<!-- gh-comment-id:1619347834 --> @xmwilldo commented on GitHub (Jul 4, 2023): @hibiken Yes, I tried but it didn't work. ``` go 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) } ```
Author
Owner

@xmwilldo commented on GitHub (Jul 4, 2023):

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

<!-- gh-comment-id:1619353054 --> @xmwilldo commented on GitHub (Jul 4, 2023): ![uTools_1688435614105](https://github.com/hibiken/asynq/assets/16560252/ccda7e6d-13a5-4412-8ac6-3d8b9da89454) I have these scheduled tasks, each task executes at least ten sub-tasks, but the statistical results are as follows: ![uTools_1688435992847](https://github.com/hibiken/asynq/assets/16560252/b1b43226-ccd2-4d31-8e2e-154a41e35915)
Author
Owner

@hibiken commented on GitHub (Jul 4, 2023):

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.

<!-- gh-comment-id:1619403141 --> @hibiken commented on GitHub (Jul 4, 2023): 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.
Author
Owner

@xmwilldo commented on GitHub (Jul 4, 2023):

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

<!-- gh-comment-id:1619642839 --> @xmwilldo commented on GitHub (Jul 4, 2023): This doesn't seem to matter, because the ui just shows the data in redis, and the data recorded in redis itself is wrong
Author
Owner

@xmwilldo commented on GitHub (Jul 4, 2023):

uTools_1688454744529
like this

<!-- gh-comment-id:1619648189 --> @xmwilldo commented on GitHub (Jul 4, 2023): ![uTools_1688454744529](https://github.com/hibiken/asynq/assets/16560252/75b3ee21-e874-4c17-a8bb-6df9a993efa2) like this
Author
Owner

@hibiken commented on GitHub (Jul 8, 2023):

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

github.com/hibiken/asynq@fde294be32/internal/base/base.go (L169-L172)

github.com/hibiken/asynq@fde294be32/internal/base/base.go (L174-L177)

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

<!-- gh-comment-id:1626711222 --> @hibiken commented on GitHub (Jul 8, 2023): 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.
Author
Owner

@xmwilldo commented on GitHub (Jul 10, 2023):

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

<!-- gh-comment-id:1627984533 --> @xmwilldo commented on GitHub (Jul 10, 2023): I would also like to participate, but this PR#683 already exists. Thanks!
Author
Owner

@xmwilldo commented on GitHub (Jan 11, 2024):

is there any progress ?

<!-- gh-comment-id:1886435487 --> @xmwilldo commented on GitHub (Jan 11, 2024): is there any progress ?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asynq#1353
No description provided.