owncloud/core — pull request #3051 by icewind1991 (2013-04-20 21:40:21+00:00)
Title: Reworked background job system.

This replaces the old background job system with a new object oriented system.

Each job is represented by a class that inherits from `OC\BackgroundJob\Job` and is registered by calling `OCP\BackgroundJob::registerJob($job, $argument=null)` where $job is either an instance of the job class or the classname of the job class, it also accepts one argument which is passed to the job on execution, this argument is json encoded before it's stored in the db so it can hold any variable that can be json encoded.

When a job is executed `$job->run($argument)` is called.

Instead of extending `OC\BackgroundJob\Job` there is also the option of extending `OC\BackgroundJob\QueuedJob` or `OC\BackgroundJob\TimedJob`.
- A `QueuedJob` is only run once and automatically removed from the job list afterwards.
- A `TimedJob` is only run at most once every specific interval, this interval is to be set in the contructor using `$this->setInterval($interval)` with $interval in secconds

--

Example:

```
class ExampleJob extends \OC\BackgroundJob\Job{
public function run($argument){
error_log($argument);
}
}

\OCP\BackgroundJob::register('ExampleJob', 'foobar');
```

Or with a timed job:

```
class ExampleTimedJob extends \OC\BackgroundJob\TimedJob{
public function __construct(){
$this->setInterval(60);
}
public function run($argument){
error_log(time());
}
}

\OCP\BackgroundJob::register('ExampleTimedJob');
```

--

This new system provides a common implementation of a system that currently needs to be re-implemented for every app that needs it, the TimedJob and makes it easy to add more job types later if needed.