[Owncloud] Background Jobs

Jakob Sack mail at jakobsack.de
Sat Aug 11 14:07:08 UTC 2012


Hi,

yesterday I pushed the new Background Jobs system to ownCloud master. 
As you can guess from the name, this feature allows ownCloud to do 
certain tasks in the background without blocking the UI. It also makes 
it possible to execute some tasks without any need of user interaction, 
for example fetching news while the user is on holidays.
 From a users perspective there is not much to pay attention to, 
background jobs tries to get out of the way as much as possible. On the 
other hand, administrators can use the settings interface to set the way 
background jobs are executed. There are four options: using the systems 
cron feature, using a webcron service, using AJAX or not using 
background jobs at all. Using the systems cron feature is the preferred 
way. It allows regular executed jobs without the limitations the web 
server may have. The second recommended option is the webcron 
implementation. By registering your ownCloud cron.php address at a 
webcron service like [1] you ensure that background jobs will be 
executed regularly. Using AJAX is the default option, although the least 
reliable. Every time a  user visits the page a single background job 
gets executed. The disadvantage of this solution compared to the webcron 
service is that it requires regular visits of the page. The reason for 
making this option the default is that this solution simply does not 
require access to the system or registration on some third party 
service.
When you are implementing background jobs in your app, please be aware 
of the difference between the AJAX/Webcron and the cron implementation! 
The AJAX/Webcron implementation gets started by 
your-favorite-web-server, so you might have some limitations on 
execution time or memory. These limitations do not affect the system 
cron implementation, which calls php from the command line. As a 
consequence, you should split large tasks when not using system cron. 
You can check whether the app has been started by systems cron by 
checking if OC::$CLI is set to true.
If you want to  use background jobs in your app, you have to register 
them in appinfo/app.php by calling OCP\BackgroundJobs::addRegularTask( 
$class,  $method ).
The first app featuring a background job is the news app being 
implemented by Alessandro Cosentino (zimba12). If you want to use 
background jobs in your app, have a look at the apps:newsapp repository 
first! There you will not only find a working example, but also a 
strategy of how to deal with the different requirements of AJAX/Webcron 
and the system cron.
Regards,

Jakob

1: http://www.easycron.com/



More information about the Owncloud mailing list