-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShowPulseDaemon.php
41 lines (30 loc) · 1.14 KB
/
ShowPulseDaemon.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
<?php
namespace App;
use App\Commands\JukeboxSelectionInsertNextCommandHandler;
use App\Commands\PostStatusToWebsiteCommandHandler;
use App\Commands\ShowPulseConstant;
use Exception;
require_once "commands/InsertNextJukeboxSelectionCommandHandler.php";
require_once "commands/PostStatusToWebsiteCommandHandler.php";
$postStatusCommand = new PostStatusToWebsiteCommandHandler();
$nextSelectionCommand = new JukeboxSelectionInsertNextCommandHandler();
$failureCount = 0;
$delaySeconds = 2;
do {
try {
$postStatusCommand->execute();
$nextSelectionCommand->execute();
sleep(ShowPulseConstant::SLEEP_SHORT_VALUE);
$failureCount = 0;
} catch (Exception $e) {
if ($failureCount < ShowPulseConstant::MAX_FAILURES_ALLOWED) {
$message = $e->getMessage() . " (Attempt $failureCount)";
$postStatusCommand->logError($message);
$failureCount++;
}
$sleepTime = $failureCount * $delaySeconds;
sleep($sleepTime);
}
$daemonFileExists = file_exists(ShowPulseConstant::DAEMON_FILE);
} while ($daemonFileExists);
$postStatusCommand->logError("Daemon stopped.");