8000 Remove millisecond precision from client job model · sablesoft/laravel-json-api@22bbefd · GitHub
[go: up one dir, main page]

Skip to content

Commit 22bbefd

Browse files
committed
Remove millisecond precision from client job model
This causes too many problems with Postgres so it is probably best at this point to stick to the Laravel default rather than doing something custom in this package.
1 parent cf894ec commit 22bbefd

File tree

6 files changed

+24
-30
lines changed

6 files changed

+24
-30
lines changed

database/migrations/2018_10_23_000001_create_client_jobs_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function up()
1616
{
1717
Schema::create('json_api_client_jobs', function (Blueprint $table) {
1818
$table->uuid('uuid')->primary();
19-
$table->timestamps(6);
19+
$table->timestamps();
2020
$table->string('api');
2121
$table->string('resource_type');
2222
$table->string('resource_id')->nullable();

src/Queue/ClientJob.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ class ClientJob extends Model implements AsynchronousProcess
7373
'timeout_at',
7474
];
7575

76-
/**
77-
* @var string
78-
*/
79-
protected $dateFormat = 'Y-m-d H:i:s.u';
80-
8176
/**
8277
* @inheritdoc
8378
*/

src/Queue/ClientJobSchema.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace CloudCreativity\LaravelJsonApi\Queue;
44

5-
use Carbon\Carbon;
5+
use DateTime;
66
use Neomerx\JsonApi\Schema\SchemaProvider;
77

88
class ClientJobSchema extends SchemaProvider
@@ -16,7 +16,7 @@ class ClientJobSchema extends SchemaProvider
1616
/**
1717
* @var string
1818
*/
19-
protected $dateFormat = 'Y-m-d\TH:i:s.uP';
19+
protected $dateFormat = DateTime::ATOM;
2020

2121
/**
2222
* @param ClientJob $resource
@@ -33,9 +33,9 @@ public function getId($resource)
3333
*/
3434
public function getAttributes($resource)
3535
{
36-
/** @var Carbon|null $completedAt */
36+
/** @var DateTime|null $completedAt */
3737
$completedAt = $resource->completed_at;
38-
/** @var Carbon|null $timeoutAt */
38+
/** @var DateTime|null $timeoutAt */
3939
$timeoutAt = $resource->timeout_at;
4040

4141
return [

tests/lib/Integration/Queue/ClientDispatchTest.php< 8000 /code>

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected function setUp()
4040
{
4141
parent::setUp();
4242
Queue::fake();
43-
Carbon::setTestNow('2018-10-23 12:00:00.123456');
43+
Carbon::setTestNow('2018-10-23 12:00:00');
4444
}
4545

4646
public function testCreate()
@@ -56,14 +56,14 @@ public function testCreate()
5656
'type' => 'queue-jobs',
5757
'attributes' => [
5858
'attempts' => 0,
59-
'created-at' => Carbon::now()->format('Y-m-d\TH:i:s.uP'),
59+
'created-at' => Carbon::now()->toAtomString(),
6060
'completed-at' => null,
6161
'failed' => false,
6262
'resource-type' => 'downloads',
6363
'timeout' => 60,
6464
'timeout-at' => null,
6565
'tries' => null,
66-
'updated-at' => Carbon::now()->format('Y-m-d\TH:i:s.uP'),
66+
'updated-at' => Carbon::now()->toAtomString(),
6767
],
6868
];
6969

@@ -81,8 +81,8 @@ public function testCreate()
8181

8282
$this->assertDatabaseHas('json_api_client_jobs', [
8383
'uuid' => $id,
84-
'created_at' => '2018-10-23 12:00:00.123456',
85-
'updated_at' => '2018-10-23 12:00:00.123456',
84+
'created_at' => '2018-10-23 12:00:00',
85+
'updated_at' => '2018-10-23 12:00:00',
8686
'api' => 'v1',
8787
'resource_type' => 'downloads',
8888
'resource_id' => null,
@@ -126,8 +126,8 @@ public function testCreateWithClientGeneratedId()
126126

127127
$this->assertDatabaseHas('json_api_client_jobs', [
128128
'uuid' => $job->clientJob->getKey(),
129-
'created_at' => '2018-10-23 12:00:00.123456',
130-
'updated_at' => '2018-10-23 12:00:00.123456',
129+
'created_at' => '2018-10-23 12:00:00',
130+
'updated_at' => '2018-10-23 12:00:00',
131131
'api' => 'v1',
132132
'resource_type' => 'downloads',
133133
'resource_id' => $data['id'],
@@ -154,7 +154,7 @@ public function testUpdate()
154154
'attributes' => [
155155
'resource-type' => 'downloads',
156156
'timeout' => null,
157-
'timeout-at' => Carbon::now()->addSeconds(25)->format('Y-m-d\TH:i:s.uP'),
157+
'timeout-at' => Carbon::now()->addSeconds(25)->toAtomString(),
158158
'tries' => null,
159159
],
160160
];
@@ -168,13 +168,13 @@ public function testUpdate()
168168

169169
$this->assertDatabaseHas('json_api_client_jobs', [
170170
'uuid' => $job->clientJob->getKey(),
171-
'created_at' => '2018-10-23 12:00:00.123456',
172-
'updated_at' => '2018-10-23 12:00:00.123456',
171+
'created_at' => '2018-10-23 12:00:00',
172+
'updated_at' => '2018-10-23 12:00:00',
173173
'api' => 'v1',
174174
'resource_type' => 'downloads',
175175
'resource_id' => $download->getRouteKey(),
176176
'timeout' => null,
177-
'timeout_at' => '2018-10-23 12:00:25.123456',
177+
'timeout_at' => '2018-10-23 12:00:25',
178178
'tries' => null,
179179
]);
180180
}
@@ -197,8 +197,8 @@ public function testDelete()
197197

198198
$this->assertDatabaseHas('json_api_client_jobs', [
199199
'uuid' => $job->clientJob->getKey(),
200-
'created_at' => '2018-10-23 12:00:00.123456',
201-
'updated_at' => '2018-10-23 12:00:00.123456',
200+
'created_at' => '2018-10-23 12:00:00',
201+
'updated_at' => '2018-10-23 12:00:00',
202202
'api' => 'v1',
203203
'resource_type' => 'downloads',
204204
'resource_id' => $download->getRouteKey(),

tests/lib/Integration/Queue/QueueEventsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testCompletes()
2828
$this->assertDatabaseHas('json_api_client_jobs', [
2929
'uuid' => $job->clientJob->getKey(),
3030
'attempts' => 1,
31-
'completed_at' => Carbon::now()->format('Y-m-d H:i:s.u'),
31+
'completed_at' => Carbon::now()->format('Y-m-d H:i:s'),
3232
'failed' => false,
3333
]);
3434
}
@@ -49,7 +49,7 @@ public function testFails()
4949
$this->assertDatabaseHas('json_api_client_jobs', [
5050
'uuid' => $job->clientJob->getKey(),
5151
'attempts' => 1,
52-
'completed_at' => Carbon::now()->format('Y-m-d H:i:s.u'),
52+
'completed_at' => Carbon::now()->format('Y-m-d H:i:s'),
5353
'failed' => true,
5454
]);
5555
}

tests/lib/Integration/Queue/QueueJobsTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,20 @@ private function jobUrl(ClientJob $job, string $resourceType = null): string
9191
private function serialize(ClientJob $job): array
9292
{
9393
$self = $this->jobUrl($job);
94-
$format = 'Y-m-d\TH:i:s.uP';
9594

9695
return [
9796
'type' => 'queue-jobs',
9897
'id' => (string) $job->getRouteKey(),
9998
'attributes' => [
10099
'attempts' => $job->attempts,
101-
'created-at' => $job->created_at->format($format),
102-
'completed-at' => $job->completed_at ? $job->completed_at->format($format) : null,
100+
'created-at' => $job->created_at->toAtomString(),
101+
'completed-at' => $job->completed_at ? $job->completed_at->toAtomString() : null,
103102
'failed' => $job->failed,
104103
'resource-type' => 'downloads',
105104
'timeout' => $job->timeout,
106-
'timeout-at' => $job->timeout_at ? $job->timeout_at->format($format) : null,
105+
'timeout-at' => $job->timeout_at ? $job->timeout_at->toAtomString() : null,
107106
'tries' => $job->tries,
108-
'updated-at' => $job->updated_at->format($format),
107+
'updated-at' => $job->updated_at->toAtomString(),
109108
],
110109
'links' => [
111110
'self' => $self,

0 commit comments

Comments
 (0)
0