TimedJob
extends Job
in package
Simple base class to extend to run periodic background jobs.
Call setInterval with your desired interval in seconds from the constructor.
Tags
Table of Contents
Properties
- $allowParallelRuns : bool
- $argument : mixed
- $id : int
- $interval : int
- $lastRun : int
- $time : ITimeFactory
- $timeSensitivity : int
Methods
- __construct() : mixed
- execute() : void
- Run the job if the last run is more than the interval ago
- getAllowParallelRuns() : bool
- getArgument() : mixed
- Get the argument associated with the background job This is the argument that will be passed to the background job
- getId() : int
- Get the id of the background job This id is determined by the job list when a job is added to the list
- getLastRun() : int
- Get the last time this job was run as unix timestamp
- isTimeSensitive() : bool
- Whether the background job is time sensitive and needs to run soon after the scheduled interval, of if it is okay to be delayed until a later time.
- setAllowParallelRuns() : void
- Set this to false to prevent two Jobs from this class from running in parallel
- setArgument() : mixed
- setId() : mixed
- setInterval() : mixed
- Set the interval for the job
- setLastRun() : mixed
- setTimeSensitivity() : void
- If your background job is not time sensitive (sending instant email notifications, etc.) it would be nice to set it to IJob::TIME_INSENSITIVE This way the execution can be delayed during high usage times.
- start() : void
- Run the job if the last run is more than the interval ago
- run() : void
- The actual function that is called to run the job
Properties
$allowParallelRuns
protected
bool
$allowParallelRuns
= true
$argument
protected
mixed
$argument
$id
protected
int
$id
= 0
$interval
protected
int
$interval
= 0
$lastRun
protected
int
$lastRun
= 0
$time
protected
ITimeFactory
$time
$timeSensitivity
protected
int
$timeSensitivity
= \OCP\BackgroundJob\IJob::TIME_SENSITIVE
Methods
__construct()
public
__construct(ITimeFactory $time) : mixed
Parameters
- $time : ITimeFactory
Tags
execute()
Run the job if the last run is more than the interval ago
public
final execute(IJobList $jobList[, ILogger|null $logger = null ]) : void
Use start() instead
Parameters
Tags
getAllowParallelRuns()
public
getAllowParallelRuns() : bool
Tags
Return values
boolgetArgument()
Get the argument associated with the background job This is the argument that will be passed to the background job
public
getArgument() : mixed
Tags
getId()
Get the id of the background job This id is determined by the job list when a job is added to the list
public
final getId() : int
Tags
Return values
intgetLastRun()
Get the last time this job was run as unix timestamp
public
final getLastRun() : int
Tags
Return values
intisTimeSensitive()
Whether the background job is time sensitive and needs to run soon after the scheduled interval, of if it is okay to be delayed until a later time.
public
isTimeSensitive() : bool
Tags
Return values
boolsetAllowParallelRuns()
Set this to false to prevent two Jobs from this class from running in parallel
public
setAllowParallelRuns(bool $allow) : void
Parameters
- $allow : bool
Tags
setArgument()
public
setArgument(mixed $argument) : mixed
Parameters
- $argument : mixed
Tags
setId()
public
final setId(int $id) : mixed
Parameters
- $id : int
Tags
setInterval()
Set the interval for the job
public
setInterval(int $seconds) : mixed
Parameters
- $seconds : int
-
the time to pass between two runs of the same job in seconds
Tags
setLastRun()
public
final setLastRun(int $lastRun) : mixed
Parameters
- $lastRun : int
Tags
setTimeSensitivity()
If your background job is not time sensitive (sending instant email notifications, etc.) it would be nice to set it to IJob::TIME_INSENSITIVE This way the execution can be delayed during high usage times.
public
setTimeSensitivity(int $sensitivity) : void
Parameters
- $sensitivity : int
Tags
start()
Run the job if the last run is more than the interval ago
public
final start(IJobList $jobList) : void
Parameters
- $jobList : IJobList
-
The job list that manages the state of this job
Tags
run()
The actual function that is called to run the job
protected
abstract run(mixed $argument) : void
Parameters
- $argument : mixed