Nextcloud PHP API (master)

TimedJob extends Job
in package

AbstractYes

Simple base class to extend to run periodic background jobs.

Call setInterval with your desired interval in seconds from the constructor.

Tags
since
15.0.0
since
25.0.0

deprecated execute() method in favor of start()

since
33.0.0

removed deprecated execute() method

Table of Contents

Properties

$allowParallelRuns  : bool
$argument  : mixed
$id  : string
$interval  : int
$lastRun  : int
$time  : ITimeFactory
$timeSensitivity  : int

Methods

__construct()  : mixed
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()  : string
Get the id of the background job This id is determined by the job list when a job is added to the list
getInterval()  : int
Get the interval [seconds] for the job
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 the same class from running in parallel
setArgument()  : void
setId()  : void
setInterval()  : void
Set the interval for the job
setLastRun()  : void
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()  : mixed

Properties

$allowParallelRuns

protected bool $allowParallelRuns = true

$argument

protected mixed $argument = null

$id

protected string $id = '0'

$lastRun

protected int $lastRun = 0

$timeSensitivity

protected int $timeSensitivity = \OCP\BackgroundJob\IJob::TIME_SENSITIVE

Methods

getAllowParallelRuns()

public getAllowParallelRuns() : bool
Attributes
#[Override]
Return values
bool

getArgument()

Get the argument associated with the background job This is the argument that will be passed to the background job

public getArgument() : mixed
Attributes
#[Override]

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() : string
Attributes
#[Override]
Return values
string

getInterval()

Get the interval [seconds] for the job

public getInterval() : int
Tags
since
32.0.0
Return values
int

getLastRun()

Get the last time this job was run as unix timestamp

public final getLastRun() : int
Attributes
#[Override]
Return values
int

isTimeSensitive()

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
since
24.0.0
Return values
bool

setAllowParallelRuns()

Set this to false to prevent two Jobs from the same class from running in parallel

public setAllowParallelRuns(bool $allow) : void
Parameters
$allow : bool
Attributes
#[Override]

setArgument()

public setArgument(mixed $argument) : void
Parameters
$argument : mixed
Attributes
#[Override]

setId()

public final setId(string $id) : void
Parameters
$id : string
Attributes
#[Override]

setInterval()

Set the interval for the job

public setInterval(int $seconds) : void
Parameters
$seconds : int

the time to pass between two runs of the same job in seconds

Tags
since
15.0.0

setLastRun()

public final setLastRun(int $lastRun) : void
Parameters
$lastRun : int
Attributes
#[Override]

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
psalm-param

IJob::TIME_* $sensitivity

since
24.0.0

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
since
25.0.0

run()

protected abstract run(mixed $argument) : mixed
Parameters
$argument : mixed

        
On this page

Search results