opm

package
v0.0.0-...-977965f Latest Latest
Warning

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

Go to latest
Published: May 28, 2019 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// CtlCommandStop : command stop
	CtlCommandStop = "stop"
	// CtlCommandCancel : command cancel
	CtlCommandCancel = "cancel"
	// CtlCommandRetry : command retry
	CtlCommandRetry = "retry"

	// EventRegisterStatusHook is event name of registering hook
	EventRegisterStatusHook = "register_hook"
)
View Source
const (

	// EventFireCommand for firing command event
	EventFireCommand = "fire_command"
)

Variables

View Source
var DefaultHookClient = NewHookClient()

DefaultHookClient is for default use.

Functions

This section is empty.

Types

type HookClient

type HookClient struct {
	// contains filtered or unexported fields
}

HookClient is used to post the related data to the interested parties.

func NewHookClient

func NewHookClient() *HookClient

NewHookClient return the ptr of the new HookClient

func (*HookClient) ReportStatus

func (hc *HookClient) ReportStatus(hookURL string, status models.JobStatusChange) error

ReportStatus reports the status change info to the subscribed party. The status includes 'checkin' info with format 'check_in:<message>'

type HookData

type HookData struct {
	JobID   string `json:"job_id"`
	HookURL string `json:"hook_url"`
}

HookData keeps the hook url info

type HookStore

type HookStore struct {
	// contains filtered or unexported fields
}

HookStore is used to cache the hooks in memory. Use job ID as key to index

func NewHookStore

func NewHookStore() *HookStore

NewHookStore is to create a ptr of new HookStore.

func (*HookStore) Add

func (hs *HookStore) Add(jobID string, hookURL string)

Add new record

func (*HookStore) Get

func (hs *HookStore) Get(jobID string) (string, bool)

Get one hook url by job ID

func (*HookStore) Remove

func (hs *HookStore) Remove(jobID string) (string, bool)

Remove the specified one

type JobStatsManager

type JobStatsManager interface {
	// Start to serve
	Start()

	// Shutdown the manager
	Shutdown()

	// Save the job stats
	// Async method to retry and improve performance
	//
	// jobStats models.JobStats : the job stats to be saved
	// 存储工作状态?是保存到数据库还是内存中?
	Save(jobStats models.JobStats)

	// Get the job stats from backend store
	// Sync method as we need the data
	//
	// Returns:
	//  models.JobStats : job stats data
	//  error           : error if meet any problems
	// 从后端存储中获取 job 状态
	Retrieve(jobID string) (models.JobStats, error)

	// Update the properties of the job stats
	//
	// jobID string                  : ID of the being retried job
	// fieldAndValues ...interface{} : One or more properties being updated
	//
	// Returns:
	//  error if update failed
	// 更新 job 状态的参数
	Update(jobID string, fieldAndValues ...interface{}) error

	// SetJobStatus will mark the status of job to the specified one
	// Async method to retry
	// 指定 job 的状态
	SetJobStatus(jobID string, status string)

	// Send command for the specified job
	//
	// jobID string   : ID of the being retried job
	// command string : the command applied to the job like stop/cancel
	// isCached bool  : to indicate if only cache the op command
	//
	// Returns:
	//  error if it was not successfully sent
	// 给指定的 job 发送 command
	SendCommand(jobID string, command string, isCached bool) error

	// CtlCommand checks if control command is fired for the specified job.
	//
	// jobID string : ID of the job
	//
	// Returns:
	//  the command if it was fired
	//  error if it was not fired yet to meet some other problems
	// 检测 job 的 control command 是否存在
	CtlCommand(jobID string) (string, error)

	// CheckIn message for the specified job like detailed progress info.
	//
	// jobID string   : ID of the job
	// message string : The message being checked in
	//
	CheckIn(jobID string, message string)

	// DieAt marks the failed jobs with the time they put into dead queue.
	//
	// jobID string   : ID of the job
	// message string : The message being checked in
	//
	// 用时间标记失败的任务
	DieAt(jobID string, dieAt int64)

	// RegisterHook is used to save the hook url or cache the url in memory.
	//
	// jobID string   : ID of job
	// hookURL string : the hook url being registered
	// isCached bool  :  to indicate if only cache the hook url
	//
	// Returns:
	//  error if meet any problems
	// 保存 hook url 或者在内存中存储
	RegisterHook(jobID string, hookURL string, isCached bool) error

	// Get hook returns the web hook url for the specified job if it is registered
	//
	// jobID string   : ID of job
	//
	// Returns:
	//  the web hook url if existing
	//  non-nil error if meet any problems
	// 获取指定 job 的 hook url
	GetHook(jobID string) (string, error)

	// Mark the periodic job stats expired
	//
	// jobID string   : ID of job
	//
	// Returns:
	//  error if meet any problems
	// 将指定的周期性job 标记为过期的
	ExpirePeriodicJobStats(jobID string) error

	// Persist the links between upstream job and the executions.
	//
	// upstreamJobID string: ID of the upstream job
	// executions  ...string: IDs of the execution jobs
	//
	// Returns:
	//  error if meet any issues
	// 持久化存储 上游 job 和当前 job 的执行之间的关系。
	AttachExecution(upstreamJobID string, executions ...string) error

	// Get all the executions (IDs) fro the specified upstream Job.
	//
	// upstreamJobID string: ID of the upstream job
	// ranges      ...Range: Define the start and end for the list, e.g:
	//   0, 10 means [0:10]
	//   10 means [10:]
	//   empty means [0:-1]==all
	// Returns:
	//  the ID list of the executions if no error occurred
	//  or a non-nil error is returned
	// 从指定的上游 job,获取所有正在执行的 jobid
	GetExecutions(upstreamJobID string, ranges ...Range) ([]string, error)
}

