github.com/uber/kraken@v0.1.4/lib/persistedretry/interfaces.go (about) 1 // Copyright (c) 2016-2019 Uber Technologies, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 package persistedretry 15 16 import "time" 17 18 // Task represents a single unit of work which must eventually succeed. 19 type Task interface { 20 GetLastAttempt() time.Time 21 GetFailures() int 22 Ready() bool 23 24 // Tags returns tags describing the context of the task, which can be 25 // included on metrics to group related instances of a task. 26 Tags() map[string]string 27 } 28 29 // Store provides persisted storage for tasks. 30 type Store interface { 31 // AddPending adds a new task as pending in the store. Implementations should 32 // return ErrTaskExists if the task is already in the store. 33 AddPending(Task) error 34 35 // AddFailed adds a new task as failed in the store. Implementations should 36 // return ErrTaskExists if the task is already in the store. 37 AddFailed(Task) error 38 39 // MarkPending marks an existing task as pending. 40 MarkPending(Task) error 41 42 // MarkFailed marks an existing task as failed. 43 MarkFailed(Task) error 44 45 // GetPending returns all pending Tasks. 46 GetPending() ([]Task, error) 47 48 // GetFailed returns all failed Tasks. 49 GetFailed() ([]Task, error) 50 51 // Remove removes a task from the store. 52 Remove(Task) error 53 54 // Find returns tasks which match a query. 55 Find(query interface{}) ([]Task, error) 56 } 57 58 // Executor executes tasks. 59 type Executor interface { 60 Exec(Task) error 61 Name() string 62 }