2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-09-20 11:05:58 +08:00

Add changelog entry, add additional test case

This commit is contained in:
Luqqk 2021-08-03 00:11:49 +02:00 committed by Ken Hibino
parent 6817af366a
commit 95c90a5cb8
3 changed files with 10 additions and 4 deletions

View File

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Changed
- `Client.Enqueue` no longer enqueues tasks with empty typename; Error message is returned.
## [0.18.2] - 2020-07-15 ## [0.18.2] - 2020-07-15
### Changed ### Changed

View File

@ -179,9 +179,6 @@ 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")
// ErrEmptyTypename indicates that task's typename is empty.
var ErrEmptyTypename = errors.New("task typename cannot be empty")
type option struct { type option struct {
retry int retry int
queue string queue string
@ -271,7 +268,7 @@ 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 strings.TrimSpace(task.Type()) == "" { if strings.TrimSpace(task.Type()) == "" {
return nil, fmt.Errorf("%w", ErrEmptyTypename) return nil, fmt.Errorf("task typename cannot be empty")
} }
c.mu.Lock() c.mu.Lock()
if defaults, ok := c.opts[task.Type()]; ok { if defaults, ok := c.opts[task.Type()]; ok {

View File

@ -590,6 +590,11 @@ func TestClientEnqueueError(t *testing.T) {
task: NewTask("", h.JSON(map[string]interface{}{})), task: NewTask("", h.JSON(map[string]interface{}{})),
opts: []Option{}, opts: []Option{},
}, },
{
desc: "With blank task typename",
task: NewTask(" ", h.JSON(map[string]interface{}{})),
opts: []Option{},
},
} }
for _, tc := range tests { for _, tc := range tests {