-
Notifications
You must be signed in to change notification settings - Fork 9
/
store.go
81 lines (66 loc) · 2.88 KB
/
store.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2016-present Oliver Eilhard. All rights reserved.
// Use of this source code is governed by a MIT-license.
// See http://olivere.mit-license.org/license.txt for details.
package jobqueue
import (
"context"
"errors"
)
var (
// ErrNotFound must be returned from Store implementation when a certain job
// could not be found in the specific data store.
ErrNotFound = errors.New("jobqueue: job not found")
)
// Store implements persistent storage of jobs.
type Store interface {
// Start is called when the manager starts up.
// This is a good time for cleanup. E.g. a persistent store might moved
// crashed jobs from a previous run into the Failed state.
Start(StartupBehaviour) error
// Create adds a job to the store.
Create(context.Context, *Job) error
// Delete removes a job from the store.
Delete(context.Context, *Job) error
// Update updates a job in the store. This is called frequently as jobs
// are processed. Update must allow for concurrent updates, e.g. by locking.
Update(context.Context, *Job) error
// Next picks the next job to execute.
//
// The store should take the job priorities into account when picking the
// next job. Jobs with higher priorities should be executed first.
//
// If no job is ready to be executed, e.g. the job queue is idle, the
// store must return nil for both the job and the error.
Next() (*Job, error)
// Stats returns statistics about the store, e.g. the number of jobs
// waiting, working, succeeded, and failed. This is run when the manager
// starts up to get initial stats.
Stats(context.Context, *StatsRequest) (*Stats, error)
// Lookup returns the details of a job by its identifier.
// If the job could not be found, ErrNotFound must be returned.
Lookup(context.Context, string) (*Job, error)
// LookupByCorrelationID returns the details of jobs by their correlation identifier.
// If no such job could be found, an empty array is returned.
LookupByCorrelationID(context.Context, string) ([]*Job, error)
// List returns a list of jobs filtered by the ListRequest.
List(context.Context, *ListRequest) (*ListResponse, error)
}
// StatsRequest returns information about the number of managed jobs.
type StatsRequest struct {
Topic string // filter by topic
CorrelationGroup string // filter by correlation group
}
// ListRequest specifies a filter for listing jobs.
type ListRequest struct {
Topic string // filter by topic
CorrelationGroup string // filter by correlation group
CorrelationID string // filter by correlation identifier
State string // filter by job state
Limit int // maximum number of jobs to return
Offset int // number of jobs to skip (for pagination)
}
// ListResponse is the outcome of invoking List on the Store.
type ListResponse struct {
Total int // total number of jobs found, excluding pagination
Jobs []*Job // list of jobs
}