Skip to content

Commit

Permalink
Merge pull request #720 from erikgaal/patch-dont-resume-recording-wit…
Browse files Browse the repository at this point in the history
…h-sync-jobs

Prevent resuming recording when processing sync job
  • Loading branch information
taylorotwell authored Sep 5, 2019
2 parents f9b0bb4 + df1e797 commit d65cf82
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/ListensForStorageOpportunities.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ protected static function storeEntriesBeforeTermination($app)
*/
protected static function storeEntriesAfterWorkerLoop($app)
{
$app['events']->listen(JobProcessing::class, function () {
static::startRecording();
$app['events']->listen(JobProcessing::class, function ($event) {
if ($event->connectionName !== 'sync') {
static::startRecording();

static::$processingJobs[] = true;
static::$processingJobs[] = true;
}
});

$app['events']->listen(JobProcessed::class, function ($event) use ($app) {
Expand Down
35 changes: 35 additions & 0 deletions tests/Telescope/TelescopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Laravel\Telescope\Tests\Telescope;

use Laravel\Telescope\Telescope;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Contracts\Queue\ShouldQueue;
use Laravel\Telescope\Tests\FeatureTestCase;
use Laravel\Telescope\Watchers\QueryWatcher;
use Laravel\Telescope\Contracts\EntriesRepository;
Expand Down Expand Up @@ -70,4 +72,37 @@ public function after_recording_callback_can_store_and_flush()

$this->assertCount(1, Telescope::$entriesQueue);
}

/**
* @test
*/
public function dont_start_recording_when_dispatching_job_synchronously()
{
Telescope::stopRecording();

$this->assertFalse(Telescope::isRecording());

$this->app->get(Dispatcher::class)->dispatch(
new MySyncJob('Awesome Laravel')
);

$this->assertFalse(Telescope::isRecording());
}
}

class MySyncJob implements ShouldQueue
{
public $connection = 'sync';

private $payload;

public function __construct($payload)
{
$this->payload = $payload;
}

public function handle()
{
//
}
}

0 comments on commit d65cf82

Please sign in to comment.