mirror of
https://github.com/hibiken/asynq.git
synced 2024-11-10 11:31:58 +08:00
client.Enqueue - prevent empty task's typename
This commit is contained in:
parent
73f930313c
commit
4bce28d677
@ -178,6 +178,9 @@ func (d processInOption) Value() interface{} { return time.Duration(d) }
|
|||||||
// ErrDuplicateTask error only applies to tasks enqueued with a Unique option.
|
// ErrDuplicateTask error only applies to tasks enqueued with a Unique option.
|
||||||
var ErrDuplicateTask = errors.New("task already exists")
|
var ErrDuplicateTask = errors.New("task already exists")
|
||||||
|
|
||||||
|
// ErrEmptyTypeTask indicates that task's typename is not specified.
|
||||||
|
var ErrEmptyTypeTask = errors.New("task typename not specified")
|
||||||
|
|
||||||
type option struct {
|
type option struct {
|
||||||
retry int
|
retry int
|
||||||
queue string
|
queue string
|
||||||
@ -266,6 +269,9 @@ func (c *Client) Close() error {
|
|||||||
//
|
//
|
||||||
// If no ProcessAt or ProcessIn options are provided, the task will be pending immediately.
|
// If no ProcessAt or ProcessIn options are provided, the task will be pending immediately.
|
||||||
func (c *Client) Enqueue(task *Task, opts ...Option) (*TaskInfo, error) {
|
func (c *Client) Enqueue(task *Task, opts ...Option) (*TaskInfo, error) {
|
||||||
|
if task.Type() == "" {
|
||||||
|
return nil, fmt.Errorf("%w", ErrEmptyTypeTask)
|
||||||
|
}
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
if defaults, ok := c.opts[task.Type()]; ok {
|
if defaults, ok := c.opts[task.Type()]; ok {
|
||||||
opts = append(defaults, opts...)
|
opts = append(defaults, opts...)
|
||||||
|
@ -585,6 +585,11 @@ func TestClientEnqueueError(t *testing.T) {
|
|||||||
Queue(""),
|
Queue(""),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "With empty task typename",
|
||||||
|
task: NewTask("", h.JSON(map[string]interface{}{})),
|
||||||
|
opts: []Option{},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
|
Loading…
Reference in New Issue
Block a user