domain

package
v0.8.7 Latest Latest
Warning

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

Go to latest
Published: May 2, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Undefined  JobStatus = iota // 0
	Pending                     // 1
	Scheduled                   // 2
	InProgress                  // 3
	Completed                   // 4
	Failed                      // 5

	PENDING     = "PENDING"
	SCHEDULED   = "SCHEDULED"
	IN_PROGRESS = "IN_PROGRESS"
	COMPLETED   = "COMPLETED"
	FAILED      = "FAILED"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job struct {
	// ID is the auto-generated job identifier in UUID4 format.
	ID string `json:"id"`

	// Name is the name of the job.
	Name string `json:"name"`

	// PipelineID is the auto-generated pipeline identifier in UUID4 format.
	// It will be empty if the job does not belong to a pipeline.
	PipelineID string `json:"pipeline_id,omitempty"`

	// NextJobID is the ID of the job that should run next in the pipeline, if any.
	NextJobID string `json:"next_job_id,omitempty"`

	// UsePreviousResults indicates where the job should use the
	// results of the previous job in the pipeline or not.
	UsePreviousResults bool `json:"use_previous_results,omitempty"`

	// Next points to the next job of the pipeline, if any.
	Next *Job `json:"next,omitempty"`

	// TaskName is the name of the task to be executed.
	TaskName string `json:"task_name"`

	// TaskParams are the required parameters for the task assigned to the specific job.
	TaskParams map[string]interface{} `json:"task_params,omitempty"`

	// Timeout is the time in seconds after which the job task will be interrupted.
	Timeout int `json:"timeout,omitempty"`

	// Description gives some information about the job.
	Description string `json:"description,omitempty"`

	// Status represents the status of the job.
	Status JobStatus `json:"status"`

	// FailureReason holds the error message that led to the job failure, if any.
	FailureReason string `json:"failure_reason,omitempty"`

	// RunAt is the UTC timestamp indicating the time for the job to run.
	RunAt *time.Time `json:"run_at,omitempty"`

	// ScheduledAt is the UTC timestamp indicating the time that the job got scheduled.
	ScheduledAt *time.Time `json:"scheduled_at,omitempty"`

	// CreatedAt is the UTC timestamp of the job creation.
	CreatedAt *time.Time `json:"created_at,omitempty"`

	// StartedAt is the UTC timestamp of the moment the job started.
	StartedAt *time.Time `json:"started_at,omitempty"`

	// CompletedAt is the UTC timestamp of the moment the job finished.
	CompletedAt *time.Time `json:"completed_at,omitempty"`

	// Duration indicates how much the job took to complete.
	Duration *time.Duration `json:"duration,omitempty"`
}

Job represents an async task.

func NewJob

func NewJob(
	uuid, name, taskName, description, pipelineID, nextJobID string,
	timeout int, runAt *time.Time, createdAt *time.Time,
	usePreviousResults bool, taskParams map[string]interface{}) *Job

NewJob initializes and returns a new Job instance.

func (*Job) BelongsToPipeline added in v0.8.0

func (j *Job) BelongsToPipeline() bool

func (*Job) HasNext added in v0.8.0

func (j *Job) HasNext() bool

func (*Job) IsScheduled added in v0.8.0

func (j *Job) IsScheduled() bool

func (*Job) MarkCompleted

func (j *Job) MarkCompleted(completedAt *time.Time)

MarkCompleted updates the status and timestamp at the moment the job finished.

func (*Job) MarkFailed

func (j *Job) MarkFailed(failedAt *time.Time, reason string)

MarkFailed updates the status and timestamp at the moment the job failed.

func (*Job) MarkScheduled

func (j *Job) MarkScheduled(scheduledAt *time.Time)

MarkScheduled updates the status and timestamp at the moment the job got scheduled.

func (*Job) MarkStarted

func (j *Job) MarkStarted(startedAt *time.Time)

MarkStarted updates the status and timestamp at the moment the job started.

func (*Job) SetDuration

