Skip to content

Commit

Permalink
fix job as segment
Browse files Browse the repository at this point in the history
  • Loading branch information
ilvalerione committed Aug 1, 2019
1 parent c67f598 commit ea27390
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/Providers/JobServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,15 @@ public function boot()
});

$this->app['events']->listen(JobProcessing::class, function (JobProcessing $event) {
// Start a transaction id there's not one
// todo: add "&& Filters::isApprovedJob($event->job)"

// Start a transaction id there's not one
if(!$this->app['inspector']->isRecording()){
$this->app['inspector']->startTransaction($event->job->resolveName());
} else {
// Open a segment if a transaction already exists
$this->initializeSegment($event->job);
}

$segment = $this->app['inspector']
->startSegment('job')
->setLabel($event->job->resolveName())
->setContext($event->job->payload());

// Jot down the job with a unique ID
$this->segments[$this->getJobId($event->job)] = $segment;
});

$this->app['events']->listen(JobProcessed::class, function (JobProcessed $event) {
Expand All @@ -61,6 +57,17 @@ public function boot()
});
}

protected function initializeSegment(Job $job)
{
$segment = $this->app['inspector']
->startSegment('job')
->setLabel($job->resolveName())
->setContext($job->payload());

// Jot down the job with a unique ID
$this->segments[$this->getJobId($job)] = $segment;
}

/**
* Report job execution to Inspector.
*
Expand Down

0 comments on commit ea27390

Please sign in to comment.