job

package
v0.5.13 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: Apache-2.0, MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PauseJobHandler

func PauseJobHandler(
	ctx context.Context,
	db *gorm.DB,
	id string,
	name string,
	jobType model.JobType) (*model.Job, error)

PauseJobHandler attempts to pause a running job for a given source storage.

This function checks if there's an existing job of the given type for the source. If the job exists and is in a pausable state, it updates the job's state to 'Paused'. If the job doesn't exist or is not in a pausable state, it returns an appropriate error.

Parameters:

  • ctx: The context for database transactions and other operations.
  • db: A pointer to the gorm.DB instance representing the database connection.
  • id: The unique identifier for the desired Preparation record.
  • name: The name of the source storage.
  • jobType: The type of the job (e.g., Scan, Upload).

Returns:

  • A pointer to the model.Job record that was paused.
  • An error, if any occurred during the database transaction or if the job doesn't exist, or if the job is not in a pausable state.

func StartJobHandler

func StartJobHandler(
	ctx context.Context,
	db *gorm.DB,
	id string,
	name string,
	jobType model.JobType) (*model.Job, error)

StartJobHandler initializes or restarts a job for a given source storage.

The function checks if there's an existing job of the given type for the source. If the job doesn't exist, it creates one. If the job exists and is in a startable state, it will reset the job to be ready to start again. If the job is already running, it returns an error.

Parameters:

  • ctx: The context for database transactions and other operations.
  • db: A pointer to the gorm.DB instance representing the database connection.
  • id: The ID or name for the desired Preparation record.
  • name: The ID or name of the source storage.
  • jobType: The type of the job (e.g., Scan, Upload).

Returns:

  • A pointer to the model.Job record that was created or updated.
  • An error, if any occurred during the database transaction or if the source storage doesn't exist, or if there's already a running job of the specified type for the source.

Note: The function ensures the job is either newly created or reset, and is ready to be executed by a worker.

Types

type DefaultHandler

type DefaultHandler struct{}

func (DefaultHandler) GetStatusHandler

func (DefaultHandler) GetStatusHandler(ctx context.Context, db *gorm.DB, id string) ([]SourceStatus, error)

GetStatusHandler fetches and returns the current status of a specific Preparation. The status includes the Preparation record and associated jobs for each source attachment.

Parameters:

  • ctx: The context for database transactions and other operations.
  • db: A pointer to the gorm.DB instance representing the database connection.
  • id: The ID or name for the desired Preparation record.

Returns:

  • A pointer to a Status structure that encapsulates the Preparation record and the associated jobs for each source attachment.
  • An error, if any occurred during the database query operation or if the Preparation record with the specified ID does not exist.

Note: The function fetches not only the Preparation record but also all associated SourceAttachment records with their associated Job records, providing a comprehensive status of a specific preparation.

func (DefaultHandler) PackHandler

func (DefaultHandler) PackHandler(
	ctx context.Context,
	db *gorm.DB,
	jobID uint64) (*model.Car, error)

PackHandler packs the given job's files and returns the corresponding CAR (Content Addressable Archive) info.

This function retrieves a job from the database with the specified job ID, preloading its associated file ranges, attachments, storages, and output storages. If the retrieval is successful, it then packs the job's files into a CAR format.

Parameters:

  • ctx: The context for managing timeouts and cancellation.
  • db: The gorm.DB instance for database operations.
  • jobID: The ID of the job to be packed.

Returns:

  • A pointer to the packed model.Car, if successful.
  • An error if any issues occur during the operation, including database retrieval errors or packing errors.

func (DefaultHandler) PauseDagGenHandler

func (DefaultHandler) PauseDagGenHandler(
	ctx context.Context,
	db *gorm.DB,
	id string,
	name string) (*model.Job, error)

PauseDagGenHandler pauses an ongoing Directed Acyclic Graph (DAG) generation job for a given source storage.

This function is a wrapper around the more general `PauseJobHandler` function, specifically for pausing 'Scan' type jobs.

Parameters:

  • ctx: The context for database transactions and other operations.
  • db: A pointer to the gorm.DB instance representing the database connection.
  • id: The unique identifier for the desired Preparation record.
  • name: The name of the source storage.

Returns:

  • A pointer to the model.Job record that was paused.
  • An error, if any occurred during the operation.

func (DefaultHandler) PausePackHandler

func (DefaultHandler) PausePackHandler(
	ctx context.Context,
	db *gorm.DB,
	id string,
	name string,
	jobID int64) ([]model.Job, error)

PausePackHandler attempts to pause pack jobs for a given source storage.

If jobID is provided, the function will attempt to pause a specific pack job. If not, it will search for all pack jobs in pausable states associated with the source and attempt to pause them. The state of the job will be updated to 'Paused'.

Parameters:

  • ctx: The context for database transactions and other operations.
  • db: A pointer to the gorm.DB instance representing the database connection.
  • id: The ID or name for the desired Preparation record.
  • name: The ID or name of the source storage.
  • jobID: The unique identifier of the job to be paused. If set to 0, all eligible jobs for the source will be paused.

Returns:

  • A slice of model.Job records that were paused.
  • An error, if any occurred during the database transaction, if the job doesn't exist, or if the job is not in a pausable state.

func (DefaultHandler) PauseScanHandler

func (DefaultHandler) PauseScanHandler(
	ctx context.Context,
	db *gorm.DB,
	id string,
	name string) (*model.Job, error)

func (DefaultHandler) PrepareToPackSourceHandler

