Nextcloud PHP API (stable18)

IJobList

Interface IJobList

This interface provides functions to register background jobs

To create a new background job create a new class that inherits from either \OC\BackgroundJob\Job, \OC\BackgroundJob\QueuedJob or \OC\BackgroundJob\TimedJob and register it using ->add($job, $argument), $argument will be passed to the run() function of the job when the job is executed.

A regular job will be executed every time cron.php is run, a QueuedJob will only run once and a TimedJob will only run at a specific interval which is to be specified in the constructor of the job by calling $this->setInterval($interval) with $interval in seconds.

Tags
since
7.0.0

Table of Contents

add()  : mixed
Add a job to the list
getAll()  : \OCP\BackgroundJob\IJob[]
get all jobs in the list
getById()  : IJob|null
getLastJob()  : int
get the id of the last ran job
getNext()  : IJob|null
get the next job in the list
has()  : bool
check if a job is in the list
remove()  : mixed
Remove a job from the list
setExecutionTime()  : mixed
set the run duration of $job
setLastJob()  : mixed
set the job that was last ran to the current time
setLastRun()  : mixed
set the lastRun of $job to now
unlockJob()  : mixed
Remove the reservation for a job

Methods

add()

Add a job to the list

public add(IJob|string $job[, mixed $argument = null ]) : mixed
Parameters
$job : IJob|string
$argument : mixed = null

The argument to be passed to $job->run() when the job is exectured

Tags
since
7.0.0
Return values
mixed

getAll()

get all jobs in the list

public getAll() : \OCP\BackgroundJob\IJob[]
Tags
since
7.0.0
deprecated
9.0.0
  • This method is dangerous since it can cause load and memory problems when creating too many instances.
Return values
\OCP\BackgroundJob\IJob[]

getById()

public getById(int $id) : IJob|null
Parameters
$id : int
Tags
since
7.0.0
Return values
IJob|null

getLastJob()

get the id of the last ran job

public getLastJob() : int
Tags
since
7.0.0
deprecated
9.1.0
  • The functionality behind the value is deprecated, it only tells you which job finished last, but since we now allow multiple executors to run in parallel, it's not used to calculate the next job.
Return values
int

getNext()

get the next job in the list

public getNext() : IJob|null
Tags
since
7.0.0
Return values
IJob|null

has()

check if a job is in the list

public has(IJob|string $job, mixed $argument) : bool
Parameters
$job : IJob|string
$argument : mixed
Tags
since
7.0.0
Return values
bool

remove()

Remove a job from the list

public remove(IJob|string $job[, mixed $argument = null ]) : mixed
Parameters
$job : IJob|string
$argument : mixed = null
Tags
since
7.0.0
Return values
mixed

setExecutionTime()

set the run duration of $job

public setExecutionTime(IJob $job,  $timeTaken) : mixed
Parameters
$job : IJob
$timeTaken :
Tags
since
12.0.0
Return values
mixed

setLastJob()

set the job that was last ran to the current time

public setLastJob(IJob $job) : mixed
Parameters
$job : IJob
Tags
since
7.0.0
Return values
mixed

setLastRun()

set the lastRun of $job to now

public setLastRun(IJob $job) : mixed
Parameters
$job : IJob
Tags
since
7.0.0
Return values
mixed

unlockJob()

Remove the reservation for a job

public unlockJob(IJob $job) : mixed
Parameters
$job : IJob
Tags
since
9.1.0
Return values
mixed

Search results