From 020309f4725283c440ebd2ddc95eb8478fe95ed3 Mon Sep 17 00:00:00 2001 From: Alexandros Ioannides Date: Sun, 9 Jul 2023 00:55:32 +0300 Subject: [PATCH] Change UTC timezone to system time --- client_test.go | 12 ++++++------ inspector_test.go | 4 ++-- internal/base/base.go | 4 ++-- internal/base/base_test.go | 20 ++++++++++---------- internal/log/log.go | 2 +- internal/rdb/inspect.go | 2 +- internal/rdb/inspect_test.go | 4 ++-- internal/rdb/rdb.go | 4 ++-- internal/rdb/rdb_test.go | 4 ++-- internal/testutil/builder_test.go | 4 ++-- tools/asynq/cmd/queue.go | 4 ++-- tools/asynq/cmd/stats.go | 2 +- 12 files changed, 33 insertions(+), 33 deletions(-) diff --git a/client_test.go b/client_test.go index da24d13..8dae91a 100644 --- a/client_test.go +++ b/client_test.go @@ -355,7 +355,7 @@ func TestClientEnqueue(t *testing.T) { desc: "With deadline option", task: task, opts: []Option{ - Deadline(time.Date(2020, time.June, 24, 0, 0, 0, 0, time.UTC)), + Deadline(time.Date(2020, time.June, 24, 0, 0, 0, 0, time.Local)), }, wantInfo: &TaskInfo{ Queue: "default", @@ -367,7 +367,7 @@ func TestClientEnqueue(t *testing.T) { LastErr: "", LastFailedAt: time.Time{}, Timeout: noTimeout, - Deadline: time.Date(2020, time.June, 24, 0, 0, 0, 0, time.UTC), + Deadline: time.Date(2020, time.June, 24, 0, 0, 0, 0, time.Local), NextProcessAt: now, }, wantPending: map[string][]*base.TaskMessage{ @@ -378,7 +378,7 @@ func TestClientEnqueue(t *testing.T) { Retry: defaultMaxRetry, Queue: "default", Timeout: int64(noTimeout.Seconds()), - Deadline: time.Date(2020, time.June, 24, 0, 0, 0, 0, time.UTC).Unix(), + Deadline: time.Date(2020, time.June, 24, 0, 0, 0, 0, time.Local).Unix(), }, }, }, @@ -388,7 +388,7 @@ func TestClientEnqueue(t *testing.T) { task: task, opts: []Option{ Timeout(20 * time.Second), - Deadline(time.Date(2020, time.June, 24, 0, 0, 0, 0, time.UTC)), + Deadline(time.Date(2020, time.June, 24, 0, 0, 0, 0, time.Local)), }, wantInfo: &TaskInfo{ Queue: "default", @@ -400,7 +400,7 @@ func TestClientEnqueue(t *testing.T) { LastErr: "", LastFailedAt: time.Time{}, Timeout: 20 * time.Second, - Deadline: time.Date(2020, time.June, 24, 0, 0, 0, 0, time.UTC), + Deadline: time.Date(2020, time.June, 24, 0, 0, 0, 0, time.Local), NextProcessAt: now, }, wantPending: map[string][]*base.TaskMessage{ @@ -411,7 +411,7 @@ func TestClientEnqueue(t *testing.T) { Retry: defaultMaxRetry, Queue: "default", Timeout: 20, - Deadline: time.Date(2020, time.June, 24, 0, 0, 0, 0, time.UTC).Unix(), + Deadline: time.Date(2020, time.June, 24, 0, 0, 0, 0, time.Local).Unix(), }, }, }, diff --git a/inspector_test.go b/inspector_test.go index 0d47d06..55c114f 100644 --- a/inspector_test.go +++ b/inspector_test.go @@ -414,7 +414,7 @@ func TestInspectorGetQueueInfo(t *testing.T) { func TestInspectorHistory(t *testing.T) { r := setup(t) defer r.Close() - now := time.Now().UTC() + now := time.Now() inspector := NewInspector(getRedisConnOpt(t)) tests := []struct { @@ -3295,7 +3295,7 @@ func TestInspectorSchedulerEntries(t *testing.T) { rdbClient := rdb.NewRDB(r) inspector := NewInspector(getRedisConnOpt(t)) - now := time.Now().UTC() + now := time.Now() schedulerID := "127.0.0.1:9876:abc123" tests := []struct { diff --git a/internal/base/base.go b/internal/base/base.go index a63c548..633ea96 100644 --- a/internal/base/base.go +++ b/internal/base/base.go @@ -168,12 +168,12 @@ func FailedTotalKey(qname string) string { // ProcessedKey returns a redis key for processed count for the given day for the queue. func ProcessedKey(qname string, t time.Time) string { - return fmt.Sprintf("%sprocessed:%s", QueueKeyPrefix(qname), t.UTC().Format("2006-01-02")) + return fmt.Sprintf("%sprocessed:%s", QueueKeyPrefix(qname), t.In(time.Local).Format("2006-01-02")) } // FailedKey returns a redis key for failure count for the given day for the queue. func FailedKey(qname string, t time.Time) string { - return fmt.Sprintf("%sfailed:%s", QueueKeyPrefix(qname), t.UTC().Format("2006-01-02")) + return fmt.Sprintf("%sfailed:%s", QueueKeyPrefix(qname), t.In(time.Local).Format("2006-01-02")) } // ServerInfoKey returns a redis key for process info. diff --git a/internal/base/base_test.go b/internal/base/base_test.go index 3ac2380..2ad73c8 100644 --- a/internal/base/base_test.go +++ b/internal/base/base_test.go @@ -214,9 +214,9 @@ func TestProcessedKey(t *testing.T) { input time.Time want string }{ - {"default", time.Date(2019, 11, 14, 10, 30, 1, 1, time.UTC), "asynq:{default}:processed:2019-11-14"}, - {"critical", time.Date(2020, 12, 1, 1, 0, 1, 1, time.UTC), "asynq:{critical}:processed:2020-12-01"}, - {"default", time.Date(2020, 1, 6, 15, 02, 1, 1, time.UTC), "asynq:{default}:processed:2020-01-06"}, + {"default", time.Date(2019, 11, 14, 10, 30, 1, 1, time.Local), "asynq:{default}:processed:2019-11-14"}, + {"critical", time.Date(2020, 12, 1, 1, 0, 1, 1, time.Local), "asynq:{critical}:processed:2020-12-01"}, + {"default", time.Date(2020, 1, 6, 15, 02, 1, 1, time.Local), "asynq:{default}:processed:2020-01-06"}, } for _, tc := range tests { @@ -233,9 +233,9 @@ func TestFailedKey(t *testing.T) { input time.Time want string }{ - {"default", time.Date(2019, 11, 14, 10, 30, 1, 1, time.UTC), "asynq:{default}:failed:2019-11-14"}, - {"custom", time.Date(2020, 12, 1, 1, 0, 1, 1, time.UTC), "asynq:{custom}:failed:2020-12-01"}, - {"low", time.Date(2020, 1, 6, 15, 02, 1, 1, time.UTC), "asynq:{low}:failed:2020-01-06"}, + {"default", time.Date(2019, 11, 14, 10, 30, 1, 1, time.Local), "asynq:{default}:failed:2019-11-14"}, + {"custom", time.Date(2020, 12, 1, 1, 0, 1, 1, time.Local), "asynq:{custom}:failed:2020-12-01"}, + {"low", time.Date(2020, 1, 6, 15, 02, 1, 1, time.Local), "asynq:{low}:failed:2020-01-06"}, } for _, tc := range tests { @@ -336,7 +336,7 @@ func TestUniqueKey(t *testing.T) { "address": map[string]string{"line": "123 Main St", "city": "Boston", "state": "MA"}, "names": []string{"bob", "mike", "rob"}}) payload4 := toBytes(map[string]interface{}{ - "time": time.Date(2020, time.July, 28, 0, 0, 0, 0, time.UTC), + "time": time.Date(2020, time.July, 28, 0, 0, 0, 0, time.Local), "duration": time.Hour}) checksum := func(data []byte) string { @@ -633,8 +633,8 @@ func TestSchedulerEntryEncoding(t *testing.T) { Type: "task_A", Payload: toBytes(map[string]interface{}{"foo": "bar"}), Opts: []string{"Queue('email')"}, - Next: time.Now().Add(30 * time.Second).UTC(), - Prev: time.Now().Add(-2 * time.Minute).UTC(), + Next: time.Now().Add(30 * time.Second), + Prev: time.Now().Add(-2 * time.Minute), }, }, } @@ -664,7 +664,7 @@ func TestSchedulerEnqueueEventEncoding(t *testing.T) { { event: SchedulerEnqueueEvent{ TaskID: uuid.NewString(), - EnqueuedAt: time.Now().Add(-30 * time.Second).UTC(), + EnqueuedAt: time.Now().Add(-30 * time.Second), }, }, } diff --git a/internal/log/log.go b/internal/log/log.go index 64a9962..6c4cafc 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -74,7 +74,7 @@ func (l *baseLogger) prefixPrint(prefix string, args ...interface{}) { func newBase(out io.Writer) *baseLogger { prefix := fmt.Sprintf("asynq: pid=%d ", os.Getpid()) return &baseLogger{ - stdlog.New(out, prefix, stdlog.Ldate|stdlog.Ltime|stdlog.Lmicroseconds|stdlog.LUTC), + stdlog.New(out, prefix, stdlog.Ldate|stdlog.Ltime|stdlog.Lmicroseconds), } } diff --git a/internal/rdb/inspect.go b/internal/rdb/inspect.go index cbaf4bf..2be5331 100644 --- a/internal/rdb/inspect.go +++ b/internal/rdb/inspect.go @@ -373,7 +373,7 @@ func (r *RDB) HistoricalStats(qname string, n int) ([]*DailyStats, error) { return nil, errors.E(op, errors.NotFound, &errors.QueueNotFoundError{Queue: qname}) } const day = 24 * time.Hour - now := r.clock.Now().UTC() + now := r.clock.Now() var days []time.Time var keys []string for i := 0; i < n; i++ { diff --git a/internal/rdb/inspect_test.go b/internal/rdb/inspect_test.go index 93b488f..a2fb81a 100644 --- a/internal/rdb/inspect_test.go +++ b/internal/rdb/inspect_test.go @@ -343,7 +343,7 @@ func TestCurrentStatsWithNonExistentQueue(t *testing.T) { func TestHistoricalStats(t *testing.T) { r := setup(t) defer r.Close() - now := time.Now().UTC() + now := time.Now() tests := []struct { qname string // queue of interest @@ -5326,7 +5326,7 @@ func TestListWorkers(t *testing.T) { func TestWriteListClearSchedulerEntries(t *testing.T) { r := setup(t) - now := time.Now().UTC() + now := time.Now() schedulerID := "127.0.0.1:9876:abc123" data := []*base.SchedulerEntry{ diff --git a/internal/rdb/rdb.go b/internal/rdb/rdb.go index c79a9c5..7c6cbe8 100644 --- a/internal/rdb/rdb.go +++ b/internal/rdb/rdb.go @@ -1356,7 +1356,7 @@ func (r *RDB) WriteServerState(info *base.ServerInfo, workers []*base.WorkerInfo if err != nil { return errors.E(op, errors.Internal, fmt.Sprintf("cannot encode server info: %v", err)) } - exp := r.clock.Now().Add(ttl).UTC() + exp := r.clock.Now().Add(ttl) args := []interface{}{ttl.Seconds(), bytes} // args to the lua script for _, w := range workers { bytes, err := base.EncodeWorkerInfo(w) @@ -1421,7 +1421,7 @@ func (r *RDB) WriteSchedulerEntries(schedulerID string, entries []*base.Schedule } args = append(args, bytes) } - exp := r.clock.Now().Add(ttl).UTC() + exp := r.clock.Now().Add(ttl) key := base.SchedulerEntriesKey(schedulerID) err := r.client.ZAdd(ctx, base.AllSchedulers, redis.Z{Score: float64(exp.Unix()), Member: key}).Err() if err != nil { diff --git a/internal/rdb/rdb_test.go b/internal/rdb/rdb_test.go index 3bd9eda..3f88066 100644 --- a/internal/rdb/rdb_test.go +++ b/internal/rdb/rdb_test.go @@ -2767,7 +2767,7 @@ func TestWriteServerState(t *testing.T) { Concurrency: 10, Queues: map[string]int{"default": 2, "email": 5, "low": 1}, StrictPriority: false, - Started: time.Now().UTC(), + Started: time.Now(), Status: "active", ActiveWorkerCount: 0, } @@ -2857,7 +2857,7 @@ func TestWriteServerStateWithWorkers(t *testing.T) { Concurrency: 10, Queues: map[string]int{"default": 2, "email": 5, "low": 1}, StrictPriority: false, - Started: time.Now().Add(-10 * time.Minute).UTC(), + Started: time.Now().Add(-10 * time.Minute), Status: "active", ActiveWorkerCount: len(workers), } diff --git a/internal/testutil/builder_test.go b/internal/testutil/builder_test.go index e955889..e6f9c3d 100644 --- a/internal/testutil/builder_test.go +++ b/internal/testutil/builder_test.go @@ -50,7 +50,7 @@ func TestTaskMessageBuilder(t *testing.T) { ops: func(b *TaskMessageBuilder) { b.SetRetry(1). SetTimeout(20 * time.Second). - SetDeadline(time.Date(2017, 3, 6, 0, 0, 0, 0, time.UTC)) + SetDeadline(time.Date(2017, 3, 6, 0, 0, 0, 0, time.Local)) }, want: &base.TaskMessage{ Type: "default_task", @@ -58,7 +58,7 @@ func TestTaskMessageBuilder(t *testing.T) { Payload: nil, Retry: 1, Timeout: 20, - Deadline: time.Date(2017, 3, 6, 0, 0, 0, 0, time.UTC).Unix(), + Deadline: time.Date(2017, 3, 6, 0, 0, 0, 0, time.Local).Unix(), }, }, { diff --git a/tools/asynq/cmd/queue.go b/tools/asynq/cmd/queue.go index 875dca5..4c333e8 100644 --- a/tools/asynq/cmd/queue.go +++ b/tools/asynq/cmd/queue.go @@ -180,7 +180,7 @@ func printQueueInfo(info *asynq.QueueInfo) { }, ) fmt.Println() - bold.Printf("Daily Stats %s UTC\n", info.Timestamp.UTC().Format("2006-01-02")) + bold.Printf("Daily Stats %s\n", info.Timestamp.In(time.Local).Format("2006-01-02")) printTable( []string{"processed", "failed", "error rate"}, func(w io.Writer, tmpl string) { @@ -218,7 +218,7 @@ func queueHistory(cmd *cobra.Command, args []string) { func printDailyStats(stats []*asynq.DailyStats) { printTable( - []string{"date (UTC)", "processed", "failed", "error rate"}, + []string{"date", "processed", "failed", "error rate"}, func(w io.Writer, tmpl string) { for _, s := range stats { var errRate string diff --git a/tools/asynq/cmd/stats.go b/tools/asynq/cmd/stats.go index 7cb1ccf..7ba8d78 100644 --- a/tools/asynq/cmd/stats.go +++ b/tools/asynq/cmd/stats.go @@ -139,7 +139,7 @@ func stats(cmd *cobra.Command, args []string) { printStatsByQueue(stats) fmt.Println() - bold.Printf("Daily Stats %s UTC\n", aggStats.Timestamp.UTC().Format("2006-01-02")) + bold.Printf("Daily Stats %s\n", aggStats.Timestamp.In(time.Local).Format("2006-01-02")) printSuccessFailureStats(&aggStats) fmt.Println()