Skip to content

Commit

Permalink
RmqException
Browse files Browse the repository at this point in the history
  • Loading branch information
medilies committed Aug 25, 2024
1 parent 675f2d5 commit 3361373
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function up(): void
->comment(RmqFile::STAGED.': staged, '.RmqFile::DELETED.': deleted, '.RmqFile::FAILED.': failed');

// ? Failure message column
// ? retries

/* ULID */
$table->string('instance', 36);
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/RmqStatsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ class RmqStatsCommand extends Command
public function handle(): int
{
/** @var array<array{Status: string, Count: int}> */
$rows = RmqFile::select('status', DB::raw('COUNT(*) as total')) // @phpstan-ignore-line
$rows = RmqFile::select('status', DB::raw('COUNT(*) as count')) // @phpstan-ignore-line
->groupBy('status')
->get()
->map(fn (RmqFile $row) => [
'Status' => $this->getStatusLabel($row->status),
'Count' => $row->total, // @phpstan-ignore-line
'Count' => $row->count, // @phpstan-ignore-line
])
->toArray();

$this->table(['Status', 'Count'], [
...$rows,
[
'Status' => 'total',
'Status' => 'Total',
'Count' => array_sum(array_column($rows, 'Count')),
],
]);
Expand Down
7 changes: 7 additions & 0 deletions src/Exceptions/RmqException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Medilies\RmQ\Facades;

use Exception;

class RmqException extends Exception {}
7 changes: 4 additions & 3 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Medilies\RmQ\Facades\RmqException;
use Tests\OrchestraTestCase;

uses(OrchestraTestCase::class)->in(__DIR__.'/laravel');
Expand All @@ -11,12 +12,12 @@ function populateFiles(int $count = 1): array
$tempDir = sys_get_temp_dir().DIRECTORY_SEPARATOR.'rm_q';

if (! file_exists($tempDir)) {
mkdir($tempDir) ?: throw new Exception('Could not create dir: '.$tempDir);
mkdir($tempDir) ?: throw new RmqException('Could not create dir: '.$tempDir);
}

for ($i = 0; $i < $count; $i++) {
$file = tempnam($tempDir, 'rm_q_') ?: throw new Exception('Failed on tempnam');
file_put_contents($file, 'foo') ?: throw new Exception('Could not create file: '.$file);
$file = tempnam($tempDir, 'rm_q_') ?: throw new RmqException('Failed on tempnam');
file_put_contents($file, 'foo') ?: throw new RmqException('Could not create file: '.$file);
$files[] = $file;
}

Expand Down
3 changes: 2 additions & 1 deletion tests/laravel/FacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
use Medilies\RmQ\Facades\RmQ;
use Medilies\RmQ\Facades\RmqException;
use Medilies\RmQ\Models\RmqFile;
use Tests\OrchestraTestCase;

Expand Down Expand Up @@ -115,7 +116,7 @@
DB::transaction(function () use ($files) {
RmQ::stage($files);

throw new Exception('foo');
throw new RmqException('foo');
});
} catch (Throwable) {
}
Expand Down

0 comments on commit 3361373

Please sign in to comment.