Skip to content

Commit

Permalink
Fill out jobResult more when total fallback happens (#4)
Browse files Browse the repository at this point in the history
* response contains an array of JobResults

* include uuid as id in fallback html

* fill out jobResult with more fields when fallback happens
  • Loading branch information
roippi authored Jan 21, 2017
1 parent f5f3a88 commit bb97068
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/JobResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ class JobResult
*/
public $originalJob;

/**
* @var array
*/
public $meta;

/**
* @var float
*/
public $duration;

/**
* @param $serverResult
* @param \WF\Hypernova\Job $originalJob
Expand All @@ -47,6 +57,8 @@ public static function fromServerResult($serverResult, \WF\Hypernova\Job $origin
$res->error = $serverResult['error'];
$res->html = $serverResult['html'];
$res->success = $serverResult['success'];
$res->meta = isset($serverResult['meta']) ? $serverResult['meta'] : [];
$res->duration = isset($serverResult['duration']) ? $serverResult['duration'] : null;
$res->originalJob = $originalJob;

return $res;
Expand Down
8 changes: 6 additions & 2 deletions src/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ protected function fallback($topLevelError, $jobs)
$result->error = $topLevelError;
$result->results = array_map(function (\WF\Hypernova\Job $job) {
$jobResult = new JobResult();
$jobResult->html = $this->getFallbackHTML($job->name, $job->data);
$uuid = \Ramsey\Uuid\Uuid::uuid4();
$jobResult->html = $this->getFallbackHTML($job->name, $job->data, $uuid);
$jobResult->meta = ['uuid' => (string) $uuid];
$jobResult->originalJob = $job;

return $jobResult;
}, $jobs);
Expand All @@ -209,10 +212,11 @@ protected function fallback($topLevelError, $jobs)
/**
* @param string $moduleName
* @param array $data
* @param \Ramsey\Uuid\UuidInterface $uuid
*
* @return string
*/
protected function getFallbackHTML($moduleName, $data)
protected function getFallbackHTML($moduleName, $data, $uuid)
{
$uuid = \Ramsey\Uuid\Uuid::uuid4();
return sprintf(
Expand Down

0 comments on commit bb97068

Please sign in to comment.