func (j *Job) SetDuration()

SetDuration sets the duration of the job if it's completed of failed.

func (*Job) Validate

func (j *Job) Validate(taskrepo *taskrepo.TaskRepository) error

Validate perfoms basic sanity checks on the job request payload.

type JobResult

type JobResult struct {
	JobID    string      `json:"job_id"`
	Metadata interface{} `json:"metadata,omitempty"`
	Error    string      `json:"error,omitempty"`
}

JobResult contains the result of a job.

type JobStatus

type JobStatus int

JobStatus holds a value for job status ranging from 1 to 5.

func (JobStatus) Index

func (js JobStatus) Index() int

Index returns the integer representation of a JobStatus.

func (*JobStatus) MarshalJSON

func (js *JobStatus) MarshalJSON() ([]byte, error)

Marshaling for JSON representation.

func (JobStatus) String

func (js JobStatus) String() string

String converts the type to a string.

func (*JobStatus) UnmarshalJSON

func (js *JobStatus) UnmarshalJSON(data []byte) error

Unmarshaling for JSON representation.

func (JobStatus) Validate

func (js JobStatus) Validate() error

Validate makes a sanity check on JobStatus.

type Pipeline added in v0.8.0

type Pipeline struct {
	// ID is the auto-generated pipeline identifier in UUID4 format.
	ID string `json:"id"`

	// Name is the name of the pipeline.
	Name string `json:"name"`

	// Description gives some information about the pipeline.
	Description string `json:"description,omitempty"`

	// Jobs represents the jobs included to this pipeline.
	Jobs []*Job `json:"jobs,omitempty"`

	// Status represents the status of the pipeline.
	// Jobs propagate their finite status to the pipeline.
	Status JobStatus `json:"status"`

	// RunAt is the UTC timestamp indicating the time for the pipeline to run.
	//  This property will be propagated to the first job of the pipeline.
	RunAt *time.Time `json:"run_at,omitempty"`

	// CreatedAt is the UTC timestamp of the pipeline creation.
	CreatedAt *time.Time `json:"created_at,omitempty"`

	// StartedAt is the UTC timestamp of the moment the pipeline started.
	StartedAt *time.Time `json:"started_at,omitempty"`

	// CompletedAt is the UTC timestamp of the moment the pipeline finished.
	CompletedAt *time.Time `json:"completed_at,omitempty"`

	// Duration indicates how much the pipeline took to complete.
	Duration *time.Duration `json:"duration,omitempty"`
}

Pipeline represents a sequence of async tasks.

func NewPipeline added in v0.8.0

func NewPipeline(id, name, description string, jobs []*Job, createdAt *time.Time) *Pipeline

func (*Pipeline) IsScheduled added in v0.8.0

func (p *Pipeline) IsScheduled() bool

func (*Pipeline) MarkCompleted added in v0.8.0

func (p *Pipeline) MarkCompleted(completedAt *time.Time)

MarkCompleted updates the status and timestamp at the moment the pipeline finished.

func (*Pipeline) MarkFailed added in v0.8.0

func (p *Pipeline) MarkFailed(failedAt *time.Time)

MarkFailed updates the status and timestamp at the moment the pipeline failed.

func (*Pipeline) MarkStarted added in v0.8.0

func (p *Pipeline) MarkStarted(startedAt *time.Time)

MarkStarted updates the status and timestamp at the moment the pipeline started.

func (*Pipeline) MergeJobsInOne added in v0.8.0

func (p *Pipeline) MergeJobsInOne()

func (*Pipeline) SetDuration added in v0.8.0

func (p *Pipeline) SetDuration()

SetDuration sets the duration of the pipeline if it's completed of failed.

func (*Pipeline) UnmergeJobs added in v0.8.0

func (p *Pipeline) UnmergeJobs()

func (*Pipeline) Validate added in v0.8.0

func (p *Pipeline) Validate() error

Validate perfoms basic sanity checks on the pipeline request payload.

Jump to

Keyboard shortcuts

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