Skip to content

Commit

Permalink
Merge pull request #477 from driesvints/fix-decimal-point
Browse files Browse the repository at this point in the history
[2.0] Fix storing floats in Redis
  • Loading branch information
taylorotwell authored Jan 28, 2019
2 parents 634771d + 01bed43 commit 64d5f32
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/JobPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function prepare($job)
return $this->set([
'type' => $this->determineType($job),
'tags' => $this->determineTags($job),
'pushedAt' => microtime(true),
'pushedAt' => str_replace(',', '.', microtime(true)),
]);
}

Expand Down
14 changes: 7 additions & 7 deletions src/Repositories/RedisJobRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function pushed($connection, $queue, JobPayload $payload)
$this->connection()->pipeline(function ($pipe) use ($connection, $queue, $payload) {
$this->storeJobReferences($pipe, $payload->id());

$time = microtime(true);
$time = str_replace(',', '.', microtime(true));

$pipe->hmset(
$payload->id(), [
Expand Down Expand Up @@ -261,7 +261,7 @@ protected function storeJobReferences($pipe, $id)
*/
public function reserved($connection, $queue, JobPayload $payload)
{
$time = microtime(true);
$time = str_replace(',', '.', microtime(true));

$this->connection()->hmset(
$payload->id(), [
Expand All @@ -287,7 +287,7 @@ public function released($connection, $queue, JobPayload $payload)
$payload->id(), [
'status' => 'pending',
'payload' => $payload->value,
'updated_at' => microtime(true),
'updated_at' => str_replace(',', '.', microtime(true)),
]
);
}
Expand All @@ -311,7 +311,7 @@ public function remember($connection, $queue, JobPayload $payload)
'name' => $payload->decoded['displayName'],
'status' => 'completed',
'payload' => $payload->value,
'completed_at' => microtime(true),
'completed_at' => str_replace(',', '.', microtime(true)),
]
);

Expand All @@ -335,7 +335,7 @@ public function migrated($connection, $queue, Collection $payloads)
$payload->id(), [
'status' => 'pending',
'payload' => $payload->value,
'updated_at' => microtime(true),
'updated_at' => str_replace(',', '.', microtime(true)),
]
);
}
Expand Down Expand Up @@ -372,7 +372,7 @@ protected function markJobAsCompleted($pipe, $id, $failed)
{
$failed
? $pipe->hmset($id, ['status' => 'failed'])
: $pipe->hmset($id, ['status' => 'completed', 'completed_at' => microtime(true)]);
: $pipe->hmset($id, ['status' => 'completed', 'completed_at' => str_replace(',', '.', microtime(true))]);

$pipe->expireat($id, Chronos::now()->addMinutes($this->recentJobExpires)->getTimestamp());
}
Expand Down Expand Up @@ -501,7 +501,7 @@ public function failed($exception, $connection, $queue, JobPayload $payload)
'status' => 'failed',
'payload' => $payload->value,
'exception' => (string) $exception,
'failed_at' => microtime(true),
'failed_at' => str_replace(',', '.', microtime(true)),
]
);

Expand Down
15 changes: 15 additions & 0 deletions tests/Feature/RedisJobRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,19 @@ public function test_it_will_not_find_a_failed_job_if_the_job_has_not_failed()

$this->assertNull($repository->findFailed(1));
}

public function test_it_saves_microseconds_as_a_float_and_disregards_the_locale()
{
setlocale(LC_NUMERIC, 'fr_FR');

$repository = $this->app->make(JobRepository::class);
$payload = new JobPayload(json_encode(['id' => 1, 'displayName' => 'foo']));

$repository->pushed('redis', 'default', $payload);
$repository->reserved('redis', 'default', $payload);

$result = $repository->getRecent()[0];

$this->assertNotContains(',', $result->reserved_at);
}
}

0 comments on commit 64d5f32

Please sign in to comment.