83 lines
1.8 KiB
PHP
Executable File
83 lines
1.8 KiB
PHP
Executable File
<?php
|
|
|
|
use ASD\ThresholdTimer;
|
|
|
|
require_once(dirname(__FILE__)."/../load.php");
|
|
|
|
require_once("/home/ddninja/private/asdphp/lib/core/ThresholdTimer.php");
|
|
|
|
|
|
$timer = new ThresholdTimer(60);
|
|
|
|
function logInfo(string $msg) {
|
|
echo date("Y-m-d H:i")." - ".$msg,PHP_EOL;
|
|
}
|
|
function execHour() {
|
|
return intval(date('i')) == 0;
|
|
}
|
|
function execDay() {
|
|
return execHour() && intval(date('H')) == 3;
|
|
}
|
|
function getMinuteTasks() {
|
|
return [
|
|
GenerateAdminActivationMailTask::class,
|
|
GenerateUserActivationMailTask::class,
|
|
GenerateAdminPasswordRecoveryMailTask::class,
|
|
GenerateUserPasswordRecoveryMailTask::class,
|
|
MailSendTask::class
|
|
];
|
|
}
|
|
function getHourTasks() {
|
|
return [
|
|
// NewsletterCheckTask::class,
|
|
DeleteOldPasswordResetRequestsTask::class,
|
|
UpdateMeteoCacheTask::class,
|
|
GenerateCommentiWarningMailTask::class
|
|
];
|
|
}
|
|
function getDailyTasks() {
|
|
return [
|
|
// SendBackupTask::class
|
|
];
|
|
}
|
|
|
|
function execute($taskName) {
|
|
try {
|
|
if ($taskName::isActive()){
|
|
logInfo("Executing task $taskName");
|
|
$taskName::execute();
|
|
logInfo("Task $taskName executed with success");
|
|
}
|
|
}
|
|
catch (Exception $ex) {
|
|
logInfo("Task $taskName failed execution");
|
|
var_dump($ex);
|
|
}
|
|
}
|
|
|
|
logInfo("Worker STARTED!!");
|
|
|
|
$count = 1;
|
|
while (1) {
|
|
logInfo("Executing Minute");
|
|
foreach (getMinuteTasks() as $task ) {
|
|
execute($task);
|
|
}
|
|
if (execHour()) {
|
|
logInfo("Exec hourly");
|
|
foreach (getHourTasks() as $task ) {
|
|
execute($task);
|
|
}
|
|
}
|
|
if (execDay()) {
|
|
logInfo("Exec Daily");
|
|
foreach (getDailyTasks() as $task ) {
|
|
execute($task);
|
|
}
|
|
}
|
|
|
|
$timer->waitUntilThresholdReached(true);
|
|
}
|
|
|
|
|
|
?>
|