S2OJ/web/app/scheduler.php

32 lines
705 B
PHP
Raw Normal View History

2023-02-13 12:29:32 +00:00
<?php
$_SERVER['DOCUMENT_ROOT'] = dirname(__DIR__);
require_once $_SERVER['DOCUMENT_ROOT'] . '/app/vendor/autoload.php';
require $_SERVER['DOCUMENT_ROOT'] . '/app/libs/uoj-lib.php';
// Create a new scheduler
$scheduler = new GO\Scheduler([
'tempDir' => '/tmp'
]);
echo '[UOJScheduler] Init', "\n";
// =========== JOBS ===========
// Email
$scheduler->call('UOJMail::cronSendEmail', [], 'cronSendEmail')
->at('* * * * *')
->onlyOne()
->before(function () {
echo "[cronSendEmail] started at " . time() . "\n";
})
->then(function () {
echo "[cronSendEmail] ended at " . time() . "\n";
});
// ============================
// Let the scheduler execute jobs which are due.
$scheduler->run();