List of background/cron jobs with execution schedule?

Is there a list of background/cron jobs with execution schedule available somewhere?

I tried to find out by searching the code, found getJobList(), registerJob() but did not find where the jobs are actually added to the list.

mysql -u<user> -p<pass> -e 'select * from nextcloud.oc_jobs;' somehow lists the jobs, but it is not well readable and hard to figure out which one is executed how often at what times.

I sometimes face topics here where this information could be useful to check if some error message could be related to a cron job execution (and which job exactly) or not.

\OCP\BackgroundJob\IJobListmight be what you are looking for. See https://github.com/nextcloud/server/blob/master/lib/private/BackgroundJob/JobList.php for the implementation details.

1 Like

How can I execute one of the methods?

I’am a beginner and have no idea how to run this method.
For example I want to get all jobs, so I want to run getAll().

I was asking myself the same questions. I tried it by

nano jobList.php

<?php
        include("/var/www/nextcloud/lib/private/BackgroundJob/JobList.php");
        $list = getAll();
        echo "$list";
?>

sudo -u www-data php jobList.php

PHP Fatal error:  Interface 'OCP\BackgroundJob\IJobList' not found in /var/www/nextcloud/lib/private/BackgroundJob/JobList.php on line 37

I guess that external scripts can not include nextcloud scripts something like this including access to database etc.
mysql -u<user> -p<pass> -e 'select * from nextcloud.oc_jobs';

+----+---------------------------------------------------+-----------------+------------+--------------+-------------+--------------------+
| id | class                                             | argument        | last_run   | last_checked | reserved_at | execution_duration |
+----+---------------------------------------------------+-----------------+------------+--------------+-------------+--------------------+
|  1 | OCA\NextcloudAnnouncements\Cron\Crawler           | null            | 1507645808 |   1507664703 |           0 |                 20 |
|  2 | OCA\Files_Versions\BackgroundJob\ExpireVersions   | null            | 1507663802 |   1507664703 |           0 |                  0 |
|  3 | OCA\Activity\BackgroundJob\EmailNotification      | null            | 1507664703 |   1507664703 |           0 |                  0 |
|  4 | OCA\Activity\BackgroundJob\ExpireActivities       | null            | 1507649410 |   1507664703 |           0 |                  0 |
|  5 | OCA\Federation\SyncJob                            | null            | 1496407315 |   1507647609 |  1507647609 |                  0 |
|  6 | OCA\Files\BackgroundJob\ScanFiles                 | null            | 1507664703 |   1507664703 |           0 |                  0 |
|  7 | OCA\Files\BackgroundJob\DeleteOrphanedItems       | null            | 1507664703 |   1507664703 |           0 |                  0 |
|  8 | OCA\Files\BackgroundJob\CleanupFileLocks          | null            | 1507664703 |   1507664703 |           0 |                  0 |
|  9 | OCA\Files_Sharing\DeleteOrphanedSharesJob         | null            | 1507664703 |   1507664703 |           0 |                  0 |
| 10 | OCA\Files_Sharing\ExpireSharesJob                 | null            | 1507636810 |   1507664703 |           0 |                  0 |
| 11 | OCA\DAV\CardDAV\SyncJob                           | null            | 1507636810 |   1507664703 |           0 |                  1 |
| 13 | OCA\UpdateNotification\Notification\BackgroundJob | null            | 1507649410 |   1507664703 |           0 |                  9 |
| 14 | OCA\Files_Trashbin\BackgroundJob\ExpireTrash      | null            | 1507664703 |   1507664703 |           0 |                  0 |
| 15 | \OC\Authentication\Token\DefaultTokenCleanupJob   | null            | 1507664703 |   1507664703 |           0 |                  0 |
| 16 | OCA\FirstRunWizard\Notification\BackgroundJob     | {"uid":"admin"} |          0 |   1507648502 |  1507648502 |                  0 |
| 17 | OCA\FirstRunWizard\Notification\BackgroundJob     | {"uid":"Micha"} |          0 |   1507649403 |  1507649403 |                  0 |
| 19 | OCA\OwnBackup\Jobs\BackupJob                      | null            | 1498129824 |   1507649409 |  1507649409 |                  0 |
| 20 | OCA\UpdateNotification\ResetTokenBackgroundJob    | null            | 1507664703 |   1507664703 |           0 |                  0 |
+----+---------------------------------------------------+-----------------+------------+--------------+-------------+--------------------+

