Documentation ¶
Index ¶
- Variables
- type Client
- func (c *Client) CreateJob(newJob NewJobDTO) (job *Job, err error)
- func (c *Client) CreateJobs(newJobs []NewJobDTO) (results []*Job, err error)
- func (c *Client) GetEndpoint() string
- func (c *Client) GetJob(additionalInstances []string) (err error)
- func (c *Client) HeartBeat(status map[string]interface{}) (err error)
- func (c *Client) MarkCurrentJobAsCompleted() (err error)
- func (c *Client) ReleaseCurrentJob() (err error)
- func (c *Client) StartCurrentJob() (err error)
- func (c *Client) UseBulk() *Client
- func (c *Client) UseDefault() *Client
- type Job
- type JobService
- type JobTask
- type NewJobDTO
- type ResponseDTO
- type ResponseMultipleDTO
- type Stats
Constants ¶
This section is empty.
Variables ¶
var ErrNo20XStatus = errors.New("no 20X status")
ErrNo20XStatus is returned if there is no 200 status code
var ErrNoJobSet = errors.New("no current job set")
var ( // ErrNoNewJobs is the error returned when there are no new jobs ErrNoNewJobs = errors.New("can not find a job") )
var ErrPayloadHasNoName = errors.New("payload has no name")
ErrPayloadHasNoName is returned if the payload has no name
var ErrWorkerInstanceNotSet = errors.New("worker instance not set")
ErrWorkerInstanceNotSet is returned if the worker instance is not set
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { Endpoint string // endpoint of the job dispatcher UUID uuid.UUID // uuid of the client WorkerInstance string // worker instance CurrentJob *Job // current job Bulk bool // use bulk endpoint Logger *log.Entry // logger }
Client is the client for the job dispatcher
func (*Client) CreateJobs ¶
CreateJobs creates multiple job at once
func (*Client) GetEndpoint ¶
func (*Client) MarkCurrentJobAsCompleted ¶
MarkCurrentJobAsCompleted marks the current job as completed
func (*Client) ReleaseCurrentJob ¶
ReleaseCurrentJob releases the current job
func (*Client) StartCurrentJob ¶
StartCurrentJob marks the current job as started
func (*Client) UseDefault ¶
UseDefault uses the default endpoint
type Job ¶
type Job struct { UUID uuid.UUID `gorm:"type:varchar(36); primaryKey" json:"uuid"` // Metadata CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` DeletedAt *time.Time `gorm:"index" json:"deletedAt"` // UUIDs MandateUID uuid.UUID `gorm:"index" gorm:"type:varchar(36);" json:"mandateUID"` ClientUID uuid.UUID `gorm:"index" gorm:"type:varchar(36);" json:"clientUID"` OwnerUID uuid.UUID `gorm:"index" gorm:"type:varchar(36);" json:"ownerUID"` // Attributes StartedAt *time.Time `gorm:"index" json:"startedAt"` // the timestamp when the worker started on this job CompletedAt *time.Time `gorm:"index" json:"completedAt"` // the timestamp when the worker finished the job LastHeartBeat *time.Time `gorm:"index" json:"lastHeartBeat"` // the last time the worker was working on this job Name string `json:"name" gorm:"type:varchar(100);"` // a short and optional name Priority uint `gorm:"index" json:"priority" gorm:"default:1;"` // the priority of the job (1 lowest priority, ... 10 high priority) Attempts uint `gorm:"index" json:"attempts" gorm:"default:0;"` // the attempts that have been tried in the past CurrentWorkerUID *uuid.UUID `gorm:"index" json:"currentWorkerUID" gorm:"type:varchar(36); default:null"` // the uuid of the the worker bot that is currently working in this job WorkerInstance string `gorm:"index" json:"workerInstance" gorm:"index:worker_instance;"` // the type of worker that should work on this job Parameters map[string]string `json:"parameters" gorm:"-"` // the search parameters the worker should use (e.g. company names ... ) ParametersJSON datatypes.JSON `json:"-" gorm:"type:jsonb;"` // json Tasks []JobTask `json:"tasks" gorm:"-"` // the way the worker should interact (e.g. click on that, extract this, store it in this bucket, ...) TasksJSON datatypes.JSON `json:"-" gorm:"type:jsonb;"` // json CurrentStatus map[string]interface{} `json:"currentStatus" gorm:"-"` // the current status of the job CurrentStatusJSON datatypes.JSON `json:"-" gorm:"type:jsonb;"` // json }
type JobService ¶
type JobService interface { New(*Job) error BulkNew([]*Job) error GetJobByUUID(uuid uuid.UUID) (*Job, error) Start(*Job) error HeartBeat(*Job, map[string]interface{}) error Release(*Job) error Complete(*Job) error GetLatestJob(workerInstances []string, workerUUID uuid.UUID) (*Job, error) GetCurrentJobOfWorker(workerInstances []string, workerUUID uuid.UUID) (*Job, bool, error) Clean() error GetStats() ([]Stats, error) }
type JobTask ¶
type JobTask struct { Version string `json:"version"` Name string `json:"name"` Type string `json:"type"` Execute interface{} `json:"execute"` }
JobTask is a task the worker should perform
type NewJobDTO ¶
type NewJobDTO struct { Name string `json:"name"` WorkerInstance string `json:"workerInstance"` Priority uint `json:"priority"` Params map[string]string `json:"params"` Tasks []JobTask `json:"tasks"` }
NewJobDTO is the dto for creating a new job
func (*NewJobDTO) GenerateJob ¶
GenerateJob transforms a dto into a job metadata is added new uuid is generated
type ResponseDTO ¶
ResponseDTO is the response for a single job
type ResponseMultipleDTO ¶
ResponseMultipleDTO is the response for multiple jobs