Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Sep 1, 2023
1 parent ffbfa27 commit 3d436e6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 45 deletions.
8 changes: 2 additions & 6 deletions src/PulseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
use Illuminate\Events\Dispatcher;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Queue\Events\JobExceptionOccurred;
use Illuminate\Queue\Events\JobFailed;
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Queue\Events\Looping;
use Illuminate\Queue\Events\WorkerStopping;
use Illuminate\Routing\Router;
use Illuminate\Support\ServiceProvider;
use Illuminate\View\Compilers\BladeCompiler;
Expand Down Expand Up @@ -122,9 +120,7 @@ protected function listenForEvents(): void
// TODO: consider moving this registration to the "Booted" event to ensure, for sure, that our stuff is registered last?
$event->listen([
Looping::class,
JobFailed::class,
JobProcessed::class,
JobExceptionOccurred::class,
WorkerStopping::class,
], function ($event) use ($app) {
$app[Pulse::class]->store($app[Ingest::class]);
});
Expand Down
1 change: 0 additions & 1 deletion tests/Feature/HttpRequestsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Illuminate\Support\Facades\Route;
use Laravel\Pulse\Facades\Pulse;
use Laravel\Pulse\Pulse as PulseInstance;

use function Pest\Laravel\actingAs;
use function Pest\Laravel\get;
use function Pest\Laravel\post;
Expand Down
54 changes: 16 additions & 38 deletions tests/Feature/JobsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Str;
use Laravel\Pulse\Contracts\Ingest;
use Laravel\Pulse\Entries\Entry;
use Laravel\Pulse\Facades\Pulse;

it('ingests bus dispatched jobs', function () {
Expand Down Expand Up @@ -80,7 +79,7 @@
'slow' => 0,
'slowest' => null,
]);
})->only();
});

it('handles a job throwing exceptions and failing', function () {
Config::set('queue.default', 'database');
Expand Down Expand Up @@ -111,7 +110,7 @@
*/

Carbon::setTestNow('2000-01-02 03:04:10');
Artisan::call('queue:work', ['--once' => true, '--stop-when-empty' => true]);
Artisan::call('queue:work', ['--max-jobs' => 1, '--stop-when-empty' => true]);
expect(Queue::size())->toBe(1);

$jobs = Pulse::ignore(fn () => DB::table('pulse_jobs')->get());
Expand All @@ -129,7 +128,7 @@
* Work the job for the second time.
*/

Artisan::call('queue:work', ['--once' => true, '--stop-when-empty' => true]);
Artisan::call('queue:work', ['--max-jobs' => 1, '--stop-when-empty' => true]);
expect(Queue::size())->toBe(1);

$jobs = Pulse::ignore(fn () => DB::table('pulse_jobs')->get());
Expand All @@ -147,7 +146,7 @@
* Work the job for the third time.
*/

Artisan::call('queue:work', ['--once' => true, '--stop-when-empty' => true]);
Artisan::call('queue:work', ['--max-jobs' => 1, '--stop-when-empty' => true]);
expect(Queue::size())->toBe(0);

$jobs = Pulse::ignore(fn () => DB::table('pulse_jobs')->get());
Expand All @@ -160,14 +159,7 @@
'slow' => 3,
'slowest' => 33,
]);

// // we expect there to be a single exception in the queue. This would
// // be stored on the next loop or while the command terminates.
expect(Pulse::entries())->toHaveCount(1);
expect(Pulse::entries()[0])->toBeInstanceOf(Entry::class);
expect(Pulse::entries()[0]->table)->toBe('pulse_exceptions');
Pulse::flushEntries();
})->only();
});

