/
engine.go
67 lines (59 loc) · 3.24 KB
/
engine.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
// Package engine defines the interface for storage engine implementations.
package engine
import (
"context"
"github.com/hyperonym/ratus"
)
// Engine defines the interface for storage engine implementations.
type Engine interface {
// Open or connect to the storage engine.
Open(ctx context.Context) error
// Close or disconnect from the storage engine.
Close(ctx context.Context) error
// Destroy clears all data and closes the storage engine.
Destroy(ctx context.Context) error
// Ready probes the storage engine and returns an error if it is not ready.
Ready(ctx context.Context) error
// Chore recovers timed out tasks and deletes expired tasks.
Chore(ctx context.Context) error
// Poll makes a promise to claim and execute the next available task in a topic.
Poll(ctx context.Context, topic string, p *ratus.Promise) (*ratus.Task, error)
// Commit applies a set of updates to a task and returns the updated task.
Commit(ctx context.Context, id string, m *ratus.Commit) (*ratus.Task, error)
// ListTopics lists all topics.
ListTopics(ctx context.Context, limit, offset int) ([]*ratus.Topic, error)
// DeleteTopics deletes all topics and tasks.
DeleteTopics(ctx context.Context) (*ratus.Deleted, error)
// GetTopic gets information about a topic.
GetTopic(ctx context.Context, topic string) (*ratus.Topic, error)
// DeleteTopic deletes a topic and its tasks.
DeleteTopic(ctx context.Context, topic string) (*ratus.Deleted, error)
// ListTasks lists all tasks in a topic.
ListTasks(ctx context.Context, topic string, limit, offset int) ([]*ratus.Task, error)
// InsertTasks inserts a batch of tasks while ignoring existing ones.
InsertTasks(ctx context.Context, ts []*ratus.Task) (*ratus.Updated, error)
// UpsertTasks inserts or updates a batch of tasks.
UpsertTasks(ctx context.Context, ts []*ratus.Task) (*ratus.Updated, error)
// DeleteTasks deletes all tasks in a topic.
DeleteTasks(ctx context.Context, topic string) (*ratus.Deleted, error)
// GetTask gets a task by its unique ID.
GetTask(ctx context.Context, id string) (*ratus.Task, error)
// InsertTask inserts a new task.
InsertTask(ctx context.Context, t *ratus.Task) (*ratus.Updated, error)
// UpsertTask inserts or updates a task.
UpsertTask(ctx context.Context, t *ratus.Task) (*ratus.Updated, error)
// DeleteTask deletes a task by its unique ID.
DeleteTask(ctx context.Context, id string) (*ratus.Deleted, error)
// ListPromises lists all promises in a topic.
ListPromises(ctx context.Context, topic string, limit, offset int) ([]*ratus.Promise, error)
// DeletePromises deletes all promises in a topic.
DeletePromises(ctx context.Context, topic string) (*ratus.Deleted, error)
// GetPromise gets a promise by the unique ID of its target task.
GetPromise(ctx context.Context, id string) (*ratus.Promise, error)
// InsertPromise makes a promise to claim and execute a task if it is in pending state.
InsertPromise(ctx context.Context, p *ratus.Promise) (*ratus.Task, error)
// UpsertPromise makes a promise to claim and execute a task regardless of its current state.
UpsertPromise(ctx context.Context, p *ratus.Promise) (*ratus.Task, error)
// DeletePromise deletes a promise by the unique ID of its target task.
DeletePromise(ctx context.Context, id string) (*ratus.Deleted, error)
}