Documentation
¶
Overview ¶
Package jobs implements a common type for quartz jobs and specific types and methods to execute different kinds of jobs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func SchedulerAPIToCtx ¶
func SchedulerAPIToCtx(ctx context.Context, schedulerAPI SchedulerAPI) context.Context
Types ¶
type ClearDeletedFeedsState ¶
type ClearDeletedFeedsState struct {
// Checkpoint is the timestamp when the job last checked for new feeds.
Checkpoint time.Time `json:"checkpoint"`
}
ClearDeletedFeedsState represents the state required by this job type.
type GetNewFeedsJobData ¶
type GetNewFeedsJobData struct {
// Interval is the interval on which to check for new feeds.
Interval string `json:"interval"`
}
GetNewFeedsJobData contains the data required by the GetNewFeeds job.
type GetNewFeedsJobState ¶
type GetNewFeedsJobState struct {
// Checkpoint is the timestamp when the job last checked for new feeds.
Checkpoint time.Time `json:"checkpoint"`
}
GetNewFeedsJobState represents the state required by this job type.
type ScheduledJob ¶
type ScheduledJob struct {
// CreatedAt records when the object was created in the database.
CreatedAt models.CreatedAt `json:"created_at" validate:"required"`
// JobData contains job-specific data.
JobData json.RawMessage `json:"job_data"`
// JobNextRun is the next run time of the job.
JobNextRun time.Time `json:"job_next_run"`
// JobOptions are additional options for the job
JobOptions *quartz.JobDetailOptions `json:"job_options,omitempty,omitzero"`
// JobTrigger is the trigger for the job.
JobTrigger json.RawMessage `json:"job_trigger" validate:"required"`
// JobTriggerType is the type of trigger the job is using.
JobTriggerType string `json:"job_trigger_type" validate:"oneof=cron poll"`
// JobDescription is a summary of what the job does.
JobDescription string `json:"job_description"`
// JobType is the type of job.
JobType string `json:"job_type" validate:"oneof=update_feed get_new_feeds"`
}
ScheduledJob represents a job that has been scheduled by the job scheduler.
func MarshalJob ¶
func MarshalJob(job quartz.ScheduledJob) (*ScheduledJob, error)
MarshalJob takes a quartz.ScheduledJob object and marshals it back into a ScheduledJob, updating fields as appropriate.
func NewClearDeletedFeedsJob ¶
func NewClearDeletedFeedsJob() (*ScheduledJob, error)
NewClearDeletedFeedsJob creates a job for checking for new feeds.
func NewGetNewFeedsJob ¶
func NewGetNewFeedsJob(ctx context.Context) (*ScheduledJob, error)
NewGetNewFeedsJob creates a job for checking for new feeds.
func NewUpdateFeedJob ¶
func NewUpdateFeedJob(id models.FeedID, urls []models.URL, trigger *pollTrigger) (*ScheduledJob, error)
NewUpdateFeedJob creates a job that can be scheduled from the given feed data.
func (*ScheduledJob) Description ¶
func (job *ScheduledJob) Description() string
Description returns the description of the Job.
func (*ScheduledJob) Execute ¶
func (job *ScheduledJob) Execute(ctx context.Context) error
Execute is called by a Scheduler when the Trigger associated with this job fires.
func (*ScheduledJob) JobDetail ¶
func (job *ScheduledJob) JobDetail() *quartz.JobDetail
JobDetail returns a quartz.JobDetail object for the job.
func (*ScheduledJob) NextRunTime ¶
func (job *ScheduledJob) NextRunTime() int64
NextRunTime returns the next scheduled run time for the job.
func (*ScheduledJob) Trigger ¶
func (job *ScheduledJob) Trigger() quartz.Trigger
Trigger defines the job trigger.
type SchedulerAPI ¶
type SchedulerAPI interface {
GetScheduledJob(jobKey *quartz.JobKey) (quartz.ScheduledJob, error)
ScheduleJob(jobDetail *quartz.JobDetail, trigger quartz.Trigger) error
DeleteJob(jobKey *quartz.JobKey) error
GetJobState(ctx context.Context, id string) (*models.JobState, error)
UpdateJobState(ctx context.Context, id string, updates map[string]any) error
}