From fa313ce180808e6ba0d7ab569f0647024bc1a0f2 Mon Sep 17 00:00:00 2001 From: Ken Hibino Date: Fri, 28 May 2021 14:40:09 -0700 Subject: [PATCH] Update to new asynq API --- conversion_helpers.go | 123 ++++++++++++----------- go.sum | 59 ++--------- main.go | 23 +++-- queue_handlers.go | 27 +++--- scheduler_entry_handlers.go | 8 +- server_handlers.go | 4 +- task_handlers.go | 188 ++++++++++++++++++------------------ 7 files changed, 193 insertions(+), 239 deletions(-) diff --git a/conversion_helpers.go b/conversion_helpers.go index a0edc9c..bc4b694 100644 --- a/conversion_helpers.go +++ b/conversion_helpers.go @@ -3,7 +3,7 @@ package main import ( "time" - "github.com/hibiken/asynq/inspeq" + "github.com/hibiken/asynq" ) // **************************************************************************** @@ -39,7 +39,7 @@ type QueueStateSnapshot struct { Timestamp time.Time `json:"timestamp"` } -func toQueueStateSnapshot(s *inspeq.QueueStats) *QueueStateSnapshot { +func toQueueStateSnapshot(s *asynq.QueueInfo) *QueueStateSnapshot { return &QueueStateSnapshot{ Queue: s.Queue, MemoryUsage: s.MemoryUsage, @@ -65,7 +65,7 @@ type DailyStats struct { Date string `json:"date"` } -func toDailyStats(s *inspeq.DailyStats) *DailyStats { +func toDailyStats(s *asynq.DailyStats) *DailyStats { return &DailyStats{ Queue: s.Queue, Processed: s.Processed, @@ -75,7 +75,7 @@ func toDailyStats(s *inspeq.DailyStats) *DailyStats { } } -func toDailyStatsList(in []*inspeq.DailyStats) []*DailyStats { +func toDailyStatsList(in []*asynq.DailyStats) []*DailyStats { out := make([]*DailyStats, len(in)) for i, s := range in { out[i] = toDailyStats(s) @@ -110,20 +110,20 @@ type ActiveTask struct { Deadline string `json:"deadline"` } -func toActiveTask(t *inspeq.ActiveTask) *ActiveTask { +func toActiveTask(t *asynq.TaskInfo) *ActiveTask { base := &BaseTask{ - ID: t.ID, + ID: t.ID(), Type: t.Type(), Payload: t.Payload(), - Queue: t.Queue, - MaxRetry: t.MaxRetry, - Retried: t.Retried, - LastError: t.LastError, + Queue: t.Queue(), + MaxRetry: t.MaxRetry(), + Retried: t.Retried(), + LastError: t.LastErr(), } return &ActiveTask{BaseTask: base} } -func toActiveTasks(in []*inspeq.ActiveTask) []*ActiveTask { +func toActiveTasks(in []*asynq.TaskInfo) []*ActiveTask { out := make([]*ActiveTask, len(in)) for i, t := range in { out[i] = toActiveTask(t) @@ -131,28 +131,27 @@ func toActiveTasks(in []*inspeq.ActiveTask) []*ActiveTask { return out } +// TODO: Maybe we don't need state specific type, just use TaskInfo type PendingTask struct { *BaseTask - Key string `json:"key"` } -func toPendingTask(t *inspeq.PendingTask) *PendingTask { +func toPendingTask(t *asynq.TaskInfo) *PendingTask { base := &BaseTask{ - ID: t.ID, + ID: t.ID(), Type: t.Type(), Payload: t.Payload(), - Queue: t.Queue, - MaxRetry: t.MaxRetry, - Retried: t.Retried, - LastError: t.LastError, + Queue: t.Queue(), + MaxRetry: t.MaxRetry(), + Retried: t.Retried(), + LastError: t.LastErr(), } return &PendingTask{ BaseTask: base, - Key: t.Key(), } } -func toPendingTasks(in []*inspeq.PendingTask) []*PendingTask { +func toPendingTasks(in []*asynq.TaskInfo) []*PendingTask { out := make([]*PendingTask, len(in)) for i, t := range in { out[i] = toPendingTask(t) @@ -162,28 +161,26 @@ func toPendingTasks(in []*inspeq.PendingTask) []*PendingTask { type ScheduledTask struct { *BaseTask - Key string `json:"key"` NextProcessAt time.Time `json:"next_process_at"` } -func toScheduledTask(t *inspeq.ScheduledTask) *ScheduledTask { +func toScheduledTask(t *asynq.TaskInfo) *ScheduledTask { base := &BaseTask{ - ID: t.ID, + ID: t.ID(), Type: t.Type(), Payload: t.Payload(), - Queue: t.Queue, - MaxRetry: t.MaxRetry, - Retried: t.Retried, - LastError: t.LastError, + Queue: t.Queue(), + MaxRetry: t.MaxRetry(), + Retried: t.Retried(), + LastError: t.LastErr(), } return &ScheduledTask{ BaseTask: base, - Key: t.Key(), - NextProcessAt: t.NextProcessAt, + NextProcessAt: t.NextProcessAt(), } } -func toScheduledTasks(in []*inspeq.ScheduledTask) []*ScheduledTask { +func toScheduledTasks(in []*asynq.TaskInfo) []*ScheduledTask { out := make([]*ScheduledTask, len(in)) for i, t := range in { out[i] = toScheduledTask(t) @@ -193,28 +190,26 @@ func toScheduledTasks(in []*inspeq.ScheduledTask) []*ScheduledTask { type RetryTask struct { *BaseTask - Key string `json:"key"` NextProcessAt time.Time `json:"next_process_at"` } -func toRetryTask(t *inspeq.RetryTask) *RetryTask { +func toRetryTask(t *asynq.TaskInfo) *RetryTask { base := &BaseTask{ - ID: t.ID, + ID: t.ID(), Type: t.Type(), Payload: t.Payload(), - Queue: t.Queue, - MaxRetry: t.MaxRetry, - Retried: t.Retried, - LastError: t.LastError, + Queue: t.Queue(), + MaxRetry: t.MaxRetry(), + Retried: t.Retried(), + LastError: t.LastErr(), } return &RetryTask{ BaseTask: base, - Key: t.Key(), - NextProcessAt: t.NextProcessAt, + NextProcessAt: t.NextProcessAt(), } } -func toRetryTasks(in []*inspeq.RetryTask) []*RetryTask { +func toRetryTasks(in []*asynq.TaskInfo) []*RetryTask { out := make([]*RetryTask, len(in)) for i, t := range in { out[i] = toRetryTask(t) @@ -224,28 +219,26 @@ func toRetryTasks(in []*inspeq.RetryTask) []*RetryTask { type ArchivedTask struct { *BaseTask - Key string `json:"key"` LastFailedAt time.Time `json:"last_failed_at"` } -func toArchivedTask(t *inspeq.ArchivedTask) *ArchivedTask { +func toArchivedTask(t *asynq.TaskInfo) *ArchivedTask { base := &BaseTask{ - ID: t.ID, + ID: t.ID(), Type: t.Type(), Payload: t.Payload(), - Queue: t.Queue, - MaxRetry: t.MaxRetry, - Retried: t.Retried, - LastError: t.LastError, + Queue: t.Queue(), + MaxRetry: t.MaxRetry(), + Retried: t.Retried(), + LastError: t.LastErr(), } return &ArchivedTask{ BaseTask: base, - Key: t.Key(), - LastFailedAt: t.LastFailedAt, + LastFailedAt: t.LastFailedAt(), } } -func toArchivedTasks(in []*inspeq.ArchivedTask) []*ArchivedTask { +func toArchivedTasks(in []*asynq.TaskInfo) []*ArchivedTask { out := make([]*ArchivedTask, len(in)) for i, t := range in { out[i] = toArchivedTask(t) @@ -264,7 +257,7 @@ type SchedulerEntry struct { PrevEnqueueAt string `json:"prev_enqueue_at,omitempty"` } -func toSchedulerEntry(e *inspeq.SchedulerEntry) *SchedulerEntry { +func toSchedulerEntry(e *asynq.SchedulerEntry) *SchedulerEntry { opts := make([]string, 0) // create a non-nil, empty slice to avoid null in json output for _, o := range e.Opts { opts = append(opts, o.String()) @@ -284,7 +277,7 @@ func toSchedulerEntry(e *inspeq.SchedulerEntry) *SchedulerEntry { } } -func toSchedulerEntries(in []*inspeq.SchedulerEntry) []*SchedulerEntry { +func toSchedulerEntries(in []*asynq.SchedulerEntry) []*SchedulerEntry { out := make([]*SchedulerEntry, len(in)) for i, e := range in { out[i] = toSchedulerEntry(e) @@ -297,14 +290,14 @@ type SchedulerEnqueueEvent struct { EnqueuedAt string `json:"enqueued_at"` } -func toSchedulerEnqueueEvent(e *inspeq.SchedulerEnqueueEvent) *SchedulerEnqueueEvent { +func toSchedulerEnqueueEvent(e *asynq.SchedulerEnqueueEvent) *SchedulerEnqueueEvent { return &SchedulerEnqueueEvent{ TaskID: e.TaskID, EnqueuedAt: e.EnqueuedAt.Format(time.RFC3339), } } -func toSchedulerEnqueueEvents(in []*inspeq.SchedulerEnqueueEvent) []*SchedulerEnqueueEvent { +func toSchedulerEnqueueEvents(in []*asynq.SchedulerEnqueueEvent) []*SchedulerEnqueueEvent { out := make([]*SchedulerEnqueueEvent, len(in)) for i, e := range in { out[i] = toSchedulerEnqueueEvent(e) @@ -324,7 +317,7 @@ type ServerInfo struct { ActiveWorkers []*WorkerInfo `json:"active_workers"` } -func toServerInfo(info *inspeq.ServerInfo) *ServerInfo { +func toServerInfo(info *asynq.ServerInfo) *ServerInfo { return &ServerInfo{ ID: info.ID, Host: info.Host, @@ -338,7 +331,7 @@ func toServerInfo(info *inspeq.ServerInfo) *ServerInfo { } } -func toServerInfoList(in []*inspeq.ServerInfo) []*ServerInfo { +func toServerInfoList(in []*asynq.ServerInfo) []*ServerInfo { out := make([]*ServerInfo, len(in)) for i, s := range in { out[i] = toServerInfo(s) @@ -347,18 +340,24 @@ func toServerInfoList(in []*inspeq.ServerInfo) []*ServerInfo { } type WorkerInfo struct { - Task *ActiveTask `json:"task"` - Started string `json:"start_time"` + TaskID string `json:"task_id"` + Queue string `json:"queue"` + TaskType string `json:"task_type"` + TakPayload []byte `json:"task_payload"` + Started string `json:"start_time"` } -func toWorkerInfo(info *inspeq.WorkerInfo) *WorkerInfo { +func toWorkerInfo(info *asynq.WorkerInfo) *WorkerInfo { return &WorkerInfo{ - Task: toActiveTask(info.Task), - Started: info.Started.Format(time.RFC3339), + TaskID: info.TaskID, + Queue: info.Queue, + TaskType: info.TaskType, + TakPayload: info.TaskPayload, + Started: info.Started.Format(time.RFC3339), } } -func toWorkerInfoList(in []*inspeq.WorkerInfo) []*WorkerInfo { +func toWorkerInfoList(in []*asynq.WorkerInfo) []*WorkerInfo { out := make([]*WorkerInfo, len(in)) for i, w := range in { out[i] = toWorkerInfo(w) diff --git a/go.sum b/go.sum index cb2d69d..e89c719 100644 --- a/go.sum +++ b/go.sum @@ -16,11 +16,8 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/go-redis/redis/v7 v7.4.0 h1:7obg6wUoj05T0EpY0o8B59S9w5yeMWql7sw2kwNW1x4= github.com/go-redis/redis/v7 v7.4.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg= -<<<<<<< HEAD github.com/go-redis/redis/v8 v8.8.0 h1:fDZP58UN/1RD3DjtTXP/fFZ04TFohSYhjZDkcDe2dnw= github.com/go-redis/redis/v8 v8.8.0/go.mod h1:F7resOH5Kdug49Otu24RjHWwgK7u9AmtqWMnCV1iP5Y= -github.com/go-redis/redis/v8 v8.4.4 h1:fGqgxCTR1sydaKI00oQf3OmkU/DIe/I/fYXvGklCIuc= -github.com/go-redis/redis/v8 v8.4.4/go.mod h1:nA0bQuF0i5JFx4Ta9RZxGKXFrQ8cRWntra97f0196iY= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -30,49 +27,32 @@ github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:x github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -<<<<<<< HEAD -======= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= ->>>>>>> 42a4ed2... Update to use new Task API github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -<<<<<<< HEAD -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -======= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= -github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= ->>>>>>> 42a4ed2... Update to use new Task API -github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs= github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= -github.com/hibiken/asynq v0.17.2 h1:ZSsBebfQFZNO84vOL8JLO8Z9BAfXsYxHCDK8Ii/mO1E= -github.com/hibiken/asynq v0.17.2/go.mod h1:yfQUmjFqSBSUIVxTK0WyW4LPj4gpr283UpWb6hKYaqE= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.15.0 h1:1V1NfVQR87RtWAgp1lv9JZJ5Jap+XFGKPi00andXGi4= github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISqnKUg= github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.10.5 h1:7n6FEkpFmfCoo2t+YYqXH0evK+a9ICQz0xcAy9dYcaQ= github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= @@ -83,32 +63,26 @@ github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.opentelemetry.io/otel v0.19.0 h1:Lenfy7QHRXPZVsw/12CWpxX6d/JkrX8wrx2vO8G80Ng= go.opentelemetry.io/otel v0.19.0/go.mod h1:j9bF567N9EfomkSidSfmMwIwIBuP37AMAIzVW85OxSg= go.opentelemetry.io/otel/metric v0.19.0 h1:dtZ1Ju44gkJkYvo+3qGqVXmf88tc+a42edOywypengg= go.opentelemetry.io/otel/metric v0.19.0/go.mod h1:8f9fglJPRnXuskQmKpnad31lcLJ2VmNNqIsx/uIwBSc= -go.opentelemetry.io/otel/oteltest v0.19.0 h1:YVfA0ByROYqTwOxqHVZYZExzEpfZor+MU1rU+ip2v9Q= go.opentelemetry.io/otel/oteltest v0.19.0/go.mod h1:tI4yxwh8U21v7JD6R3BcA/2+RBoTKFexE/PJ/nSO7IA= go.opentelemetry.io/otel/trace v0.19.0 h1:1ucYlenXIDA1OlHVLDZKX0ObXV5RLaq06DtUKz5e5zc= go.opentelemetry.io/otel/trace v0.19.0/go.mod h1:4IXiNextNOpPnRlI4ryK69mn5iC84bjBWZQA5DXz/qg= -go.uber.org/goleak v0.10.0 h1:G3eWbSNIskeRqtsN/1uI5B+eP73y3JUuBsv9AZjehb4= go.uber.org/goleak v0.10.0/go.mod h1:VCZuO8V8mFPlL0F5J5GK1rtHV3DrFcQ1R8ryq7FK0aI= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -<<<<<<< HEAD -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -======= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= ->>>>>>> 42a4ed2... Update to use new Task API golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -117,18 +91,13 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb h1:eBmm0M9fYhWpKZLjQUUKka/LtIxf46G4fxeEz5KJr9U= golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -<<<<<<< HEAD -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -======= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= ->>>>>>> 42a4ed2... Update to use new Task API golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -143,26 +112,20 @@ golang.org/x/sys v0.0.0-20210112080510-489259a85091 h1:DMyOG0U+gKfu8JZzg2UQe9Mea golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -<<<<<<< HEAD +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -======= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= @@ -171,17 +134,12 @@ google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEY google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= ->>>>>>> 42a4ed2... Update to use new Task API google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -<<<<<<< HEAD -======= google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= ->>>>>>> 42a4ed2... Update to use new Task API google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= @@ -189,14 +147,11 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/main.go b/main.go index 7fe6f2c..82633d1 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,6 @@ import ( "github.com/go-redis/redis/v8" "github.com/gorilla/mux" "github.com/hibiken/asynq" - "github.com/hibiken/asynq/inspeq" "github.com/rs/cors" ) @@ -129,7 +128,7 @@ func main() { log.Fatal(err) } - inspector := inspeq.New(asynq.RedisClientOpt{ + inspector := asynq.NewInspector(asynq.RedisClientOpt{ Addr: opts.Addr, DB: opts.DB, Password: opts.Password, @@ -161,40 +160,40 @@ func main() { api.HandleFunc("/queues/{qname}/active_tasks:batch_cancel", newBatchCancelActiveTasksHandlerFunc(inspector)).Methods("POST") api.HandleFunc("/queues/{qname}/pending_tasks", newListPendingTasksHandlerFunc(inspector)).Methods("GET") - api.HandleFunc("/queues/{qname}/pending_tasks/{task_key}", newDeleteTaskHandlerFunc(inspector)).Methods("DELETE") + api.HandleFunc("/queues/{qname}/pending_tasks/{task_id}", newDeleteTaskHandlerFunc(inspector)).Methods("DELETE") api.HandleFunc("/queues/{qname}/pending_tasks:delete_all", newDeleteAllPendingTasksHandlerFunc(inspector)).Methods("DELETE") api.HandleFunc("/queues/{qname}/pending_tasks:batch_delete", newBatchDeleteTasksHandlerFunc(inspector)).Methods("POST") - api.HandleFunc("/queues/{qname}/pending_tasks/{task_key}:archive", newArchiveTaskHandlerFunc(inspector)).Methods("POST") + api.HandleFunc("/queues/{qname}/pending_tasks/{task_id}:archive", newArchiveTaskHandlerFunc(inspector)).Methods("POST") api.HandleFunc("/queues/{qname}/pending_tasks:archive_all", newArchiveAllPendingTasksHandlerFunc(inspector)).Methods("POST") api.HandleFunc("/queues/{qname}/pending_tasks:batch_archive", newBatchArchiveTasksHandlerFunc(inspector)).Methods("POST") api.HandleFunc("/queues/{qname}/scheduled_tasks", newListScheduledTasksHandlerFunc(inspector)).Methods("GET") - api.HandleFunc("/queues/{qname}/scheduled_tasks/{task_key}", newDeleteTaskHandlerFunc(inspector)).Methods("DELETE") + api.HandleFunc("/queues/{qname}/scheduled_tasks/{task_id}", newDeleteTaskHandlerFunc(inspector)).Methods("DELETE") api.HandleFunc("/queues/{qname}/scheduled_tasks:delete_all", newDeleteAllScheduledTasksHandlerFunc(inspector)).Methods("DELETE") api.HandleFunc("/queues/{qname}/scheduled_tasks:batch_delete", newBatchDeleteTasksHandlerFunc(inspector)).Methods("POST") - api.HandleFunc("/queues/{qname}/scheduled_tasks/{task_key}:run", newRunTaskHandlerFunc(inspector)).Methods("POST") + api.HandleFunc("/queues/{qname}/scheduled_tasks/{task_id}:run", newRunTaskHandlerFunc(inspector)).Methods("POST") api.HandleFunc("/queues/{qname}/scheduled_tasks:run_all", newRunAllScheduledTasksHandlerFunc(inspector)).Methods("POST") api.HandleFunc("/queues/{qname}/scheduled_tasks:batch_run", newBatchRunTasksHandlerFunc(inspector)).Methods("POST") - api.HandleFunc("/queues/{qname}/scheduled_tasks/{task_key}:archive", newArchiveTaskHandlerFunc(inspector)).Methods("POST") + api.HandleFunc("/queues/{qname}/scheduled_tasks/{task_id}:archive", newArchiveTaskHandlerFunc(inspector)).Methods("POST") api.HandleFunc("/queues/{qname}/scheduled_tasks:archive_all", newArchiveAllScheduledTasksHandlerFunc(inspector)).Methods("POST") api.HandleFunc("/queues/{qname}/scheduled_tasks:batch_archive", newBatchArchiveTasksHandlerFunc(inspector)).Methods("POST") api.HandleFunc("/queues/{qname}/retry_tasks", newListRetryTasksHandlerFunc(inspector)).Methods("GET") - api.HandleFunc("/queues/{qname}/retry_tasks/{task_key}", newDeleteTaskHandlerFunc(inspector)).Methods("DELETE") + api.HandleFunc("/queues/{qname}/retry_tasks/{task_id}", newDeleteTaskHandlerFunc(inspector)).Methods("DELETE") api.HandleFunc("/queues/{qname}/retry_tasks:delete_all", newDeleteAllRetryTasksHandlerFunc(inspector)).Methods("DELETE") api.HandleFunc("/queues/{qname}/retry_tasks:batch_delete", newBatchDeleteTasksHandlerFunc(inspector)).Methods("POST") - api.HandleFunc("/queues/{qname}/retry_tasks/{task_key}:run", newRunTaskHandlerFunc(inspector)).Methods("POST") + api.HandleFunc("/queues/{qname}/retry_tasks/{task_id}:run", newRunTaskHandlerFunc(inspector)).Methods("POST") api.HandleFunc("/queues/{qname}/retry_tasks:run_all", newRunAllRetryTasksHandlerFunc(inspector)).Methods("POST") api.HandleFunc("/queues/{qname}/retry_tasks:batch_run", newBatchRunTasksHandlerFunc(inspector)).Methods("POST") - api.HandleFunc("/queues/{qname}/retry_tasks/{task_key}:archive", newArchiveTaskHandlerFunc(inspector)).Methods("POST") + api.HandleFunc("/queues/{qname}/retry_tasks/{task_id}:archive", newArchiveTaskHandlerFunc(inspector)).Methods("POST") api.HandleFunc("/queues/{qname}/retry_tasks:archive_all", newArchiveAllRetryTasksHandlerFunc(inspector)).Methods("POST") api.HandleFunc("/queues/{qname}/retry_tasks:batch_archive", newBatchArchiveTasksHandlerFunc(inspector)).Methods("POST") api.HandleFunc("/queues/{qname}/archived_tasks", newListArchivedTasksHandlerFunc(inspector)).Methods("GET") - api.HandleFunc("/queues/{qname}/archived_tasks/{task_key}", newDeleteTaskHandlerFunc(inspector)).Methods("DELETE") + api.HandleFunc("/queues/{qname}/archived_tasks/{task_id}", newDeleteTaskHandlerFunc(inspector)).Methods("DELETE") api.HandleFunc("/queues/{qname}/archived_tasks:delete_all", newDeleteAllArchivedTasksHandlerFunc(inspector)).Methods("DELETE") api.HandleFunc("/queues/{qname}/archived_tasks:batch_delete", newBatchDeleteTasksHandlerFunc(inspector)).Methods("POST") - api.HandleFunc("/queues/{qname}/archived_tasks/{task_key}:run", newRunTaskHandlerFunc(inspector)).Methods("POST") + api.HandleFunc("/queues/{qname}/archived_tasks/{task_id}:run", newRunTaskHandlerFunc(inspector)).Methods("POST") api.HandleFunc("/queues/{qname}/archived_tasks:run_all", newRunAllArchivedTasksHandlerFunc(inspector)).Methods("POST") api.HandleFunc("/queues/{qname}/archived_tasks:batch_run", newBatchRunTasksHandlerFunc(inspector)).Methods("POST") diff --git a/queue_handlers.go b/queue_handlers.go index a856c13..0411f91 100644 --- a/queue_handlers.go +++ b/queue_handlers.go @@ -2,10 +2,11 @@ package main import ( "encoding/json" + "errors" "net/http" "github.com/gorilla/mux" - "github.com/hibiken/asynq/inspeq" + "github.com/hibiken/asynq" ) // **************************************************************************** @@ -13,7 +14,7 @@ import ( // - http.Handler(s) for queue related endpoints // **************************************************************************** -func newListQueuesHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newListQueuesHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { qnames, err := inspector.Queues() if err != nil { @@ -22,31 +23,31 @@ func newListQueuesHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { } snapshots := make([]*QueueStateSnapshot, len(qnames)) for i, qname := range qnames { - s, err := inspector.CurrentStats(qname) + qinfo, err := inspector.GetQueueInfo(qname) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - snapshots[i] = toQueueStateSnapshot(s) + snapshots[i] = toQueueStateSnapshot(qinfo) } payload := map[string]interface{}{"queues": snapshots} json.NewEncoder(w).Encode(payload) } } -func newGetQueueHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newGetQueueHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) qname := vars["qname"] payload := make(map[string]interface{}) - stats, err := inspector.CurrentStats(qname) + qinfo, err := inspector.GetQueueInfo(qname) if err != nil { // TODO: Check for queue not found error. http.Error(w, err.Error(), http.StatusInternalServerError) return } - payload["current"] = toQueueStateSnapshot(stats) + payload["current"] = toQueueStateSnapshot(qinfo) // TODO: make this n a variable data, err := inspector.History(qname, 10) @@ -63,16 +64,16 @@ func newGetQueueHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { } } -func newDeleteQueueHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newDeleteQueueHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) qname := vars["qname"] if err := inspector.DeleteQueue(qname, false); err != nil { - if _, ok := err.(*inspeq.ErrQueueNotFound); ok { + if errors.Is(err, asynq.ErrQueueNotFound) { http.Error(w, err.Error(), http.StatusNotFound) return } - if _, ok := err.(*inspeq.ErrQueueNotEmpty); ok { + if errors.Is(err, asynq.ErrQueueNotEmpty) { http.Error(w, err.Error(), http.StatusBadRequest) return } @@ -83,7 +84,7 @@ func newDeleteQueueHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { } } -func newPauseQueueHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newPauseQueueHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) qname := vars["qname"] @@ -95,7 +96,7 @@ func newPauseQueueHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { } } -func newResumeQueueHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newResumeQueueHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) qname := vars["qname"] @@ -111,7 +112,7 @@ type ListQueueStatsResponse struct { Stats map[string][]*DailyStats `json:"stats"` } -func newListQueueStatsHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newListQueueStatsHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { qnames, err := inspector.Queues() if err != nil { diff --git a/scheduler_entry_handlers.go b/scheduler_entry_handlers.go index b9b9477..e4d888b 100644 --- a/scheduler_entry_handlers.go +++ b/scheduler_entry_handlers.go @@ -5,7 +5,7 @@ import ( "net/http" "github.com/gorilla/mux" - "github.com/hibiken/asynq/inspeq" + "github.com/hibiken/asynq" ) // **************************************************************************** @@ -13,7 +13,7 @@ import ( // - http.Handler(s) for scheduler entry related endpoints // **************************************************************************** -func newListSchedulerEntriesHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newListSchedulerEntriesHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { entries, err := inspector.SchedulerEntries() if err != nil { @@ -38,12 +38,12 @@ type ListSchedulerEnqueueEventsResponse struct { Events []*SchedulerEnqueueEvent `json:"events"` } -func newListSchedulerEnqueueEventsHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newListSchedulerEnqueueEventsHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { entryID := mux.Vars(r)["entry_id"] pageSize, pageNum := getPageOptions(r) events, err := inspector.ListSchedulerEnqueueEvents( - entryID, inspeq.PageSize(pageSize), inspeq.Page(pageNum)) + entryID, asynq.PageSize(pageSize), asynq.Page(pageNum)) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return diff --git a/server_handlers.go b/server_handlers.go index 52f2c38..921202c 100644 --- a/server_handlers.go +++ b/server_handlers.go @@ -4,7 +4,7 @@ import ( "encoding/json" "net/http" - "github.com/hibiken/asynq/inspeq" + "github.com/hibiken/asynq" ) // **************************************************************************** @@ -16,7 +16,7 @@ type ListServersResponse struct { Servers []*ServerInfo `json:"servers"` } -func newListServersHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newListServersHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { srvs, err := inspector.Servers() if err != nil { diff --git a/task_handlers.go b/task_handlers.go index fa43271..a589434 100644 --- a/task_handlers.go +++ b/task_handlers.go @@ -8,7 +8,7 @@ import ( "time" "github.com/gorilla/mux" - "github.com/hibiken/asynq/inspeq" + "github.com/hibiken/asynq" ) // **************************************************************************** @@ -21,19 +21,19 @@ type ListActiveTasksResponse struct { Stats *QueueStateSnapshot `json:"stats"` } -func newListActiveTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newListActiveTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) qname := vars["qname"] pageSize, pageNum := getPageOptions(r) tasks, err := inspector.ListActiveTasks( - qname, inspeq.PageSize(pageSize), inspeq.Page(pageNum)) + qname, asynq.PageSize(pageSize), asynq.Page(pageNum)) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - stats, err := inspector.CurrentStats(qname) + qinfo, err := inspector.GetQueueInfo(qname) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -44,11 +44,11 @@ func newListActiveTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc return } // m maps taskID to WorkerInfo. - m := make(map[string]*inspeq.WorkerInfo) + m := make(map[string]*asynq.WorkerInfo) for _, srv := range servers { for _, w := range srv.ActiveWorkers { - if w.Task.Queue == qname { - m[w.Task.ID] = w + if w.Queue == qname { + m[w.TaskID] = w } } } @@ -66,7 +66,7 @@ func newListActiveTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc resp := ListActiveTasksResponse{ Tasks: activeTasks, - Stats: toQueueStateSnapshot(stats), + Stats: toQueueStateSnapshot(qinfo), } if err := json.NewEncoder(w).Encode(resp); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) @@ -75,10 +75,10 @@ func newListActiveTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc } } -func newCancelActiveTaskHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newCancelActiveTaskHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { id := mux.Vars(r)["task_id"] - if err := inspector.CancelActiveTask(id); err != nil { + if err := inspector.CancelProcessing(id); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -86,19 +86,19 @@ func newCancelActiveTaskHandlerFunc(inspector *inspeq.Inspector) http.HandlerFun } } -func newCancelAllActiveTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newCancelAllActiveTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { const batchSize = 100 page := 1 qname := mux.Vars(r)["qname"] for { - tasks, err := inspector.ListActiveTasks(qname, inspeq.Page(page), inspeq.PageSize(batchSize)) + tasks, err := inspector.ListActiveTasks(qname, asynq.Page(page), asynq.PageSize(batchSize)) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } for _, t := range tasks { - if err := inspector.CancelActiveTask(t.ID); err != nil { + if err := inspector.CancelProcessing(t.ID()); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -121,7 +121,7 @@ type batchCancelTasksResponse struct { ErrorIDs []string `json:"error_ids"` } -func newBatchCancelActiveTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newBatchCancelActiveTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { r.Body = http.MaxBytesReader(w, r.Body, maxRequestBodySize) dec := json.NewDecoder(r.Body) @@ -139,7 +139,7 @@ func newBatchCancelActiveTasksHandlerFunc(inspector *inspeq.Inspector) http.Hand ErrorIDs: make([]string, 0), } for _, id := range req.TaskIDs { - if err := inspector.CancelActiveTask(id); err != nil { + if err := inspector.CancelProcessing(id); err != nil { log.Printf("error: could not send cancelation signal to task %s", id) resp.ErrorIDs = append(resp.ErrorIDs, id) } else { @@ -153,18 +153,18 @@ func newBatchCancelActiveTasksHandlerFunc(inspector *inspeq.Inspector) http.Hand } } -func newListPendingTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newListPendingTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) qname := vars["qname"] pageSize, pageNum := getPageOptions(r) tasks, err := inspector.ListPendingTasks( - qname, inspeq.PageSize(pageSize), inspeq.Page(pageNum)) + qname, asynq.PageSize(pageSize), asynq.Page(pageNum)) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - stats, err := inspector.CurrentStats(qname) + qinfo, err := inspector.GetQueueInfo(qname) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -176,7 +176,7 @@ func newListPendingTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFun } else { payload["tasks"] = toPendingTasks(tasks) } - payload["stats"] = toQueueStateSnapshot(stats) + payload["stats"] = toQueueStateSnapshot(qinfo) if err := json.NewEncoder(w).Encode(payload); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -184,18 +184,18 @@ func newListPendingTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFun } } -func newListScheduledTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newListScheduledTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) qname := vars["qname"] pageSize, pageNum := getPageOptions(r) tasks, err := inspector.ListScheduledTasks( - qname, inspeq.PageSize(pageSize), inspeq.Page(pageNum)) + qname, asynq.PageSize(pageSize), asynq.Page(pageNum)) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - stats, err := inspector.CurrentStats(qname) + qinfo, err := inspector.GetQueueInfo(qname) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -207,7 +207,7 @@ func newListScheduledTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerF } else { payload["tasks"] = toScheduledTasks(tasks) } - payload["stats"] = toQueueStateSnapshot(stats) + payload["stats"] = toQueueStateSnapshot(qinfo) if err := json.NewEncoder(w).Encode(payload); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -215,18 +215,18 @@ func newListScheduledTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerF } } -func newListRetryTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newListRetryTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) qname := vars["qname"] pageSize, pageNum := getPageOptions(r) tasks, err := inspector.ListRetryTasks( - qname, inspeq.PageSize(pageSize), inspeq.Page(pageNum)) + qname, asynq.PageSize(pageSize), asynq.Page(pageNum)) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - stats, err := inspector.CurrentStats(qname) + qinfo, err := inspector.GetQueueInfo(qname) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -238,7 +238,7 @@ func newListRetryTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc } else { payload["tasks"] = toRetryTasks(tasks) } - payload["stats"] = toQueueStateSnapshot(stats) + payload["stats"] = toQueueStateSnapshot(qinfo) if err := json.NewEncoder(w).Encode(payload); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -246,18 +246,18 @@ func newListRetryTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc } } -func newListArchivedTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newListArchivedTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) qname := vars["qname"] pageSize, pageNum := getPageOptions(r) tasks, err := inspector.ListArchivedTasks( - qname, inspeq.PageSize(pageSize), inspeq.Page(pageNum)) + qname, asynq.PageSize(pageSize), asynq.Page(pageNum)) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - stats, err := inspector.CurrentStats(qname) + qinfo, err := inspector.GetQueueInfo(qname) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -269,7 +269,7 @@ func newListArchivedTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFu } else { payload["tasks"] = toArchivedTasks(tasks) } - payload["stats"] = toQueueStateSnapshot(stats) + payload["stats"] = toQueueStateSnapshot(qinfo) if err := json.NewEncoder(w).Encode(payload); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -277,15 +277,15 @@ func newListArchivedTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFu } } -func newDeleteTaskHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newDeleteTaskHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) - qname, key := vars["qname"], vars["task_key"] - if qname == "" || key == "" { + qname, taskid := vars["qname"], vars["task_id"] + if qname == "" || taskid == "" { http.Error(w, "route parameters should not be empty", http.StatusBadRequest) return } - if err := inspector.DeleteTaskByKey(qname, key); err != nil { + if err := inspector.DeleteTask(qname, taskid); err != nil { // TODO: Handle task not found error and return 404 http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -294,15 +294,15 @@ func newDeleteTaskHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { } } -func newRunTaskHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newRunTaskHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) - qname, key := vars["qname"], vars["task_key"] - if qname == "" || key == "" { + qname, taskid := vars["qname"], vars["task_id"] + if qname == "" || taskid == "" { http.Error(w, "route parameters should not be empty", http.StatusBadRequest) return } - if err := inspector.RunTaskByKey(qname, key); err != nil { + if err := inspector.RunTask(qname, taskid); err != nil { // TODO: Handle task not found error and return 404 http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -311,15 +311,15 @@ func newRunTaskHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { } } -func newArchiveTaskHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newArchiveTaskHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) - qname, key := vars["qname"], vars["task_key"] - if qname == "" || key == "" { + qname, taskid := vars["qname"], vars["task_id"] + if qname == "" || taskid == "" { http.Error(w, "route parameters should not be empty", http.StatusBadRequest) return } - if err := inspector.ArchiveTaskByKey(qname, key); err != nil { + if err := inspector.ArchiveTask(qname, taskid); err != nil { // TODO: Handle task not found error and return 404 http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -333,7 +333,7 @@ type DeleteAllTasksResponse struct { Deleted int `json:"deleted"` } -func newDeleteAllPendingTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newDeleteAllPendingTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { qname := mux.Vars(r)["qname"] n, err := inspector.DeleteAllPendingTasks(qname) @@ -349,7 +349,7 @@ func newDeleteAllPendingTasksHandlerFunc(inspector *inspeq.Inspector) http.Handl } } -func newDeleteAllScheduledTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newDeleteAllScheduledTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { qname := mux.Vars(r)["qname"] n, err := inspector.DeleteAllScheduledTasks(qname) @@ -365,7 +365,7 @@ func newDeleteAllScheduledTasksHandlerFunc(inspector *inspeq.Inspector) http.Han } } -func newDeleteAllRetryTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newDeleteAllRetryTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { qname := mux.Vars(r)["qname"] n, err := inspector.DeleteAllRetryTasks(qname) @@ -381,7 +381,7 @@ func newDeleteAllRetryTasksHandlerFunc(inspector *inspeq.Inspector) http.Handler } } -func newDeleteAllArchivedTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newDeleteAllArchivedTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { qname := mux.Vars(r)["qname"] n, err := inspector.DeleteAllArchivedTasks(qname) @@ -397,7 +397,7 @@ func newDeleteAllArchivedTasksHandlerFunc(inspector *inspeq.Inspector) http.Hand } } -func newRunAllScheduledTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newRunAllScheduledTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { qname := mux.Vars(r)["qname"] if _, err := inspector.RunAllScheduledTasks(qname); err != nil { @@ -408,7 +408,7 @@ func newRunAllScheduledTasksHandlerFunc(inspector *inspeq.Inspector) http.Handle } } -func newRunAllRetryTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newRunAllRetryTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { qname := mux.Vars(r)["qname"] if _, err := inspector.RunAllRetryTasks(qname); err != nil { @@ -419,7 +419,7 @@ func newRunAllRetryTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFun } } -func newRunAllArchivedTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newRunAllArchivedTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { qname := mux.Vars(r)["qname"] if _, err := inspector.RunAllArchivedTasks(qname); err != nil { @@ -430,7 +430,7 @@ func newRunAllArchivedTasksHandlerFunc(inspector *inspeq.Inspector) http.Handler } } -func newArchiveAllPendingTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newArchiveAllPendingTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { qname := mux.Vars(r)["qname"] if _, err := inspector.ArchiveAllPendingTasks(qname); err != nil { @@ -441,7 +441,7 @@ func newArchiveAllPendingTasksHandlerFunc(inspector *inspeq.Inspector) http.Hand } } -func newArchiveAllScheduledTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newArchiveAllScheduledTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { qname := mux.Vars(r)["qname"] if _, err := inspector.ArchiveAllScheduledTasks(qname); err != nil { @@ -452,7 +452,7 @@ func newArchiveAllScheduledTasksHandlerFunc(inspector *inspeq.Inspector) http.Ha } } -func newArchiveAllRetryTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newArchiveAllRetryTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { qname := mux.Vars(r)["qname"] if _, err := inspector.ArchiveAllRetryTasks(qname); err != nil { @@ -465,26 +465,26 @@ func newArchiveAllRetryTasksHandlerFunc(inspector *inspeq.Inspector) http.Handle // request body used for all batch delete tasks endpoints. type batchDeleteTasksRequest struct { - TaskKeys []string `json:"task_keys"` + TaskIDs []string `json:"task_ids"` } // Note: Redis does not have any rollback mechanism, so it's possible // to have partial success when doing a batch operation. -// For this reason this response contains a list of succeeded keys -// and a list of failed keys. +// For this reason this response contains a list of succeeded ids +// and a list of failed ids. type batchDeleteTasksResponse struct { - // task keys that were successfully deleted. - DeletedKeys []string `json:"deleted_keys"` + // task ids that were successfully deleted. + DeletedIDs []string `json:"deleted_ids"` - // task keys that were not deleted. - FailedKeys []string `json:"failed_keys"` + // task ids that were not deleted. + FailedIDs []string `json:"failed_ids"` } // Maximum request body size in bytes. // Allow up to 1MB in size. const maxRequestBodySize = 1000000 -func newBatchDeleteTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newBatchDeleteTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { r.Body = http.MaxBytesReader(w, r.Body, maxRequestBodySize) dec := json.NewDecoder(r.Body) @@ -499,15 +499,15 @@ func newBatchDeleteTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFun qname := mux.Vars(r)["qname"] resp := batchDeleteTasksResponse{ // avoid null in the json response - DeletedKeys: make([]string, 0), - FailedKeys: make([]string, 0), + DeletedIDs: make([]string, 0), + FailedIDs: make([]string, 0), } - for _, key := range req.TaskKeys { - if err := inspector.DeleteTaskByKey(qname, key); err != nil { - log.Printf("error: could not delete task with key %q: %v", key, err) - resp.FailedKeys = append(resp.FailedKeys, key) + for _, taskid := range req.TaskIDs { + if err := inspector.DeleteTask(qname, taskid); err != nil { + log.Printf("error: could not delete task with id %q: %v", taskid, err) + resp.FailedIDs = append(resp.FailedIDs, taskid) } else { - resp.DeletedKeys = append(resp.DeletedKeys, key) + resp.DeletedIDs = append(resp.DeletedIDs, taskid) } } if err := json.NewEncoder(w).Encode(resp); err != nil { @@ -518,17 +518,17 @@ func newBatchDeleteTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFun } type batchRunTasksRequest struct { - TaskKeys []string `json:"task_keys"` + TaskIDs []string `json:"task_ids"` } type batchRunTasksResponse struct { - // task keys that were successfully moved to the pending state. - PendingKeys []string `json:"pending_keys"` - // task keys that were not able to move to the pending state. - ErrorKeys []string `json:"error_keys"` + // task ids that were successfully moved to the pending state. + PendingIDs []string `json:"pending_ids"` + // task ids that were not able to move to the pending state. + ErrorIDs []string `json:"error_ids"` } -func newBatchRunTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newBatchRunTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { r.Body = http.MaxBytesReader(w, r.Body, maxRequestBodySize) dec := json.NewDecoder(r.Body) @@ -543,15 +543,15 @@ func newBatchRunTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { qname := mux.Vars(r)["qname"] resp := batchRunTasksResponse{ // avoid null in the json response - PendingKeys: make([]string, 0), - ErrorKeys: make([]string, 0), + PendingIDs: make([]string, 0), + ErrorIDs: make([]string, 0), } - for _, key := range req.TaskKeys { - if err := inspector.RunTaskByKey(qname, key); err != nil { - log.Printf("error: could not run task with key %q: %v", key, err) - resp.ErrorKeys = append(resp.ErrorKeys, key) + for _, taskid := range req.TaskIDs { + if err := inspector.RunTask(qname, taskid); err != nil { + log.Printf("error: could not run task with id %q: %v", taskid, err) + resp.ErrorIDs = append(resp.ErrorIDs, taskid) } else { - resp.PendingKeys = append(resp.PendingKeys, key) + resp.PendingIDs = append(resp.PendingIDs, taskid) } } if err := json.NewEncoder(w).Encode(resp); err != nil { @@ -562,17 +562,17 @@ func newBatchRunTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { } type batchArchiveTasksRequest struct { - TaskKeys []string `json:"task_keys"` + TaskIDs []string `json:"task_ids"` } type batchArchiveTasksResponse struct { - // task keys that were successfully moved to the archived state. - ArchivedKeys []string `json:"archived_keys"` - // task keys that were not able to move to the archived state. - ErrorKeys []string `json:"error_keys"` + // task ids that were successfully moved to the archived state. + ArchivedIDs []string `json:"archived_ids"` + // task ids that were not able to move to the archived state. + ErrorIDs []string `json:"error_ids"` } -func newBatchArchiveTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFunc { +func newBatchArchiveTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { r.Body = http.MaxBytesReader(w, r.Body, maxRequestBodySize) dec := json.NewDecoder(r.Body) @@ -587,15 +587,15 @@ func newBatchArchiveTasksHandlerFunc(inspector *inspeq.Inspector) http.HandlerFu qname := mux.Vars(r)["qname"] resp := batchArchiveTasksResponse{ // avoid null in the json response - ArchivedKeys: make([]string, 0), - ErrorKeys: make([]string, 0), + ArchivedIDs: make([]string, 0), + ErrorIDs: make([]string, 0), } - for _, key := range req.TaskKeys { - if err := inspector.ArchiveTaskByKey(qname, key); err != nil { - log.Printf("error: could not archive task with key %q: %v", key, err) - resp.ErrorKeys = append(resp.ErrorKeys, key) + for _, taskid := range req.TaskIDs { + if err := inspector.ArchiveTask(qname, taskid); err != nil { + log.Printf("error: could not archive task with id %q: %v", taskid, err) + resp.ErrorIDs = append(resp.ErrorIDs, taskid) } else { - resp.ArchivedKeys = append(resp.ArchivedKeys, key) + resp.ArchivedIDs = append(resp.ArchivedIDs, taskid) } } if err := json.NewEncoder(w).Encode(resp); err != nil {