jobs

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ErrJobsBootstrap error when bootstrap fails.
	ErrJobsBootstrap = errors.Error("failed to bootstrap jobs")

	// ErrJobsMissing error when job doesn't exist in Repository.
	ErrJobsMissing = errors.Error("job doesn't exist")

	// ErrKeyConstructionFailed error when the key construction failed.
	ErrKeyConstructionFailed = errors.Error("failed to construct job key")
)
View Source
const (

	// Success is the success status for a job or a task
	Success Status = "success"
	// Failed is the failed status for a job or a task
	Failed Status = "failed"
	// Pending is the pending status for a job or a task
	Pending Status = "pending"

	// JobIDParam maps job ID in the kwargs.
	JobIDParam = "jobID"

	// BootstrappedRepo is the key mapped to jobs.Repository.
	BootstrappedRepo = "BootstrappedRepo"

	// BootstrappedService is the key to mapped jobs.JobManager
	BootstrappedService = "BootstrappedService"

	// JobDataTypeURL is the type of the job data
	JobDataTypeURL = "http://github.com/centrifuge/go-centrifuge/jobs/#Job"
)

Variables

This section is empty.

Functions

func JobIDEqual

func JobIDEqual(t1 JobID, t2 JobID) bool

JobIDEqual checks if given two JobIDs are equal

Types

type Config

type Config interface {
	GetTaskValidDuration() time.Duration
}

Config is the config interface for jobs package

type Job

type Job struct {
	ID          JobID
	DID         identity.DID
	Description string

	// Status is the overall status of the Job
	Status Status

	// TaskStatus tracks the status of individual tasks running in the system for this Job
	TaskStatus map[string]Status

	// Logs are Job log messages
	Logs      []Log
	CreatedAt time.Time

	// Values retrieved from events
	Values map[string]JobValue
}

Job contains details of Job.

func NewJob

func NewJob(identity identity.DID, description string) *Job

NewJob returns a new Job with a pending state

func (*Job) FromJSON

func (t *Job) FromJSON(data []byte) error

FromJSON loads the data into job.

func (*Job) JSON

func (t *Job) JSON() ([]byte, error)

JSON returns json marshaled job.

func (*Job) Type

func (t *Job) Type() reflect.Type

Type returns the reflect.Type of the job.

type JobID

type JobID uuid.UUID

JobID is a centrifuge job ID. Internally represented by a UUID. Externally visible as a byte slice or a hex encoded string.

func FromString

func FromString(jobIDHex string) (JobID, error)

FromString tries to convert the given hex string jobID into a type JobID

func NewJobID

func NewJobID() JobID

NewJobID creates a new JobID

func NilJobID

func NilJobID() JobID

NilJobID returns a nil JobID

func (JobID) Bytes

func (t JobID) Bytes() []byte

Bytes returns the byte slice representation of the JobID

func (JobID) String

func (t JobID) String() string

String marshals a JobID to its hex string form

type JobValue

type JobValue struct {
	Key    string
	KeyIdx int
	Value  []byte
}

JobValue holds the key and value filtered by the Job

type Log

type Log struct {
	Action    string
	Message   string
	CreatedAt time.Time
}

Log represents a single task in a job.

func NewLog

func NewLog(action, message string) Log

NewLog constructs a new log with action and message

type Manager

type Manager interface {
	// ExecuteWithinJob executes the given unit of work within a Job
	ExecuteWithinJob(ctx context.Context, accountID identity.DID, existingJobID JobID, desc string, work func(accountID identity.DID, jobID JobID, jobManager Manager, err chan<- error)) (jobID JobID, done chan error, err error)
	GetJob(accountID identity.DID, id JobID) (*Job, error)
	UpdateJobWithValue(accountID identity.DID, id JobID, key string, value []byte) error
	UpdateTaskStatus(accountID identity.DID, id JobID, status Status, taskName, message string) error
	GetJobStatus(accountID identity.DID, id JobID) (StatusResponse, error)
	WaitForJob(accountID identity.DID, txID JobID) error
	GetDefaultTaskTimeout() time.Duration
}

Manager is a manager for centrifuge Jobs.

type Repository

type Repository interface {
	Get(did identity.DID, id JobID) (*Job, error)
	Save(job *Job) error
}

Repository can be implemented by a type that handles storage for Jobs.

type Status

type Status string

Status represents the status of the job

type StatusResponse added in v1.0.0

type StatusResponse struct {
	JobID       string    `json:"job_id"`
	Status      string    `json:"status"`
	Message     string    `json:"message"`
	LastUpdated time.Time `json:"last_updated" swaggertype:"primitive,string"`
}

StatusResponse holds the job status details.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL