更新
This commit is contained in:
@@ -26,6 +26,14 @@ use Cron\CronExpression;
|
||||
*/
|
||||
class CrontabLogic extends BaseLogic
|
||||
{
|
||||
private const CRAWLER_MIGRATED_MESSAGE = 'crawler任务已迁移到Docker容器调度,请查看管理端爬虫任务日志';
|
||||
|
||||
private const CRAWLER_MIGRATED_COMMANDS = [
|
||||
'crawler',
|
||||
'truth_social',
|
||||
'fifa_worldcup_news',
|
||||
];
|
||||
|
||||
/**
|
||||
* @notes 添加定时任务
|
||||
* @param $params
|
||||
@@ -158,6 +166,13 @@ class CrontabLogic extends BaseLogic
|
||||
throw new \Exception('定时任务不存在');
|
||||
}
|
||||
|
||||
if (in_array($crontab->command, self::CRAWLER_MIGRATED_COMMANDS, true)) {
|
||||
Crontab::where('id', $crontab->id)->update([
|
||||
'error' => self::CRAWLER_MIGRATED_MESSAGE,
|
||||
]);
|
||||
throw new \Exception(self::CRAWLER_MIGRATED_MESSAGE);
|
||||
}
|
||||
|
||||
$log = CrontabLog::create([
|
||||
'crontab_id' => $crontab->id,
|
||||
'name' => $crontab->name,
|
||||
@@ -169,18 +184,6 @@ class CrontabLogic extends BaseLogic
|
||||
'trigger_type' => 2,
|
||||
]);
|
||||
|
||||
if ($crontab->command === 'crawler') {
|
||||
$crawlerDir = app()->getRootPath() . 'public/dongqiudi-crawler';
|
||||
$python = 'python3';
|
||||
$action = $crontab->params ?: 'all';
|
||||
$logId = $log->id;
|
||||
$crontabId = $crontab->id;
|
||||
$cmd = "cd {$crawlerDir} && nohup {$python} main.py {$action} --log-id={$logId} --crontab-id={$crontabId} > /dev/null 2>&1 &";
|
||||
\shell_exec($cmd);
|
||||
|
||||
return ['log_id' => $logId, 'output' => '任务已提交,后台执行中...', 'async' => true];
|
||||
}
|
||||
|
||||
if ($crontab->command === 'truth_social') {
|
||||
$crawlerDir = app()->getRootPath() . 'public/dongqiudi-crawler';
|
||||
$python = 'python3';
|
||||
|
||||
Reference in New Issue
Block a user