65 lines
1.4 KiB
PHP
65 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Services\Cron\HttpQueue as CronHttpQueue;
|
|
use App\Services\Cron\ArticleSchema as CronArticleSchema;
|
|
|
|
final class Cron
|
|
{
|
|
public bool $bIsTest = false;
|
|
public ?int $iTestH = null;
|
|
public ?int $iTestI = null;
|
|
public ?int $iTestS = null;
|
|
|
|
public function run(): void
|
|
{
|
|
$h = (int) date("H");
|
|
$i = (int) date("i");
|
|
$s = (int) date("s");
|
|
|
|
if ($this->bIsTest) {
|
|
$h = (int) ($this->iTestH ?? $h);
|
|
$i = (int) ($this->iTestI ?? $i);
|
|
$s = (int) ($this->iTestS ?? $s);
|
|
}
|
|
|
|
echo "cron开始执行\n\n";
|
|
|
|
if ($s == 0 && $i % 3 === 0) {
|
|
CronArticleSchema::cacheTgSave();
|
|
CronArticleSchema::pushToSlave();
|
|
CronHttpQueue::pop();
|
|
}
|
|
|
|
if ($i === 0) {
|
|
// ReportSender::handle();
|
|
}
|
|
}
|
|
|
|
public function setTestH(int $h): void
|
|
{
|
|
$this->enableTestMode();
|
|
$this->iTestH = $h;
|
|
}
|
|
|
|
public function setTestI(int $i): void
|
|
{
|
|
$this->enableTestMode();
|
|
$this->iTestI = $i;
|
|
}
|
|
|
|
public function setTestS(int $s): void
|
|
{
|
|
$this->enableTestMode();
|
|
$this->iTestS = $s;
|
|
}
|
|
|
|
public function enableTestMode(bool $enable = true): void
|
|
{
|
|
$this->bIsTest = $enable;
|
|
}
|
|
}
|