船舶更新
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace app\process;
|
||||
|
||||
use app\command\UpdateShipInfoCommand;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
use Workerman\Crontab\Crontab;
|
||||
use Workerman\Timer;
|
||||
use Workerman\Worker;
|
||||
use support\Log;
|
||||
|
||||
class ShipUpdateScheduler extends Worker
|
||||
{
|
||||
public function onWorkerStart()
|
||||
{
|
||||
new Crontab('0 5 */3 * *', function(){
|
||||
$this->runShipUpdateCommand();
|
||||
});
|
||||
// 每三天执行一次船舶信息更新
|
||||
// 3天 = 3 * 24 * 60 * 60 = 259200秒
|
||||
// Timer::add(259200, function() {
|
||||
// $this->runShipUpdateCommand();
|
||||
// });
|
||||
//
|
||||
// // 启动时也执行一次,确保有数据
|
||||
// $this->runShipUpdateCommand();
|
||||
//
|
||||
// Log::info('船舶信息更新调度器已启动');
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行船舶信息更新命令
|
||||
*/
|
||||
private function runShipUpdateCommand()
|
||||
{
|
||||
try {
|
||||
Log::info('开始执行船舶信息更新任务');
|
||||
|
||||
$command = new UpdateShipInfoCommand();
|
||||
$input = new ArrayInput([]);
|
||||
$output = new BufferedOutput();
|
||||
|
||||
$exitCode = $command->run($input, $output);
|
||||
|
||||
if ($exitCode === 0) {
|
||||
Log::info('船舶信息更新任务执行成功: ' . $output->fetch());
|
||||
} else {
|
||||
Log::error('船舶信息更新任务执行失败: ' . $output->fetch());
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('船舶信息更新任务执行异常', [
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user