Skip to content

Commit ab360f8

Browse files
authored
Merge pull request #3438 from codeeu/dev
Dev
2 parents a680e53 + 7dca567 commit ab360f8

2 files changed

Lines changed: 31 additions & 28 deletions

File tree

app/Console/Commands/CertificateGenerateWindow.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ class CertificateGenerateWindow extends Command
1111
protected $signature = 'certificate:generate-window
1212
{--edition=2025 : Target edition year}
1313
{--type=all : excellence|super-organiser|all}
14-
{--limit=500 : Max recipients to process per type in this run}
15-
{--include-failed : Include rows with previous generation errors}';
14+
{--limit=500 : Max recipients to process per type per batch}
15+
{--include-failed : Include rows with previous generation errors}
16+
{--once : Run only one batch per type then stop (default: run until no pending left)}';
1617

17-
protected $description = 'Generate certificates in controlled windows (e.g. 500 at a time); use --type=all for both certs';
18+
protected $description = 'Generate certificates in batches; runs until no pending left (use --once for single batch)';
1819

1920
public function handle(): int
2021
{
2122
$edition = (int) $this->option('edition');
2223
$limit = max(1, (int) $this->option('limit'));
2324
$includeFailed = (bool) $this->option('include-failed');
25+
$once = (bool) $this->option('once');
2426
$typeInput = strtolower(trim((string) $this->option('type')));
2527
$types = $this->resolveTypes($typeInput);
2628
if ($types === null) {
@@ -30,22 +32,21 @@ public function handle(): int
3032

3133
$totalOk = 0;
3234
$totalFailed = 0;
33-
$any = false;
35+
$batchCount = 0;
3436

3537
foreach ($types as $type) {
36-
$result = $this->generateWindowForType($edition, $type, $limit, $includeFailed);
37-
$totalOk += $result['ok'];
38-
$totalFailed += $result['failed'];
39-
if ($result['processed'] > 0) {
40-
$any = true;
41-
}
38+
do {
39+
$result = $this->generateWindowForType($edition, $type, $limit, $includeFailed);
40+
$totalOk += $result['ok'];
41+
$totalFailed += $result['failed'];
42+
if ($result['processed'] > 0) {
43+
$batchCount++;
44+
}
45+
} while (! $once && $result['processed'] > 0);
4246
}
4347

4448
$this->newLine();
45-
$this->info("Generate window(s) complete. Total success: {$totalOk}, Total failed: {$totalFailed}.");
46-
if ($any) {
47-
$this->line('Run the same command again to process the next batch.');
48-
}
49+
$this->info("Generate complete. Batches: {$batchCount}, Total success: {$totalOk}, Total failed: {$totalFailed}.");
4950
return self::SUCCESS;
5051
}
5152

app/Console/Commands/CertificateSendWindow.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@ class CertificateSendWindow extends Command
1414
protected $signature = 'certificate:send-window
1515
{--edition=2025 : Target edition year}
1616
{--type=all : excellence|super-organiser|all}
17-
{--limit=500 : Max recipients to send per type in this run}
18-
{--include-send-failed : Include rows that previously failed sending}';
17+
{--limit=500 : Max recipients to send per type per batch}
18+
{--include-send-failed : Include rows that previously failed sending}
19+
{--once : Run only one batch per type then stop (default: run until no recipients left)}';
1920

20-
protected $description = 'Send certificate emails in controlled windows (e.g. 500 at a time); use --type=all for both certs';
21+
protected $description = 'Send certificate emails in batches; runs until no recipients left (use --once for single batch)';
2122

2223
public function handle(): int
2324
{
2425
$edition = (int) $this->option('edition');
2526
$limit = max(1, (int) $this->option('limit'));
2627
$includeSendFailed = (bool) $this->option('include-send-failed');
28+
$once = (bool) $this->option('once');
2729
$typeInput = strtolower(trim((string) $this->option('type')));
2830
$types = $this->resolveTypes($typeInput);
2931
if ($types === null) {
@@ -33,22 +35,22 @@ public function handle(): int
3335

3436
$totalQueued = 0;
3537
$totalFailed = 0;
36-
$any = false;
38+
$batchCount = 0;
3739

3840
foreach ($types as $type) {
39-
$result = $this->sendWindowForType($edition, $type, $limit, $includeSendFailed);
40-
$totalQueued += $result['queued'];
41-
$totalFailed += $result['failed'];
42-
if ($result['processed'] > 0) {
43-
$any = true;
44-
}
41+
do {
42+
$result = $this->sendWindowForType($edition, $type, $limit, $includeSendFailed);
43+
$totalQueued += $result['queued'];
44+
$totalFailed += $result['failed'];
45+
if ($result['processed'] > 0) {
46+
$batchCount++;
47+
}
48+
} while (! $once && $result['processed'] > 0);
4549
}
4650

4751
$this->newLine();
48-
$this->info("Send window(s) complete. Total queued: {$totalQueued}, Total failed: {$totalFailed}.");
49-
if ($any) {
50-
$this->line('Run the same command again to process the next batch (or ensure queue worker is running: php artisan queue:work).');
51-
}
52+
$this->info("Send complete. Batches: {$batchCount}, Total queued: {$totalQueued}, Total failed: {$totalFailed}.");
53+
$this->line('Ensure queue worker is running to deliver: php artisan queue:work');
5254
return self::SUCCESS;
5355
}
5456

0 commit comments

Comments
 (0)