-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrivers.go
More file actions
40 lines (33 loc) · 1.4 KB
/
drivers.go
File metadata and controls
40 lines (33 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package queue
import (
"errors"
"time"
)
// Driver Manages the connection to the background queue to keep track of tasks
type Driver interface {
clear() error // Clears the queue. Obviously, be careful
addTask(init TaskInit) error
// getTask(taskName string) (Task, error) // Grabs most recent entry for that task name
name() string // Returns a name for the driver
// pop Grabs the earliest task that's ready for action
pop() (Task, error)
// cleanup Gives the driver a chance to clean up the task, such as closing
// off any transactions
cleanup(Task)
// refreshRetry Refreshes all tasks marked as retry that are older than the specified interval
refreshRetry(age time.Duration) error
// complete Marks a task as complete
complete(task Task, message string) error
// cancel Marks a task as cancelled
cancel(task Task, message string) error
// fail Marks a task as permanently failed
fail(task Task, message string) error
// retry Marks a task as temporarily failed and in need of a retry later
retry(task Task, message string) error
// getQueueLength returns the number of total tasks currently in the queue
getQueueLength() (int64, error)
// getTaskCount returns the number of active tasks in the queue that have the given name
getTaskCount(taskName string) (int64, error)
}
// ErrNoTasks Returned when there are no tasks available in the queue
var ErrNoTasks = errors.New("no tasks available")