Fledex.Scheduler
(Fledex_Scheduler v0.3.0)
View Source
Fledex.Scheduler schedules jobs (either an m,f,a or a function) to run in the future.
These jobs are run in isolated processes, and are unsurpervised.
For even more control, you can use Fledex.Scheduler.Runner directly that even allwos
you to provide your own process names, and to attach it to a supervision tree.
Summary
Functions
Cancels the given scheduled job
Runs the given function at the given time
Runs the given module, function and argument at the given time
Runs the given function on every occurrence of the given crontab. If func is of arity 1, the scheduled execution time will be passed for each invocation
Runs the given module, function and argument on every occurrence of the given crontab. Any
values in the arguments array which are equal to the magic symbol :sched_ex_scheduled_time
are replaced with the scheduled execution time for each invocation
Runs the given function in given number of units (this corresponds to milliseconds
unless a custom time_scale is specified). If func is of arity 1, the scheduled
execution time will be passed for each invocation
Runs the given module, function and argument in given number of units (this
corresponds to milliseconds unless a custom time_scale is specified). Any
values in the arguments array which are equal to the magic symbol :sched_ex_scheduled_time
are replaced with the scheduled execution time for each invocation
You can run a Fledex.Scheduler.Job by calling this function.
You can update the job (for example change your scheduling) by calling this function
Functions
@spec cancel(GenServer.server()) :: :ok
Cancels the given scheduled job
@spec run_at(Fledex.Scheduler.Job.task(), DateTime.t(), keyword()) :: GenServer.on_start()
Runs the given function at the given time
@spec run_at(module(), atom(), list(), DateTime.t(), keyword()) :: GenServer.on_start()
Runs the given module, function and argument at the given time
@spec run_every( Fledex.Scheduler.Job.task(), String.t() | Crontab.CronExpression.t(), keyword() ) :: GenServer.on_start() | {:error, any()}
Runs the given function on every occurrence of the given crontab. If func is of arity 1, the scheduled execution time will be passed for each invocation
Takes the same options as run_every/5
@spec run_every( module(), atom(), list(), String.t() | Crontab.CronExpression.t(), keyword() ) :: GenServer.on_start()
Runs the given module, function and argument on every occurrence of the given crontab. Any
values in the arguments array which are equal to the magic symbol :sched_ex_scheduled_time
are replaced with the scheduled execution time for each invocation
Supports the following options:
timezone: A string timezone identifier (America/Chicago) specifying the timezone within which the crontab should be interpreted. If not specified, defaults toUTCtime_scale: A module that implements theFledex.Scheduler.TimeScalebehaviour, by default is set toFledex.Scheduler.IdentityTimeScale. Can be used to speed up time (often used for speeding up test runs)name: To attach a name to the process. Useful for adding a name to Registry to lookup later. ie. {:via, Registry, {YourRegistryName, "scheduled-task-1"}}nonexistent_time_strategy: How to handle scheduled runs within a DST forward boundary when evaluated within the timezone specified by thetimezoneoption. Valid values are:skip(the default) and:adjust. By way of example, for a job which is scheduled to happen daily at 2:30am in theAmerica/Chicagotimezone, on days where a forward DST transition happens (such as 10 March 2019):skipwill skip this invocation and next run the job at 2:30 CDT 11 March 2019, while:adjustwill run the job the same amount of time into the day as it would normally run (2.5 hours after midnight, which will be at 3:30 CDT 10 March 2019).
@spec run_in( Fledex.Scheduler.Job.task(), Fledex.Scheduler.Job.schedule() | pos_integer(), keyword() ) :: GenServer.on_start()
@spec run_in(Fledex.Scheduler.Job.task(), pos_integer(), keyword()) :: GenServer.on_start()
Runs the given function in given number of units (this corresponds to milliseconds
unless a custom time_scale is specified). If func is of arity 1, the scheduled
execution time will be passed for each invocation
Takes the same options as run_in/5
@spec run_in(module(), atom(), list(), pos_integer(), keyword()) :: GenServer.on_start()
Runs the given module, function and argument in given number of units (this
corresponds to milliseconds unless a custom time_scale is specified). Any
values in the arguments array which are equal to the magic symbol :sched_ex_scheduled_time
are replaced with the scheduled execution time for each invocation
Supports the following options:
repeat: Whether or not this job should be recurringstart_time: ADateTimeto use as the basis to offset fromtime_scale: A module that implements theFledex.Scheduler.TimeScalebehaviour, by default is set toFledex.Scheduler.IdentityTimeScale. Can be used to speed up time (often used for speeding up test runs)name: To attach a name to the process. Useful for adding a name to Registry to lookup later. ie. {:via, Registry, {YourRegistryName, "scheduled-task-1"}}
Note:
The
m, f, abeing called can contain arguments of:fledex_scheduler_scheduled_time. (or for legacy:sched_ex_scheduled_time). Those will be replaced with the actual time when the job was supposed to be run (which should be close the time it actually . got run)
@spec run_job( Fledex.Scheduler.Job.t(), keyword() ) :: GenServer.on_start()
You can run a Fledex.Scheduler.Job by calling this function.
All the other run_* functions actually map to a job under the hood and therefore this function provides
you with the most flexibility and power.
The additionl test_opts (keyword list) is for passing some extra settings that are mainly interesting for
testing.
@spec update_job( Fledex.Scheduler.Job.t(), keyword() ) :: :ok
You can update the job (for example change your scheduling) by calling this function
If you used run_job/2 your process will get the name of the job nad throuh
this the job will be identified.