Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
7.69% |
1 / 13 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| QuotationsSync | |
7.69% |
1 / 13 |
|
50.00% |
1 / 2 |
16.58 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| handle | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Console\Commands; |
| 4 | |
| 5 | use App\Jobs\SyncG3WRegion; |
| 6 | use App\Services\PresupuestosService; |
| 7 | use Illuminate\Console\Command; |
| 8 | use Illuminate\Support\Facades\Log; |
| 9 | |
| 10 | class QuotationsSync extends Command |
| 11 | { |
| 12 | /** |
| 13 | * The name and signature of the console command. |
| 14 | * |
| 15 | * @var string |
| 16 | */ |
| 17 | protected $signature = 'quotations:sync {date?} {name?} {region?}'; |
| 18 | |
| 19 | /** |
| 20 | * The console command description. |
| 21 | * |
| 22 | * @var string |
| 23 | */ |
| 24 | protected $description = 'Synchronizes budgets for the specified date'; |
| 25 | |
| 26 | /** |
| 27 | * @var PresupuestosService |
| 28 | */ |
| 29 | protected $presupuestoService; |
| 30 | |
| 31 | /** |
| 32 | * Create a new command instance. |
| 33 | */ |
| 34 | public function __construct(private readonly PresupuestosService $presupuestosService) |
| 35 | { |
| 36 | parent::__construct(); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Execute the console command. |
| 41 | */ |
| 42 | public function handle(): int |
| 43 | { |
| 44 | $date = $this->argument('date') ?? date('Y-m-d'); |
| 45 | $name = $this->argument('name') ?? 'System'; |
| 46 | $regions = $this->argument('region') ? explode(',', $this->argument('region')) : ['Cataluña', 'Madrid', 'Comunidad Valenciana', 'AndalucĂa', 'Baleares']; |
| 47 | |
| 48 | $cronStart = microtime(true); |
| 49 | |
| 50 | // FIRE-1151: dispatch one job per region. |
| 51 | // - Under QUEUE_CONNECTION=sync (today), jobs run inline: same shape |
| 52 | // and timing as the old foreach. |
| 53 | // - Under QUEUE_CONNECTION=redis + a worker (after FIRE-1147 ops setup), |
| 54 | // jobs run in parallel on the 'g3w' queue. Per-region wall-time is |
| 55 | // still logged from inside the job (SyncG3WRegion::handle) so we |
| 56 | // can see each region's duration in either mode. |
| 57 | foreach ($regions as $region) { |
| 58 | SyncG3WRegion::dispatch($date, $name, $region)->onQueue('g3w'); |
| 59 | } |
| 60 | |
| 61 | Log::channel('g3w')->info('quotations:sync dispatched', [ |
| 62 | 'regions' => count($regions), |
| 63 | 'date' => $date, |
| 64 | 'dispatch_ms' => (int) round((microtime(true) - $cronStart) * 1000), |
| 65 | ]); |
| 66 | |
| 67 | return Command::SUCCESS; |
| 68 | } |
| 69 | } |