mirror of
https://github.com/hibiken/asynq.git
synced 2025-09-19 13:21:58 +08:00
Extract rdb to internal package
This commit is contained in:
14
client.go
14
client.go
@@ -4,21 +4,23 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hibiken/asynq/internal/rdb"
|
||||
)
|
||||
|
||||
// Client is an interface for scheduling tasks.
|
||||
type Client struct {
|
||||
rdb *rdb
|
||||
rdb *rdb.RDB
|
||||
}
|
||||
|
||||
// NewClient creates and returns a new client.
|
||||
func NewClient(config *RedisConfig) *Client {
|
||||
return &Client{rdb: newRDB(config)}
|
||||
r := rdb.NewRDB(newRedisClient(config))
|
||||
return &Client{r}
|
||||
}
|
||||
|
||||
// Process enqueues the task to be performed at a given time.
|
||||
func (c *Client) Process(task *Task, processAt time.Time) error {
|
||||
msg := &taskMessage{
|
||||
msg := &rdb.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
Type: task.Type,
|
||||
Payload: task.Payload,
|
||||
@@ -29,9 +31,9 @@ func (c *Client) Process(task *Task, processAt time.Time) error {
|
||||
}
|
||||
|
||||
// enqueue pushes a given task to the specified queue.
|
||||
func (c *Client) enqueue(msg *taskMessage, processAt time.Time) error {
|
||||
func (c *Client) enqueue(msg *rdb.TaskMessage, processAt time.Time) error {
|
||||
if time.Now().After(processAt) {
|
||||
return c.rdb.enqueue(msg)
|
||||
return c.rdb.Enqueue(msg)
|
||||
}
|
||||
return c.rdb.schedule(scheduled, processAt, msg)
|
||||
return c.rdb.Schedule(rdb.Scheduled, processAt, msg)
|
||||
}
|
||||
|
Reference in New Issue
Block a user