Skip to content

Commit 675c3bf

Browse files
Cleanup comments, tweak lock file creation
1 parent 77fe405 commit 675c3bf

File tree

1 file changed

+51
-52
lines changed

1 file changed

+51
-52
lines changed

Diff for: src/Shell/SchedulerShell.php

+51-52
Original file line numberDiff line numberDiff line change
@@ -43,43 +43,42 @@
4343

4444
class SchedulerShell extends Shell{
4545

46-
public $tasks = [];
47-
48-
/**
49-
* The array of scheduled tasks.
50-
*/
46+
/**
47+
* The array of scheduled tasks.
48+
*/
5149
private $schedule = [];
5250

53-
/**
54-
* The key which you set Configure::read() for your jobs
55-
*/
51+
/**
52+
* The key which you set Configure::read() for your jobs
53+
*/
5654
private $configKey = 'SchedulerShell';
5755

58-
/**
59-
* The path where the store file is placed. null will store in Config folder
60-
*/
61-
private $storePath = null;
56+
/**
57+
* The path where the store file is placed. null will store in Config folder
58+
*/
59+
private $storePath = TMP;
6260

63-
/**
64-
* The file name of the store
65-
*/
61+
/**
62+
* The file name of the store
63+
*/
6664
private $storeFile = 'cron_scheduler.json';
6765

68-
/**
69-
* The number of seconds to wait before running a parallel SchedulerShell
70-
*/
71-
private $processingTimeout = 600;
66+
/**
67+
* The file name of the processing flag file (indicates that existing job is running)
68+
*/
69+
private $processingFlagFile = '.cron_scheduler_processing_flag';
7270

73-
/**
74-
* The main method which you want to schedule for the most frequent interval
75-
*/
71+
/**
72+
* The number of seconds to wait before running a parallel SchedulerShell
73+
*/
74+
private $processingTimeout = 600;
7675

77-
/**
78-
* main function.
79-
*
80-
* @access public
81-
* @return void
82-
*/
76+
/**
77+
* The main method which you want to schedule for the most frequent interval
78+
*
79+
* @access public
80+
* @return void
81+
*/
8382
public function main() {
8483

8584
// read in the config
@@ -93,6 +92,10 @@ public function main() {
9392
$this->storeFile = $config['storeFile'];
9493
}
9594

95+
if (isset($config['processingFlagFile'])) {
96+
$this->processingFlagFile = $config['processingFlagFile'];
97+
}
98+
9699
if (isset($config['processingTimeout'])) {
97100
$this->processingTimeout = $config['processingTimeout'];
98101
}
@@ -110,17 +113,17 @@ public function main() {
110113
$this->runjobs();
111114
}
112115

113-
/**
114-
* The connect method adds tasks to the schedule
115-
*
116-
* @access public
117-
* @param string $name - unique name for this job, isn't bound to anything and doesn't matter what it is
118-
* @param string $interval - date interval string "PT5M" (every 5 min) or a relative Date string "next day 10:00"
119-
* @param string $task - name of the cake task to call
120-
* @param string $action - name of the method within the task to call
121-
* @param array $pass - array of arguments to pass to the method
122-
* @return void
123-
*/
116+
/**
117+
* The connect method adds tasks to the schedule
118+
*
119+
* @access public
120+
* @param string $name - unique name for this job, isn't bound to anything and doesn't matter what it is
121+
* @param string $interval - date interval string "PT5M" (every 5 min) or a relative Date string "next day 10:00"
122+
* @param string $task - name of the cake task to call
123+
* @param string $action - name of the method within the task to call
124+
* @param array $pass - array of arguments to pass to the method
125+
* @return void
126+
*/
124127
public function connect($name, $interval, $task, $action = 'main', $pass = []) {
125128
$this->schedule[$name] = [
126129
'name' => $name,
@@ -133,18 +136,18 @@ public function connect($name, $interval, $task, $action = 'main', $pass = []) {
133136
];
134137
}
135138

136-
/**
137-
* Process the tasks when they need to run
138-
*
139-
* @access private
140-
* @return void
141-
*/
139+
/**
140+
* Process the tasks when they need to run
141+
*
142+
* @access private
143+
* @return void
144+
*/
142145
private function runjobs() {
143-
$dir = new Folder(TMP);
146+
$dir = new Folder($this->storePath);
144147

145148
// set processing flag so function takes place only once at any given time
146-
$processing = count($dir->find('\.scheduler_running_flag'));
147-
$processingFlag = new File($dir->slashTerm($dir->pwd()) . '.scheduler_running_flag');
149+
$processingFlag = new File($dir->slashTerm($dir->pwd()) . $this->processingFlagFile, false);
150+
$processing = $processingFlag->exists();
148151

149152
if ($processing && (time() - $processingFlag->lastChange()) < $this->processingTimeout) {
150153
$this->out("Scheduler already running! Exiting.");
@@ -154,10 +157,6 @@ private function runjobs() {
154157
$processingFlag->create();
155158
}
156159

157-
if (!$this->storePath) {
158-
$this->storePath = TMP;
159-
}
160-
161160
// look for a store of the previous run
162161
$store = "";
163162
$storeFilePath = $this->storePath.$this->storeFile;

0 commit comments

Comments
 (0)