Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent resuming recording when processing sync job #720

Merged
merged 2 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
{
//
}
}