func (DefaultHandler) PrepareToPackSourceHandler(
	ctx context.Context,
	db *gorm.DB,
	id string,
	name string,
) error

func (DefaultHandler) StartDagGenHandler

func (DefaultHandler) StartDagGenHandler(
	ctx context.Context,
	db *gorm.DB,
	id string,
	name string) (*model.Job, error)

StartDagGenHandler initiates the start of a Directed Acyclic Graph (DAG) generation job for a given source storage.

This function is a wrapper around the more general `StartJobHandler` function and sets the job type to 'Scan'.

Parameters:

  • ctx: The context for database transactions and other operations.
  • db: A pointer to the gorm.DB instance representing the database connection.
  • id: The unique identifier for the desired Preparation record.
  • name: The name of the source storage.

Returns:

  • A pointer to the model.Job record that was initiated.
  • An error, if any occurred during the operation.

func (DefaultHandler) StartPackHandler

func (DefaultHandler) StartPackHandler(
	ctx context.Context,
	db *gorm.DB,
	id string,
	name string,
	jobID int64) ([]model.Job, error)

StartPackHandler initiates pack jobs for a given source storage.

If jobID is provided, this function will attempt to start a specific pack job. If not, it will search for all pack jobs in startable states associated with the source and attempt to start them. The state of the job will be updated to 'Ready'.

Parameters:

  • ctx: The context for database transactions and other operations.
  • db: A pointer to the gorm.DB instance representing the database connection.
  • id: The ID or name of Preparation record.
  • name: The ID or name of the source storage.
  • jobID: The unique identifier of the job to be started. If set to 0, all eligible jobs for the source will be initiated.

Returns:

  • A slice of model.Job records that were started.
  • An error, if any occurred during the database transaction or if the job doesn't exist, or if the job is not in a startable state.

func (DefaultHandler) StartScanHandler

func (DefaultHandler) StartScanHandler(
	ctx context.Context,
	db *gorm.DB,
	id string,
	name string) (*model.Job, error)

type Handler

type Handler interface {
	StartDagGenHandler(
		ctx context.Context,
		db *gorm.DB,
		id string,
		name string) (*model.Job, error)

	PauseDagGenHandler(
		ctx context.Context,
		db *gorm.DB,
		id string,
		name string) (*model.Job, error)

	StartPackHandler(
		ctx context.Context,
		db *gorm.DB,
		id string,
		name string,
		jobID int64) ([]model.Job, error)

	PausePackHandler(
		ctx context.Context,
		db *gorm.DB,
		id string,
		name string,
		jobID int64) ([]model.Job, error)

	StartScanHandler(
		ctx context.Context,
		db *gorm.DB,
		id string,
		name string) (*model.Job, error)

	PauseScanHandler(
		ctx context.Context,
		db *gorm.DB,
		id string,
		name string) (*model.Job, error)

	GetStatusHandler(ctx context.Context, db *gorm.DB, id string) ([]SourceStatus, error)

	PackHandler(
		ctx context.Context,
		db *gorm.DB,
		jobID uint64) (*model.Car, error)

	PrepareToPackSourceHandler(
		ctx context.Context,
		db *gorm.DB,
		id string,
		name string,
	) error
}
var Default Handler = &DefaultHandler{}

type MockJob added in v0.5.0

type MockJob struct {
	mock.Mock
}

func (*MockJob) GetStatusHandler added in v0.5.0

func (m *MockJob) GetStatusHandler(ctx context.Context, db *gorm.DB, id string) ([]SourceStatus, error)

func (*MockJob) PackHandler added in v0.5.0

func (m *MockJob) PackHandler(ctx context.Context, db *gorm.DB, jobID uint64) (*model.Car, error)

func (*MockJob) PauseDagGenHandler added in v0.5.0

func (m *MockJob) PauseDagGenHandler(ctx context.Context, db *gorm.DB, id string, name string) (*model.Job, error)

func (*MockJob) PausePackHandler added in v0.5.0

func (m *MockJob) PausePackHandler(ctx context.Context, db *gorm.DB, id string, name string, jobID int64) ([]model.Job, error)

func (*MockJob) PauseScanHandler added in v0.5.0

func (m *MockJob) PauseScanHandler(ctx context.Context, db *gorm.DB, id string, name string) (*model.Job, error)

func (*MockJob) PrepareToPackSourceHandler added in v0.5.0

func (m *MockJob) PrepareToPackSourceHandler(ctx context.Context, db *gorm.DB, id string, name string) error

func (*MockJob) StartDagGenHandler added in v0.5.0

func (m *MockJob) StartDagGenHandler(ctx context.Context, db *gorm.DB, id string, name string) (*model.Job, error)

func (*MockJob) StartPackHandler added in v0.5.0

func (m *MockJob) StartPackHandler(ctx context.Context, db *gorm.DB, id string, name string, jobID int64) ([]model.Job, error)

func (*MockJob) StartScanHandler added in v0.5.0

func (m *MockJob) StartScanHandler(ctx context.Context, db *gorm.DB, id string, name string) (*model.Job, error)

type SourceStatus

type SourceStatus struct {
	AttachmentID    *model.SourceAttachmentID `json:"attachmentId"`
	SourceStorageID *model.StorageID          `json:"storageId"`
	SourceStorage   *model.Storage            `json:"source"       table:"expand;header:Source Storage"`
	OutputStorages  []model.Storage           `json:"output"       table:"expand;header:Output Storages"`
	Jobs            []model.Job               `json:"jobs"         table:"expand"`
}

Jump to

Keyboard shortcuts

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