JobStatsManager defines the methods to handle stats of job. 用来处理 job 的处理状态。

func NewRedisJobStatsManager

func NewRedisJobStatsManager(ctx context.Context, namespace string, redisPool *redis.Pool) JobStatsManager

NewRedisJobStatsManager is constructor of RedisJobStatsManager

type Range

type Range int

Range for list scope defining

type RedisJobStatsManager

type RedisJobStatsManager struct {
	// contains filtered or unexported fields
}

RedisJobStatsManager implements JobStatsManager based on redis.

func (*RedisJobStatsManager) AttachExecution

func (rjs *RedisJobStatsManager) AttachExecution(upstreamJobID string, executions ...string) error

AttachExecution persist the links between upstream jobs and the related executions (jobs).

func (*RedisJobStatsManager) CheckIn

func (rjs *RedisJobStatsManager) CheckIn(jobID string, message string)

CheckIn mesage

func (*RedisJobStatsManager) CtlCommand

func (rjs *RedisJobStatsManager) CtlCommand(jobID string) (string, error)

CtlCommand checks if control command is fired for the specified job.

func (*RedisJobStatsManager) DieAt

func (rjs *RedisJobStatsManager) DieAt(jobID string, dieAt int64)

DieAt marks the failed jobs with the time they put into dead queue.

func (*RedisJobStatsManager) ExpirePeriodicJobStats

func (rjs *RedisJobStatsManager) ExpirePeriodicJobStats(jobID string) error

ExpirePeriodicJobStats marks the periodic job stats expired

func (*RedisJobStatsManager) GetExecutions

func (rjs *RedisJobStatsManager) GetExecutions(upstreamJobID string, ranges ...Range) ([]string, error)

GetExecutions returns the existing executions (IDs) for the specified job.

func (*RedisJobStatsManager) GetHook

func (rjs *RedisJobStatsManager) GetHook(jobID string) (string, error)

GetHook returns the status web hook url for the specified job if existing

func (*RedisJobStatsManager) RegisterHook

func (rjs *RedisJobStatsManager) RegisterHook(jobID string, hookURL string, isCached bool) error

RegisterHook is used to save the hook url or cache the url in memory.

func (*RedisJobStatsManager) Retrieve

func (rjs *RedisJobStatsManager) Retrieve(jobID string) (models.JobStats, error)

Retrieve is implementation of same method in JobStatsManager interface. Sync method

func (*RedisJobStatsManager) Save

func (rjs *RedisJobStatsManager) Save(jobStats models.JobStats)

Save is implementation of same method in JobStatsManager interface. Async method 异步的方法

func (*RedisJobStatsManager) SendCommand

func (rjs *RedisJobStatsManager) SendCommand(jobID string, command string, isCached bool) error

SendCommand for the specified job

func (*RedisJobStatsManager) SetJobStatus

func (rjs *RedisJobStatsManager) SetJobStatus(jobID string, status string)

SetJobStatus is implementation of same method in JobStatsManager interface. Async method 设置 job 的状态

func (*RedisJobStatsManager) Shutdown

func (rjs *RedisJobStatsManager) Shutdown()

Shutdown is implementation of same method in JobStatsManager interface.

func (*RedisJobStatsManager) Start

func (rjs *RedisJobStatsManager) Start()

Start is implementation of same method in JobStatsManager interface.

func (*RedisJobStatsManager) Update

func (rjs *RedisJobStatsManager) Update(jobID string, fieldAndValues ...interface{}) error

Update the properties of job stats

Jump to

Keyboard shortcuts

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