domain

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 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 FutureJobResult

type FutureJobResult struct {
	Result chan JobResult
}

FutureJobResult is a JobResult that may not yet have become available and can be Wait()'ed on.

func (FutureJobResult) Wait

func (f FutureJobResult) Wait() JobResult

Wait waits for JobResult to become available and returns it.

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"`

	// 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 string, timeout int,
	runAt *time.Time, createdAt *time.Time, taskParams map[string]interface{}) *Job

NewJob initializes and returns a new Job instance.

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 (job *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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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