Documentation ¶
Overview ¶
Package postgresql implements tmanager.Storage interface using Postgresql database.
Index ¶
- Variables
- type Config
- type Storage
- func (s *Storage) CreateOneActiveTask(ctx context.Context, task tmanager.Task) error
- func (s *Storage) CreateTasks(ctx context.Context, tasks ...tmanager.Task) error
- func (s *Storage) DeleteCompletedTasks(ctx context.Context, olderThen time.Time) error
- func (s *Storage) DeleteNamedCompletedTasks(ctx context.Context, olderThen time.Time, names ...string) error
- func (s *Storage) GetFailedTasks(ctx context.Context) ([]inspector.Task, error)
- func (s *Storage) GetNextTask(ctx context.Context, now time.Time) (tmanager.Task, error)
- func (s *Storage) GetStuckedTasks(ctx context.Context, inWorkBefore time.Time) ([]inspector.Task, error)
- func (s *Storage) RestartTask(ctx context.Context, task tmanager.Task, restartAfter time.Time) error
- func (s *Storage) SaveTaskWithError(ctx context.Context, task tmanager.Task, taskErr error) error
- func (s *Storage) SaveTaskWithSuccess(ctx context.Context, task tmanager.Task) error
- type Task
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidDataJSONB = errors.New("invalid data for JSONB type")
ErrInvalidDataJSONB returns when database returns wrong type for JSON field.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Schema with tables in database, postgres current_schema by default. Schema string // TableName table name with tasks, "tmanager_tasks" by default. TableName string }
Config optional config of the postgresql connection. Feel free to skip any of fields.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage contains methods to manage tasks in database.
func New ¶
New creates new schema and task table if not exists. Takes std sql connection and optional (may be nil) config with schema and table name.
func (*Storage) CreateOneActiveTask ¶
CreateOneActiveTask creates table constraint to control that DB contains only one active task and creates task with ignoring conflict.
func (*Storage) CreateTasks ¶
CreateTasks creates list of the tasks in the DB.
func (*Storage) DeleteCompletedTasks ¶
DeleteCompletedTasks delete completed tasks completed before olderThen param.
func (*Storage) DeleteNamedCompletedTasks ¶ added in v0.0.5
func (s *Storage) DeleteNamedCompletedTasks(ctx context.Context, olderThen time.Time, names ...string) error
DeleteNamedCompletedTasks delete completed tasks with special handler names and completed before olderThen param.
func (*Storage) GetFailedTasks ¶
GetFailedTasks returns failed tasks. Failed task it is undone task with error. Returns empty slcie when storage can't found failed tasks.
func (*Storage) GetNextTask ¶
GetNextTask returns the oldest task that the worker has not yet taken to work. Value of the StartAfter must be less then "now" argument. Returns error ErrTaskNotFound when can't found task.
func (*Storage) GetStuckedTasks ¶
func (s *Storage) GetStuckedTasks(ctx context.Context, inWorkBefore time.Time) ([]inspector.Task, error)
GetStuckedTasks returns stucked tasks. Stuck task it is task without error and taked in work before inWorkBefore. Returns empty slcie when storage can't found stucked tasks.
func (*Storage) RestartTask ¶
func (s *Storage) RestartTask(ctx context.Context, task tmanager.Task, restartAfter time.Time) error
RestartTask makes the task free to re-taking in GetNextTask method. You have to set time to re-taking.
func (*Storage) SaveTaskWithError ¶
SaveTaskWithError saves task with error. Saved previous error text in the column.
type Task ¶
type Task struct { ID int64 CreatedAt time.Time UpdatedAt time.Time InWorkAt *time.Time // time when the task was taken to work, will be nil in the new task DoneAt *time.Time // time when the task was done Error *string // error text of the task StartAfter time.Time // time after which the task should be started. Handler string // name of the task handler Data jsonb // data of the handler }
Task is a database model of the task.
func (*Task) GetData ¶
func (t *Task) GetData() json.RawMessage
GetData returns data of the handler.
func (*Task) GetHandler ¶
GetHandler returns name of the task handler.
func (*Task) GetStartAfter ¶
GetStartAfter returns time after which the task should be started.