period

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: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EventSchedulePeriodicPolicy is for scheduling periodic policy event
	EventSchedulePeriodicPolicy = "schedule"
	// EventUnSchedulePeriodicPolicy is for unscheduling periodic policy event
	EventUnSchedulePeriodicPolicy = "unschedule"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface interface {
	// Schedule the specified cron job policy.
	//
	// jobName string           : The name of periodical job
	// params models.Parameters : The parameters required by the periodical job
	// cronSpec string          : The periodical settings with cron format
	//
	// Returns:
	//  The uuid of the cron job policy
	//  The latest next trigger time
	//  error if failed to schedule
	// 包含了具体周期性调度任务的执行策略
	Schedule(jobName string, params models.Parameters, cronSpec string) (string, int64, error)

	// Unschedule the specified cron job policy.
	//
	// cronJobPolicyID string: The ID of cron job policy.
	//
	// Return:
	//  error if failed to unschedule
	// 取消调度任务
	UnSchedule(cronJobPolicyID string) error

	// Load and cache data if needed
	//
	// Return:
	//  error if failed to do
	// 载入需要的数据
	Load() error

	// Clear all the cron job policies.
	//
	// Return:
	//  error if failed to do
	// 清除所有的 周期性任务的调度策略
	Clear() error

	// Start to serve
	// 启动服务
	Start()

	// Accept the pushed policy and cache it
	//
	// policy *PeriodicJobPolicy : the periodic policy being accept
	//
	// Return:
	//  error if failed to do
	// 接受上传来的调度策略并存储
	AcceptPeriodicPolicy(policy *PeriodicJobPolicy) error

	// Remove the specified policy from the cache if it is existing
	//
	// policyID string : ID of the policy being removed
	//
	// Return:
	//  the ptr of the being deletd policy
	// 移除调度策略
	RemovePeriodicPolicy(policyID string) *PeriodicJobPolicy
}

Interface defines operations the periodic scheduler should have. 周期性调度任务应该有的操作

type PeriodicJobPolicy

type PeriodicJobPolicy struct {
	// NOTES: The 'PolicyID' should not be set when serialize this policy struct to the zset
	// because each 'Policy ID' is different and it may cause issue of losing zset unique capability.
	PolicyID      string                 `json:"policy_id,omitempty"`
	JobName       string                 `json:"job_name"`
	JobParameters map[string]interface{} `json:"job_params"`
	CronSpec      string                 `json:"cron_spec"`
}

PeriodicJobPolicy ...

func (*PeriodicJobPolicy) DeSerialize

func (pjp *PeriodicJobPolicy) DeSerialize(rawJSON []byte) error

DeSerialize the raw json to policy.

func (*PeriodicJobPolicy) Serialize

func (pjp *PeriodicJobPolicy) Serialize() ([]byte, error)

Serialize the policy to raw data.

type RedisPeriodicScheduler

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

RedisPeriodicScheduler manages the periodic scheduling policies.

func NewRedisPeriodicScheduler

func NewRedisPeriodicScheduler(ctx *env.Context, namespace string, redisPool *redis.Pool, statsManager opm.JobStatsManager) *RedisPeriodicScheduler

NewRedisPeriodicScheduler is constructor of RedisPeriodicScheduler

func (*RedisPeriodicScheduler) AcceptPeriodicPolicy

func (rps *RedisPeriodicScheduler) AcceptPeriodicPolicy(policy *PeriodicJobPolicy) error

AcceptPeriodicPolicy is implementation of the same method in period.Interface

func (*RedisPeriodicScheduler) Clear

func (rps *RedisPeriodicScheduler) Clear() error

Clear is implementation of the same method in period.Interface

func (*RedisPeriodicScheduler) Load

func (rps *RedisPeriodicScheduler) Load() error

Load data from zset

func (*RedisPeriodicScheduler) RemovePeriodicPolicy

func (rps *RedisPeriodicScheduler) RemovePeriodicPolicy(policyID string) *PeriodicJobPolicy

RemovePeriodicPolicy is implementation of the same method in period.Interface

func (*RedisPeriodicScheduler) Schedule

func (rps *RedisPeriodicScheduler) Schedule(jobName string, params models.Parameters, cronSpec string) (string, int64, error)

Schedule is implementation of the same method in period.Interface

func (*RedisPeriodicScheduler) Start

func (rps *RedisPeriodicScheduler) Start()

Start to serve

func (*RedisPeriodicScheduler) UnSchedule

func (rps *RedisPeriodicScheduler) UnSchedule(cronJobPolicyID string) error

UnSchedule is implementation of the same method in period.Interface

type Sweeper

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

Sweeper take charge of clearing the outdated data such as scheduled jobs etc.. Currently, only used in redis worker pool.

func NewSweeper

func NewSweeper(namespace string, pool *redis.Pool, client *work.Client) *Sweeper

NewSweeper is constructor of Sweeper.

func (*Sweeper) ClearOutdatedScheduledJobs

func (s *Sweeper) ClearOutdatedScheduledJobs() error

ClearOutdatedScheduledJobs clears the outdated scheduled jobs. Try best to do

Jump to

Keyboard shortcuts

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