1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by Gorlum 08.02.2020 18:54 |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Fleet; |
7
|
|
|
|
8
|
|
|
use Core\GlobalContainer; |
9
|
|
|
use Core\HttpUrl; |
10
|
|
|
use SN; |
11
|
|
|
use classConfig; |
12
|
|
|
use Core\Scheduler\TaskPeriodic; |
13
|
|
|
use Core\Scheduler\Lock; |
14
|
|
|
|
15
|
|
|
class TaskDispatchFleets extends TaskPeriodic { |
16
|
|
|
/** |
17
|
|
|
* Name of config field to monitor |
18
|
|
|
* |
19
|
|
|
* @var string $configName |
20
|
|
|
*/ |
21
|
|
|
protected $configName = 'fleet_update_last'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param GlobalContainer $gc |
25
|
|
|
* |
26
|
|
|
* @return Lock |
27
|
|
|
*/ |
28
|
|
|
public static function getLock($gc) { |
29
|
|
|
return new Lock($gc, 'fleet_update_lock', PERIOD_MINUTE, 10, classConfig::DATE_TYPE_UNIX); |
30
|
|
|
// return new Lock($gc, 'fleet_update_lock', 10, 0, classConfig::DATE_TYPE_UNIX); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* TaskDispatchFleets constructor. |
35
|
|
|
* |
36
|
|
|
* @param GlobalContainer|null $gc |
37
|
|
|
*/ |
38
|
|
|
public function __construct($gc = null) { |
39
|
|
|
parent::__construct($gc); |
40
|
|
|
|
41
|
|
|
$this->interval = $this->config->fleet_update_interval; |
42
|
|
|
$this->lock = $this::getLock($this->gc); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function isTaskAllowed() { |
46
|
|
|
return !SN::$options[PAGE_OPTION_FLEET_UPDATE_SKIP] && !SN::gameIsDisabled() && parent::isTaskAllowed(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* This function called if task have a lock and lock grace period expired |
51
|
|
|
* Here can be added some checks and even recovery procedures for expired lock |
52
|
|
|
* |
53
|
|
|
* @return bool True if task can proceed even on lock expiration time |
54
|
|
|
*/ |
55
|
|
|
protected function proceedLockExpiration() { |
56
|
|
|
$this->gc->debug->warning('Fleet dispatcher was locked too long - unlocked by watchdog', 'FFH Error', 504); |
57
|
|
|
|
58
|
|
|
return Lock::LOCK_EXPIRED_IGNORE; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
protected function task() { |
63
|
|
|
$url = HttpUrl::spawn($this->gc) |
64
|
|
|
->parseUrl(SN_ROOT_VIRTUAL) |
65
|
|
|
->addPath('index.php') |
66
|
|
|
->addParams(['page' => 'worker', 'mode' => 'dispatchFleets',]); |
67
|
|
|
|
68
|
|
|
sn_get_url_contents($url->urlSigned()); |
69
|
|
|
|
70
|
|
|
// invokeUrl($url); |
71
|
|
|
|
72
|
|
|
return true; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|