|
|
@@ -136,79 +136,55 @@ class StationTaskBatchService
|
|
|
{
|
|
|
LogService::log(__METHOD__,'runMany','波次任务分配6.1:'.json_encode($stationTaskBatches));
|
|
|
$stationTaskBatches_failed = null;
|
|
|
- ($execute =
|
|
|
- function (
|
|
|
- Collection $stationTaskBatches, &$stationTaskBatches_failed) {
|
|
|
- LogService::log(__METHOD__,'runMany','波次任务分配6.2:'.json_encode($stationTaskBatches));
|
|
|
- if ($stationTaskBatches->isEmpty()) return;
|
|
|
- LogService::log(__METHOD__,'runMany','波次任务分配6.3:'.json_encode($stationTaskBatches));
|
|
|
+ ($execute = function(Collection $stationTaskBatches, &$stationTaskBatches_failed){
|
|
|
+ if ($stationTaskBatches->isEmpty()) return; //波次任务不存在 跳出
|
|
|
$stationTaskBatches_failed = collect();
|
|
|
- LogService::log(__METHOD__,'runMany','波次任务分配6.4:'.json_encode($stationTaskBatches));
|
|
|
foreach ($stationTaskBatches as $stationTaskBatch) {
|
|
|
- LogService::log(__METHOD__,'runMany','波次任务分配6.5:'.json_encode($stationTaskBatches));
|
|
|
- $failed = !$this->run($stationTaskBatch);
|
|
|
- LogService::log(__METHOD__,'runMany','波次任务分配6.6:'.json_encode($stationTaskBatches));
|
|
|
- if ($failed) $stationTaskBatches_failed->push($stationTaskBatch);
|
|
|
+ $failed = !$this->run($stationTaskBatch); //运行波次 获取执行结果
|
|
|
+ if ($failed) $stationTaskBatches_failed->push($stationTaskBatch);//执行失败 记录失败波次
|
|
|
}
|
|
|
- })($stationTaskBatches, $stationTaskBatches_failed);
|
|
|
+ })($stationTaskBatches, $stationTaskBatches_failed);
|
|
|
|
|
|
- ($logAtFailings_andWait =
|
|
|
- function ($stationTaskBatches_failed) {
|
|
|
- LogService::log(__METHOD__,'runMany','波次任务分配6.7:'.json_encode($stationTaskBatches_failed));
|
|
|
+ (function ($stationTaskBatches_failed) {
|
|
|
if ($stationTaskBatches_failed->isEmpty()) return;
|
|
|
- LogService::log(__METHOD__,'runMany','波次任务分配6.8:'.json_encode($stationTaskBatches_failed));
|
|
|
$retry_after_sec = config('task.batchTask.retry_after_sec');
|
|
|
LogService::log(__METHOD__, __FUNCTION__,
|
|
|
'任务波次没有执行完的,' . $retry_after_sec . '秒后准备重试:' . $stationTaskBatches_failed->toJson()
|
|
|
. '调用堆栈r:' . json_encode(array_slice(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), 0, 3))
|
|
|
);
|
|
|
- LogService::log(__METHOD__,'runMany','波次任务分配6.9:'.json_encode($stationTaskBatches_failed));
|
|
|
sleep($retry_after_sec);
|
|
|
- LogService::log(__METHOD__,'runMany','波次任务分配6.91:'.json_encode($stationTaskBatches_failed));
|
|
|
})($stationTaskBatches_failed);
|
|
|
- LogService::log(__METHOD__,'runMany','波次任务分配6.92:'.json_encode($stationTaskBatches));
|
|
|
-
|
|
|
- $execute ($stationTaskBatches_failed, $stationTaskBatches_failed); //再次尝试
|
|
|
- LogService::log(__METHOD__,'runMany','波次任务分配6.93:'.json_encode($stationTaskBatches));
|
|
|
- $this->markManyExcepted ($stationTaskBatches_failed);
|
|
|
- LogService::log(__METHOD__,'runMany','波次任务分配6.94:'.json_encode($stationTaskBatches));
|
|
|
- return $stationTaskBatches_failed;
|
|
|
+ $execute($stationTaskBatches_failed, $stationTaskBatches_failed); //再次尝试
|
|
|
+ $this->markManyExcepted($stationTaskBatches_failed);
|
|
|
+ return $stationTaskBatches_failed;
|
|
|
}
|
|
|
|
|
|
function run(StationTaskBatch $stationTaskBatch): bool
|
|
|
{
|
|
|
- LogService::log(__METHOD__,'runMany','波次任务分配6.r1:'.json_encode($stationTaskBatch));
|
|
|
$this->instant($this->foreignHaiRoboticsService,'ForeignHaiRoboticsService');
|
|
|
$this->instant($this->stationService,'StationService');
|
|
|
$stationTaskBatch->loadMissing(['station','stationTask.stationTaskMaterialBoxes']);
|
|
|
LogService::log(__METHOD__,'runMany','波次任务分配6.r2:'.json_encode($stationTaskBatch));
|
|
|
- $toLocation = $this->stationService->getULineEntrance($stationTaskBatch['station'])['code'];
|
|
|
- LogService::log(__METHOD__,'runMany','波次任务分配6.r3:'.json_encode($stationTaskBatch));
|
|
|
- $groupPrefix = $stationTaskBatch['id'];
|
|
|
+ $toLocation = $this->stationService->getULineEntrance($stationTaskBatch['station'])['code'];//获取放线入口
|
|
|
+ $groupPrefix = $stationTaskBatch['id'];//将波次任务ID当作组前缀
|
|
|
$taskMaterialBoxes = $stationTaskBatch['stationTask']['stationTaskMaterialBoxes'] ??
|
|
|
(function () use ($stationTaskBatch) {
|
|
|
LogService::log(__METHOD__,'runMany','波次任务分配6.r4:'.json_encode($stationTaskBatch));
|
|
|
throw new Exception('找不到料箱:' . json_encode($stationTaskBatch));
|
|
|
- })();
|
|
|
+ })();//存在任务返回任务 否则抛出无料箱异常
|
|
|
try{
|
|
|
- LogService::log(__METHOD__,'runMany','波次任务分配6.r5:'.json_encode($stationTaskBatch));
|
|
|
- $isFetchedFromRobotics
|
|
|
- = $this->foreignHaiRoboticsService->
|
|
|
- fetchGroup($toLocation, $taskMaterialBoxes, $groupPrefix);
|
|
|
+ $isFetchedFromRobotics = $this->foreignHaiRoboticsService->
|
|
|
+ fetchGroup($toLocation, $taskMaterialBoxes, $groupPrefix);//执行料箱任务
|
|
|
LogService::log(__METHOD__,'runMany','波次任务分配6.r6:'.json_encode($stationTaskBatch));
|
|
|
}catch(Exception $e){
|
|
|
throw new ErrorException('$stationTaskBatch运行波次机器人任务失败,获取组失败: '.$stationTaskBatch->toJson() . $e->getMessage());
|
|
|
}
|
|
|
- LogService::log(__METHOD__,'runMany','波次任务分配6.r7:'.json_encode($stationTaskBatch));
|
|
|
- ($markNewStatus
|
|
|
- =function()use($isFetchedFromRobotics,$stationTaskBatch){
|
|
|
+ (function()use($isFetchedFromRobotics,$stationTaskBatch){
|
|
|
$isFetchedFromRobotics?
|
|
|
- $this->markProcessing($stationTaskBatch):
|
|
|
- $this->markExcepted($stationTaskBatch);
|
|
|
- LogService::log(__METHOD__,'runMany','波次任务分配6.r8:'.json_encode($stationTaskBatch));
|
|
|
+ $this->markProcessing($stationTaskBatch)://执行成功标记已处理
|
|
|
+ $this->markExcepted($stationTaskBatch);//执行失败标记失败
|
|
|
})();
|
|
|
- LogService::log(__METHOD__,'runMany','波次任务分配6.r9:'.json_encode($stationTaskBatch));
|
|
|
- return $isFetchedFromRobotics;
|
|
|
+ return $isFetchedFromRobotics;//返回执行结果
|
|
|
}
|
|
|
|
|
|
function markProcessing($stationTaskBatch_orCollection)
|