-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.php
executable file
·59 lines (51 loc) · 1.35 KB
/
run.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env php
<?php
set_time_limit(0);
date_default_timezone_set('Europe/Berlin');
require_once __DIR__.'/vendor/autoload.php';
class Runner
{
protected $working = true;
/**
* @var array
*/
protected $mailboxes = [];
public function start()
{
//pcntl_signal(SIGTERM, array(&$this, 'stop'));
\Pottkinder\ImapSync\Service\InstallService::getInstance()->ensureInstallation();
$this->mailboxes = \Pottkinder\ImapSync\Service\ConfigurationService::getInstance()->getConfiguration();
$this->run();
}
public function run()
{
while ($this->working) {
$task = $this->getTask();
if ($task !== null) {
$tmp = new \Pottkinder\ImapSync\Worker\Thread($task);
$tmp->start();
} else {
\Pottkinder\ImapSync\Service\LogService::log(getmypid(), 'No jobs found.');
}
sleep(30);
}
}
public function stop()
{
$this->working = false;
}
protected function getTask()
{
/**
* @var \Pottkinder\ImapSync\Model\Mailbox
*/
foreach ($this->mailboxes as $mailbox) {
if ($mailbox->shouldRun()) {
return $mailbox;
}
}
return null;
}
}
$runner = new Runner();
$runner->start();