bg_jobs/scheduled_job

Types

pub type CronSchedule {
  CronSchedule(
    second: TimeValue,
    minute: TimeValue,
    hour: TimeValue,
    day_of_month: TimeValue,
    month: TimeValue,
    day_of_week: TimeValue,
  )
}

Constructors

  • CronSchedule(
      second: TimeValue,
      minute: TimeValue,
      hour: TimeValue,
      day_of_month: TimeValue,
      month: TimeValue,
      day_of_week: TimeValue,
    )
pub type Duration {
  Millisecond(Int)
  Second(Int)
  Minute(Int)
  Hour(Int)
  Day(Int)
  Week(Int)
  Month(Int)
  Year(Int)
}

Constructors

  • Millisecond(Int)
  • Second(Int)
  • Minute(Int)
  • Hour(Int)
  • Day(Int)
  • Week(Int)
  • Month(Int)
  • Year(Int)
pub type Schedule {
  Interval(Duration)
  Schedule(CronSchedule)
}

Constructors

  • Interval(Duration)
  • Schedule(CronSchedule)
pub type Spec {
  Spec(
    schedule: Schedule,
    worker: jobs.Worker,
    max_retries: Int,
    init_timeout: Int,
    poll_interval: Int,
    event_listeners: List(events.EventListener),
  )
}

Constructors

  • Spec(
      schedule: Schedule,
      worker: jobs.Worker,
      max_retries: Int,
      init_timeout: Int,
      poll_interval: Int,
      event_listeners: List(events.EventListener),
    )
pub type TimeSelection {
  Value(Int)
  Range(Int, Int)
}

Constructors

  • Value(Int)
  • Range(Int, Int)
pub type TimeValue {
  Every
  Specific(List(TimeSelection))
}

Constructors

  • Every
  • Specific(List(TimeSelection))

Functions

pub fn between_day_of_months(
  self: CronSchedule,
  start: Int,
  end: Int,
) -> CronSchedule

Sets a range of days of the month during which the schedule should trigger.

pub fn between_day_of_weeks(
  self: CronSchedule,
  start: Int,
  end: Int,
) -> CronSchedule

Sets a range of days of the week during which the schedule should trigger.

pub fn between_hours(
  self: CronSchedule,
  start: Int,
  end: Int,
) -> CronSchedule

Sets a range of hours during which the schedule should trigger.

pub fn between_minutes(
  self: CronSchedule,
  start: Int,
  end: Int,
) -> CronSchedule

Sets a range of minutes during which the schedule should trigger.

pub fn between_months(
  self: CronSchedule,
  start: Int,
  end: Int,
) -> CronSchedule

Sets a range of months during which the schedule should trigger.

pub fn between_seconds(
  self: CronSchedule,
  start: Int,
  end: Int,
) -> CronSchedule

Sets a range of seconds during which the schedule should trigger.

pub fn build(
  registry registry: Subject(
    Message(
      bg_jobs/internal/scheduled_jobs_messages.Message,
      String,
      Nil,
    ),
  ),
  dispatch_registry dispatch_registry: Subject(
    Message(
      bg_jobs/internal/dispatcher_messages.Message,
      String,
      Nil,
    ),
  ),
  db_adapter db_adapter: DbAdapter,
  spec spec: Spec,
) -> Result(
  Subject(bg_jobs/internal/scheduled_jobs_messages.Message),
  StartError,
)
pub fn every_second(self: CronSchedule) -> CronSchedule

Sets the schedule to trigger every second.

pub fn new(worker: Worker, schedule: Schedule) -> Spec
pub fn new_interval_days(days: Int) -> Schedule

Create interval schedule in days

pub fn new_interval_hours(hours: Int) -> Schedule

Create interval schedule in hours

pub fn new_interval_milliseconds(milliseconds: Int) -> Schedule

Create interval schedule in milliseconds

pub fn new_interval_minutes(minutes: Int) -> Schedule

Create interval schedule in minutes

pub fn new_interval_months(months: Int) -> Schedule

Create interval schedule in months

pub fn new_interval_seconds(seconds: Int) -> Schedule

Create interval schedule in seconds

pub fn new_interval_weeks(weeks: Int) -> Schedule

Create interval schedule in weeks

pub fn new_interval_years(years: Int) -> Schedule

Create interval schedule in years

pub fn new_schedule() -> CronSchedule

Create a new schedule that runs on the first second every minut

pub fn on_aprils(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger in April.

pub fn on_augusts(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger in August.

pub fn on_day_of_month(
  self: CronSchedule,
  value: Int,
) -> CronSchedule

Adds a specific day of the month on which the schedule should trigger. If other specific days are already set, appends the given day.

pub fn on_day_of_week(
  self: CronSchedule,
  value: Int,
) -> CronSchedule

Adds a specific day of the week on which the schedule should trigger. If other specific days are already set, appends the given day.

pub fn on_decembers(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger in December.

pub fn on_februaries(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger in February.

pub fn on_fridays(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger on Fridays.

pub fn on_hour(self: CronSchedule, value: Int) -> CronSchedule

Adds a specific hour at which the schedule should trigger. If other specific hours are already set, appends the given hour.

pub fn on_januaries(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger in January.

pub fn on_julies(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger in July.

pub fn on_junes(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger in June.

pub fn on_marches(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger in March.

pub fn on_mays(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger in May.

pub fn on_minute(self: CronSchedule, value: Int) -> CronSchedule

Adds a specific minute at which the schedule should trigger. If other specific minutes are already set, appends the given minute.

pub fn on_mondays(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger on Mondays.

pub fn on_month(self: CronSchedule, value: Int) -> CronSchedule

Adds a specific month in which the schedule should trigger. If other specific months are already set, appends the given month.

pub fn on_novembers(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger in November.

pub fn on_octobers(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger in October.

pub fn on_saturdays(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger on Saturdays.

pub fn on_second(self: CronSchedule, second: Int) -> CronSchedule

Adds a specific second at which the schedule should trigger. If other specific seconds are already set, appends the given second.

Note: the default value is to trigger on second 0 so you would need to set it to every second first and then to a specific to only get that

pub fn on_septembers(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger in September.

pub fn on_sundays(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger on Sundays.

pub fn on_thuesdays(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger on Thuesdays.

pub fn on_thursdays(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger on Thursdays.

pub fn on_wednesdays(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger on Wednesdays.

pub fn on_weekdays(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger on weekdays (Monday through Friday).

pub fn on_weekends(self: CronSchedule) -> CronSchedule

Shortcut function to set the schedule to trigger on weekends (Saturday and Sunday).

pub fn to_cron_syntax(self: CronSchedule) -> String

Convert the CronSchedule to actual cron syntax

pub fn with_event_listeners(
  spec: Spec,
  event_listeners: List(fn(Event) -> Nil),
) -> Spec

Set event listeners for the queue NOTE: This will override previously added workers

pub fn with_init_timeout(spec: Spec, init_timeout: Int) -> Spec

Amount of time in milli seconds the queue is given to start

pub fn with_max_retries(spec: Spec, max_retries: Int) -> Spec

Maximum times a job will be retried before being considered failed and moved to the failed_jobs table

pub fn with_poll_interval_ms(
  spec: Spec,
  poll_interval: Int,
) -> Spec

Time in milli seconds to wait in between checking for new jobs

Search Document