This somehow shows the jobs for me, but it is a bid a mess to extract schedules from it and what which job actually does. I was hoping from an official list from nextcloud developers which contains all background jobs from the nextcloud core/core apps.

Just translated the unix time stamps from above. All active jobs are checked every 15 minutes with cron.php. FirstRunWizard of course does not run for my user(s), anyway the app is also inactive. Federation and OwnBackup are inactive/removed.
For all the other jobs, you could derive the execution schedule moreless from the last_run time stamp:

OCA\NextcloudAnnouncements\Cron\Crawler
last_run 10.10.2017 - 16:30:08
=> still no execution at 01:00 

OCA\Files_Versions\BackgroundJob\ExpireVersions
last_run 10.10.2017 - 21:30:02
=> every 30 minutes?

OCA\Activity\BackgroundJob\EmailNotification
last_run 10.10.2017 - 21:45:03
=> 00:45:02 clearly after 01:00 , and same as `ExpireVersions` then, thus every 30 minutes?

OCA\Activity\BackgroundJob\ExpireActivities
last_run 10.10.2017 - 17:30:10
=> still no execution until 01:00 

OCA\Files\BackgroundJob\ScanFiles
last_run 10.10.2017 - 21:45:03 
=> every 15 minutes

OCA\Files\BackgroundJob\DeleteOrphanedItems
last_run 10.10.2017 - 21:45:03 
=> 00:00:03 at 01:00 , thus every hour?

OCA\Files\BackgroundJob\CleanupFileLocks
last_run 10.10.2017 - 21:45:03 
=> every 15 minutes

OCA\Files_Sharing\DeleteOrphanedSharesJob
last_run 10.10.2017 - 21:45:03 
=> 00:45:02 clearly after 01:00 , thus every 30 minutes?

OCA\Files_Sharing\ExpireSharesJob
last_run 10.10.2017 - 14:00:10 
=> still no execution until 01:00 

OCA\DAV\CardDAV\SyncJob
last_run 10.10.2017 - 14:00:10 
=> same as ExpireSharesJob

OCA\UpdateNotification\Notification\BackgroundJob
last_run 10.10.2017 - 17:30:10 
=> same as ExpireActivities

OCA\Files_Trashbin\BackgroundJob\ExpireTrash
last_run 10.10.2017 - 21:45:03 
=> 00:30:03 at 01:00 , every hour?

\OC\Authentication\Token\DefaultTokenCleanupJob
last_run 10.10.2017 - 21:45:03 
=> every 15 minutes

OCA\UpdateNotification\ResetTokenBackgroundJob
last_run 10.10.2017 - 21:45:03 
=> every 15 minutes

It is a mess to derive the times from there, especially because the jobs seem to be re added after their execution with wanted delay, thus because of exact 15 minutes cron.php will be added to one cron execution later. This causes jobs that want to be executed every 30 minutes to be executed actually every 45 minutes :stuck_out_tongue:.

As you can see from oc_jobs that background jobs are added by the apps, I found this easier: https://github.com/nextcloud/server/blob/master/apps/files_versions/lib/BackgroundJob/ExpireVersions.php#L48
=> files_versions checks for expired file versions every 30 minutes
=> NextcloudAnnouncements\Cron\Crawler, ExpireActivities, ExpireSharesJob, Federation- and CardDAV SyncJobs would be e.g. candidates that run once a day, which can be easily found out by checking their background job php :smile:.

But it thus really depends on the active/installed apps, so everybody should check his own job list via mysql command above.

I know this thread is a bit older but I just found it and wanted to share a tip: using mysql you can easily convert the timestamps to readable dates:

select class, argument, FROM_UNIXTIME(last_run) as last_run, FROM_UNIXTIME(last_checked) as last_checked, FROM_UNIXTIME(reserved_at) as reserved_at from oc_jobs order by last_run;

4 Likes