jobs

package
v0.100.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0

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

View Source
var (
	ErrExecuteJobFailed = errors.New("could not execute job")
	ErrCreateJobFailed  = errors.New("create job failed")
	ErrMarshalJobFailed = errors.New("could not marshal job")
	ErrInvalidJob       = errors.New("invalid job")
	ErrNoJob            = errors.New("no job found")
)
View Source
var ErrFetchFailed = errors.New("fetching feed details failed")
View Source
var UserTipsJobs = map[string]time.Duration{
	"tip-email-newsletters": 24 * time.Hour,
	"new-inactive-user":     5 * 24 * time.Hour,
}

Functions

func NewUserTipsJob added in v0.87.0

func NewUserTipsJob(userID models.UserID, tip string) (*userTipsJob, error)

NewUserTipsJob create a one-shot job to email the user an app tip after a delay as part of onboarding/retention.

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 ClearExpiredSessionsState added in v0.40.0

type ClearExpiredSessionsState struct {
	// Checkpoint is the timestamp when the job last cleared expired sessions.
	Checkpoint time.Time `json:"checkpoint"`
}

ClearExpiredSessionsState 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 jobType `json:"job_type" validate:"required"`
}

ScheduledJob represents a job that has been scheduled by the job scheduler.

func NewClearDeletedFeedsJob

func NewClearDeletedFeedsJob() (*ScheduledJob, error)

NewClearDeletedFeedsJob creates a job for checking for new feeds.

func NewClearExpiredSessionsJob added in v0.40.0

func NewClearExpiredSessionsJob() (*ScheduledJob, error)

NewClearExpiredSessionsJob 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, trigger *pollTrigger) (*ScheduledJob, error)

NewUpdateFeedJob creates a job that can be scheduled from the given feed data.

func (*ScheduledJob) AsScheduledJob added in v0.61.0

func (job *ScheduledJob) AsScheduledJob() *ScheduledJob

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) SetCreatedAt added in v0.61.0

func (job *ScheduledJob) SetCreatedAt(createdAt time.Time)

func (*ScheduledJob) SetNextRun added in v0.61.0

func (job *ScheduledJob) SetNextRun(nextRun time.Time)

func (*ScheduledJob) SetOptions added in v0.61.0

func (job *ScheduledJob) SetOptions(opts *quartz.JobDetailOptions)

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
}

type UpdateFeedJobData

type UpdateFeedJobData struct {
	// FeedID is the unique ID of a feed.
	FeedID  models.FeedID `json:"feed_id" validate:"required,startswith=feed_"`
	Deleted bool          `json:"deleted"`
}

Jump to

Keyboard shortcuts

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