Documentation
¶
Index ¶
- Constants
- Variables
- type Account
- type Application
- type Attempt
- type Base
- func (b *Base) AckAttempt(attemptID bson.ObjectId) (err error)
- func (b *Base) AuthenticateAccount(account bson.ObjectId, key string) (bool, error)
- func (b *Base) Bootstrap() error
- func (b *Base) CleanDeletedRessources() error
- func (b *Base) CleanFinishedAttempts(seconds int64) (deleted int, err error)
- func (b *Base) DeQueue(queueID bson.ObjectId, attemptID bson.ObjectId) (err error)
- func (b *Base) DeleteAccount(account bson.ObjectId) (err error)
- func (b *Base) DeleteApplication(account bson.ObjectId, name string) (err error)
- func (b *Base) DeleteApplications(account bson.ObjectId) (err error)
- func (b *Base) DeletePendingAttempts(taskID bson.ObjectId) (bool, error)
- func (b *Base) DeleteQueue(account bson.ObjectId, application string, name string) (err error)
- func (b *Base) DeleteQueues(account bson.ObjectId, application string) (err error)
- func (b *Base) DeleteTask(account bson.ObjectId, application string, name string) (err error)
- func (b *Base) DeleteTasks(account bson.ObjectId, application string) (err error)
- func (b *Base) DoAttempt(attempt *Attempt) error
- func (b *Base) EnQueue(queueID bson.ObjectId, attemptID bson.ObjectId) (full bool, err error)
- func (b *Base) EnsureApplicationIndex() (err error)
- func (b *Base) EnsureAttemptIndex() (err error)
- func (b *Base) EnsureQueueIndex() (err error)
- func (b *Base) EnsureTaskIndex() (err error)
- func (b *Base) FixIntegrity() error
- func (b *Base) FixQueues() (err error)
- func (b *Base) ForceAttemptForTask(account bson.ObjectId, application string, name string) (attempt *Attempt, err error)
- func (b *Base) GetAccount(accountID bson.ObjectId) (account *Account, err error)
- func (b *Base) GetAccounts(lp ListParams, lr *ListResult) (err error)
- func (b *Base) GetApplication(account bson.ObjectId, name string) (application *Application, err error)
- func (b *Base) GetApplications(account bson.ObjectId, lp ListParams, lr *ListResult) (err error)
- func (b *Base) GetAttempt(attemptID bson.ObjectId) (*Attempt, error)
- func (b *Base) GetAttemptByID(attemptID bson.ObjectId) (attempt *Attempt, err error)
- func (b *Base) GetAttempts(account bson.ObjectId, application string, task string, lp ListParams, ...) (err error)
- func (b *Base) GetQueue(account bson.ObjectId, application string, name string) (queue *Queue, err error)
- func (b *Base) GetQueues(account bson.ObjectId, application string, lp ListParams, lr *ListResult) (err error)
- func (b *Base) GetTask(account bson.ObjectId, application string, name string) (task *Task, err error)
- func (b *Base) GetTaskByID(taskID bson.ObjectId) (task *Task, err error)
- func (b *Base) GetTasks(account bson.ObjectId, application string, lp ListParams, lr *ListResult) (err error)
- func (b *Base) NewAccount(name *string) (account *Account, err error)
- func (b *Base) NewApplication(account bson.ObjectId, name string) (application *Application, err error)
- func (b *Base) NewAttempt(task *Task, deletePending bool, force bool) (*Attempt, error)
- func (b *Base) NewQueue(account bson.ObjectId, applicationName string, name string, retry *Retry, ...) (queue *Queue, err error)
- func (b *Base) NewTask(account bson.ObjectId, applicationName string, name string, queueName string, ...) (task *Task, err error)
- func (b *Base) NextAttempt(ttr int64) (*Attempt, error)
- func (b *Base) NextAttemptForTask(attempt *Attempt) (nextAttempt *Attempt, err error)
- func (b *Base) SetAttemptQueuedForTask(task *Task) (err error)
- func (b *Base) ShouldRefreshSession(err error) (bool, error)
- func (b *Base) TouchAttempt(attemptID bson.ObjectId, seconds int64) error
- func (b *Base) UpdateAccount(accountID bson.ObjectId, name *string) (account *Account, err error)
- type HTTPAuth
- type ListParams
- type ListResult
- type Queue
- type Retry
- type Task
Constants ¶
const (
// DefaultMaxInFlight is the maximum number of tasks executed in parallel.
DefaultMaxInFlight = 10
)
Variables ¶
var ( // ErrDeleteDefaultApplication is returned when trying to delete the default application. ErrDeleteDefaultApplication = errors.New("can not delete default application") // ErrApplicationNotFound is returned when the application does not exist. ErrApplicationNotFound = errors.New("application does not exist") )
var ( // ModelsBaseDebug ... ModelsBaseDebug = debug.Debug("hooky.models.base") ErrDatabase = fmt.Errorf("Database Error") )
var ( // ErrDeleteDefaultQueue is returned when trying to delete the default queue. ErrDeleteDefaultQueue = errors.New("can not delete default queue") // ErrQueueNotFound is returned when the queue does not exist. ErrQueueNotFound = errors.New("queue does not exist") )
var AttemptStatuses = map[string]bool{ "pending": true, "running": true, "success": true, "error": true, }
AttemptStatuses
var ( // ErrMaxAttemptsExceeded indicates that the maximum retries has been // excedeed. Usually to consider a service unreachable/unavailable. ErrMaxAttemptsExceeded = errors.New("maximum of attempts exceeded") )
var (
// ModelsAttemptDebug ...
ModelsAttemptDebug = debug.Debug("hooky.models.attempt")
)
var (
// ModelsTaskDebug ...
ModelsTaskDebug = debug.Debug("hooky.models.task")
)
var TaskStatuses = map[string]bool{ "pending": true, "retrying": true, "canceled": true, "success": true, "error": true, }
TaskStatuses are the differents statuses that a Task can have.
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct { // ID is the ID of the Account. ID bson.ObjectId `bson:"_id"` // Name is display name for the Account. Name *string `bson:"name,omitempty"` // Key is the secret key to authenticate the Account ID. Key string `bson:"key"` // Deleted Deleted bool `bson:"deleted"` }
Account is an account to access the service.
type Application ¶
type Application struct { // ID is the ID of the Application. ID bson.ObjectId `bson:"_id"` // Account is the ID of the Account owning the Application. Account bson.ObjectId `bson:"account"` // Name is the Application's name. Name string `bson:"name"` // Deleted Deleted bool `bson:"deleted"` }
Application is a list of recurring Tasks.
type Attempt ¶
type Attempt struct { // ID is the ID of the attempt. ID bson.ObjectId `bson:"_id"` // Account is the ID of the Account owning the Task. Account bson.ObjectId `bson:"account"` // Application is the name of the parent Application. Application string `bson:"application"` // Task is the task's name. Task string `bson:"task"` // TaskID is the ID of the parent Task of this attempt. TaskID bson.ObjectId `bson:"task_id"` // Queue is the name of the parent Queue. Queue string `bson:"queue"` // QueueID is the ID of the parent Queue QueueID bson.ObjectId `bson:"queue_id"` // URL is the URL that the worker with requests. URL string `bson:"url"` // HTTPAuth is the HTTP authentication to use if any. HTTPAuth HTTPAuth `json:"auth"` // Method is the HTTP method that will be used to execute the request. Method string `bson:"method"` // Headers are the HTTP headers that will be used when executing the request. Headers map[string]string `bson:"headers"` // Payload is a arbitrary data that will be POSTed on the URL. Payload string `bson:"payload"` // Reserved is a Unix timestamp until when the attempt is reserved by a worker. Reserved int64 `bson:"reserved"` // At is a Unix timestamp representing the time a request must be performed. At int64 `bson:"at"` // Finished is a Unix timestamp representing the time the attempt finished. Finished int64 `bson:"finished,omitempty"` // Status is either `pending`, `running`, `success` or `error` Status string `bson:"status"` // StatusCode is the HTTP status code. StatusCode int32 `bson:"status_code,omitempty"` // StatusMessage is a human readable message related to the Status. StatusMessage string `bson:"status_message,omitempty"` // Acked Acked bool `bson:"acked"` // Deleted Deleted bool `bson:"deleted"` }
Attempt describes a HTTP request that must be perform for a task.
type Base ¶
type Base struct {
// contains filtered or unexported fields
}
func (*Base) AckAttempt ¶
AckAttempt marks the attempt as acknowledged.
func (*Base) AuthenticateAccount ¶
AuthenticateAccount authenticates an Account.
func (*Base) CleanDeletedRessources ¶
CleanDeletedRessources cleans ressources that have been deleted.
func (*Base) CleanFinishedAttempts ¶
CleanFinishedAttempts cleans attempts that are finished since more than X seconds.
func (*Base) DeleteAccount ¶
DeleteAccount deletes an Account given its ID.
func (*Base) DeleteApplication ¶
DeleteApplication deletes an Application and all its children.
func (*Base) DeleteApplications ¶
DeleteApplications deletes all Applications owns by an Account.
func (*Base) DeletePendingAttempts ¶
DeletePendingAttempts deletes all pending Attempts for a given Task ID.
func (*Base) DeleteQueue ¶
DeleteQueue deletes an Queue and all its children.
func (*Base) DeleteQueues ¶
DeleteQueues deletes all Queues owns by an Account.
func (*Base) DeleteTask ¶
DeleteTask deletes a Task.
func (*Base) DeleteTasks ¶
DeleteTasks deletes all Tasks from an Application.
func (*Base) EnsureApplicationIndex ¶
EnsureApplicationIndex creates mongo indexes for Application.
func (*Base) EnsureAttemptIndex ¶
EnsureAttemptIndex creates mongo indexes for Application.
func (*Base) EnsureQueueIndex ¶
EnsureQueueIndex creates mongo indexes for Queue.
func (*Base) EnsureTaskIndex ¶
EnsureTaskIndex creates mongo indexes for Application.
func (*Base) ForceAttemptForTask ¶
func (b *Base) ForceAttemptForTask(account bson.ObjectId, application string, name string) (attempt *Attempt, err error)
ForceAttemptForTask ...
func (*Base) GetAccount ¶
GetAccount returns an Account given its ID.
func (*Base) GetAccounts ¶
func (b *Base) GetAccounts(lp ListParams, lr *ListResult) (err error)
GetAccounts returns a list of Accounts.
func (*Base) GetApplication ¶
func (b *Base) GetApplication(account bson.ObjectId, name string) (application *Application, err error)
GetApplication returns an Application.
func (*Base) GetApplications ¶
func (b *Base) GetApplications(account bson.ObjectId, lp ListParams, lr *ListResult) (err error)
GetApplications returns a list of Applications.
func (*Base) GetAttempt ¶
GetAttempt returns an Attempt.
func (*Base) GetAttemptByID ¶
GetAttemptByID returns a Attempt given its ID.
func (*Base) GetAttempts ¶
func (b *Base) GetAttempts(account bson.ObjectId, application string, task string, lp ListParams, lr *ListResult) (err error)
GetAttempts returns a list of Attempts.
func (*Base) GetQueue ¶
func (b *Base) GetQueue(account bson.ObjectId, application string, name string) (queue *Queue, err error)
GetQueue returns a Queue.
func (*Base) GetQueues ¶
func (b *Base) GetQueues(account bson.ObjectId, application string, lp ListParams, lr *ListResult) (err error)
GetQueues returns a list of Queues.
func (*Base) GetTask ¶
func (b *Base) GetTask(account bson.ObjectId, application string, name string) (task *Task, err error)
GetTask returns a Task.
func (*Base) GetTaskByID ¶
GetTaskByID returns a Task given its ID.
func (*Base) GetTasks ¶
func (b *Base) GetTasks(account bson.ObjectId, application string, lp ListParams, lr *ListResult) (err error)
GetTasks returns a list of Tasks.
func (*Base) NewAccount ¶
NewAccount creates a new Account.
func (*Base) NewApplication ¶
func (b *Base) NewApplication(account bson.ObjectId, name string) (application *Application, err error)
NewApplication creates a new Application.
func (*Base) NewAttempt ¶
NewAttempt creates a new Attempt.
func (*Base) NewQueue ¶
func (b *Base) NewQueue(account bson.ObjectId, applicationName string, name string, retry *Retry, maxInFlight int) (queue *Queue, err error)
NewQueue creates a new Queue.
func (*Base) NewTask ¶
func (b *Base) NewTask(account bson.ObjectId, applicationName string, name string, queueName string, URL string, auth HTTPAuth, method string, headers map[string]string, payload string, schedule string, retry *Retry, active bool) (task *Task, err error)
NewTask creates a new Task.
func (*Base) NextAttempt ¶
NextAttempt reserves and returns the next Attempt.
func (*Base) NextAttemptForTask ¶
NextAttemptForTask enqueue the next Attempt if any and returns it.
func (*Base) SetAttemptQueuedForTask ¶
SetAttemptQueuedForTask marks the attempt as queued for a given task ID.
func (*Base) ShouldRefreshSession ¶
ShouldRefreshSession checks if we should refresh the mongo session
func (*Base) TouchAttempt ¶
TouchAttempt reserves an attemptsttempt for more time.
type HTTPAuth ¶
type HTTPAuth struct { Username string `json:"username,omitempty" bson:"username,omitempty"` Password string `json:"password,omitempty" bson:"password,omitempty"` }
HTTPAuth is used for HTTP Basic Auth.
type ListParams ¶
type ListResult ¶
type ListResult struct { List interface{} `json:"list"` HasMore bool `json:"hasMore"` Total int `json:"total"` Count int `json:"count"` Page int `json:"page"` Pages int `json:"pages"` }
ListResult is the structure used for listing collections.
type Queue ¶
type Queue struct { // ID is the ID of the Queue. ID bson.ObjectId `bson:"_id"` // Account is the ID of the Account owning the Queue. Account bson.ObjectId `bson:"account"` // Application is the name of the parent Application. Application string `bson:"application"` // Name is the Queue's name. Name string `bson:"name"` // Retry is the retry strategy parameters in case of errors. Retry *Retry `bson:"retry"` // Deleted Deleted bool `bson:"deleted"` // MaxInFlight is the maximum number of attempts executed in parallel. MaxInFlight int `bson:"max_in_flight"` // AvailableInFlight is the available number of slots to execute tasks in parallel. AvailableInFlight int `bson:"available_in_flight"` // AttemptsInFlight is the list of attempts currently in flight. AttemptsInFlight []bson.ObjectId `bson:"attempts_in_flight"` }
Queue ...
type Retry ¶
type Retry struct { // Attempts is the current number of attempts we did. Attempts int `bson:"attempts" json:"attempts"` // MaxAttempts is the maximum number of attempts we will try. MaxAttempts int `bson:"max_attempts" json:"maxAttempts"` // Factor is factor to increase the duration between each attempts. Factor float64 `bson:"factor" json:"factor"` // Min is the minimum duration between each attempts in seconds. Min int `bson:"min" json:"min"` // Max is the maximum duration between each attempts in seconds. Max int `bson:"max" json:"max"` }
func (*Retry) SetDefault ¶
func (r *Retry) SetDefault()
type Task ¶
type Task struct { // ID is the ID of the Task. ID bson.ObjectId `bson:"_id"` // Account is the ID of the Account owning the Task. Account bson.ObjectId `bson:"account"` // Application is the name of the parent Application. Application string `bson:"application"` // Name is the task's name. Name string `bson:"name"` // Queue is the name of the parent Queue. Queue string `bson:"queue"` // QueueID is the ID of the parent Queue QueueID bson.ObjectId `bson:"queue_id"` // URL is the URL that the worker with requests. URL string `bson:"url"` // HTTPAuth is the HTTP authentication to use if any. HTTPAuth HTTPAuth `bson:"auth"` // Method is the HTTP method that will be used to execute the request. Method string `bson:"method"` // Headers are the HTTP headers that will be used when executing the request. Headers map[string]string `bson:"headers,omitempty"` // Payload is arbitrary data that will be POSTed on the URL. Payload string `bson:"payload,omitempty"` // Schedule is a cron specification describing the recurrency if any. Schedule string `bson:"schedule"` // At is a Unix timestamp representing the next time a request must be performed. At int64 `bson:"at"` // Status is either `pending`, `retrying`, `canceled`, `success` or `error` Status string `bson:"status"` // Executed is the timestamp of the last time a attempt was executed. Executed int64 `bson:"executed,omitempty"` // Active is the task active. Active bool `bson:"active"` // Errors counts the number of attempts that failed. Errors int `bson:"errors,omitempty"` // LastError is the timestamp of the last attempt in error status LastError int64 `bson:"last_error,omitempty"` // LastSuccess is the timestamp of the last attempt in success status LastSuccess int64 `bson:"last_success,omitempty"` // Executions counts the number of attempts that were executed. Executions int `bson:"executions,omitempty"` // Retry is the retry strategy parameters in case of errors. Retry *Retry `bson:"retry"` // CurrentAttempt is the current attempt ID for this task. CurrentAttempt bson.ObjectId `bson:"current_attempt"` // AttemptQueued is set to true when the attempt as been successfully created. AttemptQueued bool `bson:"attempt_queued"` // AttemptUpdated is the Unix timestamp of the last update of the current attempt. AttemptUpdated int64 `bson:"attempt_updated"` // Deleted Deleted bool `bson:"deleted"` }
Task describes a Task.