Completed
Push — master ( 850169...6f6518 )
by Lukas
43:58 queued 29:47
created

BackgroundJob::addRegularTask()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Bart Visscher <[email protected]>
6
 * @author Felix Moeller <[email protected]>
7
 * @author Jakob Sack <[email protected]>
8
 * @author Joas Schilling <[email protected]>
9
 * @author Jörn Friedrich Dreyer <[email protected]>
10
 * @author Morris Jobke <[email protected]>
11
 * @author Robin Appelman <[email protected]>
12
 * @author Robin McCorkell <[email protected]>
13
 *
14
 * @license AGPL-3.0
15
 *
16
 * This code is free software: you can redistribute it and/or modify
17
 * it under the terms of the GNU Affero General Public License, version 3,
18
 * as published by the Free Software Foundation.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License, version 3,
26
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
27
 *
28
 */
29
30
/**
31
 * Public interface of ownCloud for background jobs.
32
 */
33
34
// use OCP namespace for all classes that are considered public.
35
// This means that they should be used by apps instead of the internal ownCloud classes
36
namespace OCP;
37
38
39
/**
40
 * This class provides functions to register backgroundjobs in ownCloud
41
 *
42
 * To create a new backgroundjob create a new class that inherits from either \OC\BackgroundJob\Job,
43
 * \OC\BackgroundJob\QueuedJob or \OC\BackgroundJob\TimedJob and register it using
44
 * \OCP\BackgroundJob->registerJob($job, $argument), $argument will be passed to the run() function
45
 * of the job when the job is executed.
46
 *
47
 * A regular Job will be executed every time cron.php is run, a QueuedJob will only run once and a TimedJob
48
 * will only run at a specific interval which is to be specified in the constructor of the job by calling
49
 * $this->setInterval($interval) with $interval in seconds.
50
 * @since 4.5.0
51
 */
52
class BackgroundJob {
53
	/**
54
	 * get the execution type of background jobs
55
	 *
56
	 * @return string
57
	 *
58
	 * This method returns the type how background jobs are executed. If the user
59
	 * did not select something, the type is ajax.
60
	 * @since 5.0.0
61
	 */
62
	public static function getExecutionType() {
63
		return \OC::$server->getConfig()->getAppValue('core', 'backgroundjobs_mode', 'ajax');
64
	}
65
66
	/**
67
	 * sets the background jobs execution type
68
	 *
69
	 * @param string $type execution type
70
	 * @return false|null
71
	 *
72
	 * This method sets the execution type of the background jobs. Possible types
73
	 * are "none", "ajax", "webcron", "cron"
74
	 * @since 5.0.0
75
	 */
76
	public static function setExecutionType($type) {
77
		if( !in_array( $type, array('none', 'ajax', 'webcron', 'cron'))) {
78
			return false;
79
		}
80
		\OC::$server->getConfig()->setAppValue('core', 'backgroundjobs_mode', $type);
81
	}
82
83
	/**
84
	 * @param string $job
85
	 * @param mixed $argument
86
	 * @deprecated 8.1.0 Use \OC::$server->getJobList()->add() instead
87
	 * @since 6.0.0
88
	 */
89
	public static function registerJob($job, $argument = null) {
90
		$jobList = \OC::$server->getJobList();
91
		$jobList->add($job, $argument);
92
	}
93
}
94