mirror of
https://github.com/hibiken/asynq.git
synced 2024-12-25 23:32:17 +08:00
Rename (*rdb).push to enqueue
This commit is contained in:
parent
737de898eb
commit
faa9b6ee22
@ -37,7 +37,7 @@ func (c *Client) Process(task *Task, executeAt time.Time) error {
|
||||
// enqueue pushes a given task to the specified queue.
|
||||
func (c *Client) enqueue(msg *taskMessage, executeAt time.Time) error {
|
||||
if time.Now().After(executeAt) {
|
||||
return c.rdb.push(msg)
|
||||
return c.rdb.enqueue(msg)
|
||||
}
|
||||
return c.rdb.zadd(scheduled, float64(executeAt.Unix()), msg)
|
||||
}
|
||||
|
7
rdb.go
7
rdb.go
@ -37,8 +37,9 @@ func newRDB(client *redis.Client) *rdb {
|
||||
return &rdb{client}
|
||||
}
|
||||
|
||||
// push enqueues the task to queue.
|
||||
func (r *rdb) push(msg *taskMessage) error {
|
||||
// enqueue inserts the given task to the end of the queue.
|
||||
// It also adds the queue name to the "all-queues" list.
|
||||
func (r *rdb) enqueue(msg *taskMessage) error {
|
||||
bytes, err := json.Marshal(msg)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not encode task into JSON: %v", err)
|
||||
@ -130,7 +131,7 @@ func (r *rdb) move(from string, msg *taskMessage) error {
|
||||
return errSerializeTask
|
||||
}
|
||||
if r.client.ZRem(from, string(bytes)).Val() > 0 {
|
||||
err = r.push(msg)
|
||||
err = r.enqueue(msg)
|
||||
if err != nil {
|
||||
log.Printf("[SERVERE ERROR] could not push task to queue %q: %v\n",
|
||||
msg.Queue, err)
|
||||
|
@ -42,7 +42,7 @@ func randomTask(taskType, qname string, payload map[string]interface{}) *taskMes
|
||||
}
|
||||
}
|
||||
|
||||
func TestPush(t *testing.T) {
|
||||
func TestEnqueue(t *testing.T) {
|
||||
r := setup(t)
|
||||
tests := []struct {
|
||||
msg *taskMessage
|
||||
@ -53,7 +53,7 @@ func TestPush(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
err := r.push(tc.msg)
|
||||
err := r.enqueue(tc.msg)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -83,7 +83,7 @@ func TestPush(t *testing.T) {
|
||||
func TestDequeueImmediateReturn(t *testing.T) {
|
||||
r := setup(t)
|
||||
msg := randomTask("export_csv", "csv", nil)
|
||||
r.push(msg)
|
||||
r.enqueue(msg)
|
||||
|
||||
res, err := r.dequeue("asynq:queues:csv", time.Second)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user