commit21
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\ReplenishmentHeartbeat;
|
||||
use App\Services\ReplenishmentProcessLock;
|
||||
use App\Services\ReplenishmentQueue;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
@@ -24,10 +26,30 @@ class ReplenishmentTick extends Command
|
||||
|
||||
return self::INVALID;
|
||||
}
|
||||
$queue->discover();
|
||||
$result = $queue->drain((int) $limit);
|
||||
$this->info('Reposição: '.$result['processed'].' trabalhos conferidos; '.$result['failed'].' a recuperar.');
|
||||
$started = now()->toIso8601String();
|
||||
$exitCode = self::FAILURE;
|
||||
$lock = app(ReplenishmentProcessLock::class);
|
||||
if (! $lock->acquire()) {
|
||||
$this->info('Verificação periódica já em execução; aguarde a próxima passagem.');
|
||||
|
||||
return $result['failed'] === 0 ? self::SUCCESS : self::FAILURE;
|
||||
return self::FAILURE;
|
||||
}
|
||||
try {
|
||||
$queue->discover();
|
||||
$result = $queue->drain((int) $limit);
|
||||
$this->info('Reposição: '.$result['processed'].' trabalhos conferidos; '.$result['failed'].' a recuperar.');
|
||||
$exitCode = $result['failed'] === 0 ? self::SUCCESS : self::FAILURE;
|
||||
|
||||
return $exitCode;
|
||||
} finally {
|
||||
try {
|
||||
app(ReplenishmentHeartbeat::class)->record($started, $exitCode);
|
||||
} catch (\Throwable $error) {
|
||||
report($error);
|
||||
$this->warn('Não foi possível actualizar o acompanhamento técnico desta execução.');
|
||||
} finally {
|
||||
$lock->release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user