it('only remembers the slowest duration', function () {
Config::set('queue.default', 'database');
Expand Down Expand Up @@ -198,7 +190,7 @@
*/

Carbon::setTestNow('2000-01-02 03:04:10');
Artisan::call('queue:work', ['--once' => true, '--stop-when-empty' => true]);
Artisan::call('queue:work', ['--max-jobs' => 1, '--stop-when-empty' => true]);
expect(Queue::size())->toBe(1);

$jobs = Pulse::ignore(fn () => DB::table('pulse_jobs')->get());
Expand All @@ -216,7 +208,7 @@
* Work the job for the second time.
*/

Artisan::call('queue:work', ['--once' => true, '--stop-when-empty' => true]);
Artisan::call('queue:work', ['--max-jobs' => 1, '--stop-when-empty' => true]);
expect(Queue::size())->toBe(1);

$jobs = Pulse::ignore(fn () => DB::table('pulse_jobs')->get());
Expand All @@ -234,7 +226,7 @@
* Work the job for the third time.
*/

Artisan::call('queue:work', ['--once' => true, '--stop-when-empty' => true]);
Artisan::call('queue:work', ['--max-jobs' => 1, '--stop-when-empty' => true]);
expect(Queue::size())->toBe(0);

$jobs = Pulse::ignore(fn () => DB::table('pulse_jobs')->get());
Expand All @@ -247,14 +239,7 @@
'slow' => 3,
'slowest' => 99,
]);

// // we expect there to be a single exception in the queue. This would
// // be stored on the next loop or while the command terminates.
expect(Pulse::entries())->toHaveCount(1);
expect(Pulse::entries()[0])->toBeInstanceOf(Entry::class);
expect(Pulse::entries()[0]->table)->toBe('pulse_exceptions');
Pulse::flushEntries();
})->only();
});

it('handles a failure and then a successful job', function () {
Config::set('queue.default', 'database');
Expand Down Expand Up @@ -285,7 +270,7 @@
*/

Carbon::setTestNow('2000-01-02 03:04:10');
Artisan::call('queue:work', ['--once' => true, '--stop-when-empty' => true]);
Artisan::call('queue:work', ['--max-jobs' => 1, '--stop-when-empty' => true]);
expect(Queue::size())->toBe(1);

$jobs = Pulse::ignore(fn () => DB::table('pulse_jobs')->get());
Expand All @@ -303,7 +288,7 @@
* Work the job for the second time.
*/

Artisan::call('queue:work', ['--once' => true, '--stop-when-empty' => true]);
Artisan::call('queue:work', ['--max-jobs' => 1, '--stop-when-empty' => true]);
expect(Queue::size())->toBe(0);

$jobs = Pulse::ignore(fn () => DB::table('pulse_jobs')->get());
Expand All @@ -316,7 +301,7 @@
'slow' => 2,
'slowest' => 99,
]);
})->only();
});

it('handles a slow successful job', function () {
Config::set('queue.default', 'database');
Expand Down Expand Up @@ -347,7 +332,7 @@
*/

Carbon::setTestNow('2000-01-02 03:04:10');
Artisan::call('queue:work', ['--once' => true, '--stop-when-empty' => true]);
Artisan::call('queue:work', ['--max-jobs' => 1, '--stop-when-empty' => true]);
expect(Queue::size())->toBe(0);

$jobs = Pulse::ignore(fn () => DB::table('pulse_jobs')->get());
Expand All @@ -360,7 +345,7 @@
'slow' => 1,
'slowest' => 100,
]);
})->only();
});

it('handles a job that was manually failed', function () {
Config::set('queue.default', 'database');
Expand Down Expand Up @@ -391,7 +376,7 @@
*/

Carbon::setTestNow('2000-01-02 03:04:10');
Artisan::call('queue:work', ['--once' => true, '--stop-when-empty' => true]);
Artisan::call('queue:work', ['--max-jobs' => 1, '--stop-when-empty' => true]);
expect(Queue::size())->toBe(0);

$jobs = Pulse::ignore(fn () => DB::table('pulse_jobs')->get());
Expand All @@ -404,14 +389,7 @@
'slow' => 1,
'slowest' => 100,
]);

// // we expect there to be a single exception in the queue. This would
// // be stored on the next loop or while the command terminates.
expect(Pulse::entries())->toHaveCount(1);
expect(Pulse::entries()[0])->toBeInstanceOf(Entry::class);
expect(Pulse::entries()[0]->table)->toBe('pulse_exceptions');
Pulse::flushEntries();
})->todo();
});

class MyJob implements ShouldQueue
{
Expand Down

0 comments on commit 3d436e6

Please sign in to comment.