Skip to content

Commit 6c4ef01

Browse files
authored
Merge pull request #12 from keboola/papa_PS-3184_jobSuccess
PS-2184 Job success notification
2 parents 2e8e938 + 900dc0d commit 6c4ef01

7 files changed

Lines changed: 284 additions & 2 deletions
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Keboola\NotificationClient\Requests\PostEvent;
6+
7+
use Keboola\NotificationClient\Requests\EventDataInterface;
8+
9+
class JobSucceededEventData implements EventDataInterface
10+
{
11+
private string $projectId;
12+
private string $projectName;
13+
private JobData $jobData;
14+
15+
public function __construct(string $projectId, string $projectName, JobData $jobData)
16+
{
17+
$this->projectId = $projectId;
18+
$this->projectName = $projectName;
19+
$this->jobData = $jobData;
20+
}
21+
22+
public function jsonSerialize(): array
23+
{
24+
return [
25+
'job' => $this->jobData->jsonSerialize(),
26+
'project' => [
27+
'id' => $this->projectId,
28+
'name' => $this->projectName,
29+
],
30+
];
31+
}
32+
33+
public static function getEventTypeName(): string
34+
{
35+
return 'job-succeeded';
36+
}
37+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Keboola\NotificationClient\Requests\PostEvent;
6+
7+
use Keboola\NotificationClient\Requests\EventDataInterface;
8+
9+
class PhaseJobSucceededEventData implements EventDataInterface
10+
{
11+
private string $projectId;
12+
private string $projectName;
13+
private JobData $jobData;
14+
private string $phaseName;
15+
private string $phaseId;
16+
17+
public function __construct(
18+
string $projectId,
19+
string $projectName,
20+
string $phaseName,
21+
string $phaseId,
22+
JobData $jobData
23+
) {
24+
$this->projectId = $projectId;
25+
$this->projectName = $projectName;
26+
$this->jobData = $jobData;
27+
$this->phaseName = $phaseName;
28+
$this->phaseId = $phaseId;
29+
}
30+
31+
public function jsonSerialize(): array
32+
{
33+
return [
34+
'job' => $this->jobData->jsonSerialize(),
35+
'phase' => [
36+
'id' => $this->phaseId,
37+
'name' => $this->phaseName,
38+
],
39+
'project' => [
40+
'id' => $this->projectId,
41+
'name' => $this->projectName,
42+
],
43+
];
44+
}
45+
46+
public static function getEventTypeName(): string
47+
{
48+
return 'phase-job-succeeded';
49+
}
50+
}

src/Requests/Subscription.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
use Keboola\NotificationClient\Exception\ClientException;
1010
use Keboola\NotificationClient\Requests\PostEvent\JobFailedEventData;
1111
use Keboola\NotificationClient\Requests\PostEvent\JobProcessingLongEventData;
12+
use Keboola\NotificationClient\Requests\PostEvent\JobSucceededEventData;
1213
use Keboola\NotificationClient\Requests\PostEvent\JobSucceededWithWarningEventData;
1314
use Keboola\NotificationClient\Requests\PostEvent\PhaseJobFailedEventData;
1415
use Keboola\NotificationClient\Requests\PostEvent\PhaseJobProcessingLongEventData;
16+
use Keboola\NotificationClient\Requests\PostEvent\PhaseJobSucceededEventData;
1517
use Keboola\NotificationClient\Requests\PostEvent\PhaseJobSucceededWithWarningEventData;
1618
use Keboola\NotificationClient\Requests\PostSubscription\EmailRecipient;
1719
use Keboola\NotificationClient\Requests\PostSubscription\Filter;
@@ -57,9 +59,11 @@ private function checkEventType(string $eventType): void
5759
{
5860
$validEventTypes = [
5961
JobFailedEventData::getEventTypeName(),
62+
JobSucceededEventData::getEventTypeName(),
6063
JobSucceededWithWarningEventData::getEventTypeName(),
6164
JobProcessingLongEventData::getEventTypeName(),
6265
PhaseJobFailedEventData::getEventTypeName(),
66+
PhaseJobSucceededEventData::getEventTypeName(),
6367
PhaseJobSucceededWithWarningEventData::getEventTypeName(),
6468
PhaseJobProcessingLongEventData::getEventTypeName(),
6569
];
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Keboola\NotificationClient\Tests\Requests\PostEvent;
6+
7+
use DateTimeImmutable;
8+
use Keboola\NotificationClient\Requests\PostEvent\JobData;
9+
use Keboola\NotificationClient\Requests\PostEvent\JobSucceededEventData;
10+
use PHPUnit\Framework\TestCase;
11+
12+
class JobSucceededEventDataTest extends TestCase
13+
{
14+
public function testJsonSerialize(): void
15+
{
16+
$jobData = new JobData(
17+
'23456',
18+
'http://someUrl',
19+
new DateTimeImmutable('2020-01-01T11:11:00+00:00'),
20+
new DateTimeImmutable('2020-01-01T12:11:00+00:00'),
21+
'keboola.orchestrator',
22+
'Orchestrator',
23+
'my-configuration',
24+
'My configuration'
25+
);
26+
$failedEventData = new JobSucceededEventData(
27+
'1234',
28+
'My project',
29+
$jobData
30+
);
31+
32+
self::assertSame(
33+
[
34+
'job' => [
35+
'id' => '23456',
36+
'url' => 'http://someUrl',
37+
'component' => [
38+
'id' => 'keboola.orchestrator',
39+
'name' => 'Orchestrator',
40+
],
41+
'tasks' => [],
42+
'startTime' => '2020-01-01T11:11:00+00:00',
43+
'endTime' => '2020-01-01T12:11:00+00:00',
44+
'configuration' => [
45+
'id' => 'my-configuration',
46+
'name' => 'My configuration',
47+
],
48+
],
49+
'project' => [
50+
'id' => '1234',
51+
'name' => 'My project',
52+
],
53+
],
54+
$failedEventData->jsonSerialize()
55+
);
56+
}
57+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Keboola\NotificationClient\Tests\Requests\PostEvent;
6+
7+
use DateTimeImmutable;
8+
use Keboola\NotificationClient\Requests\PostEvent\JobData;
9+
use Keboola\NotificationClient\Requests\PostEvent\PhaseJobSucceededEventData;
10+
use PHPUnit\Framework\TestCase;
11+
12+
class PhaseJobSucceededEventDataTest extends TestCase
13+
{
14+
public function testJsonSerialize(): void
15+
{
16+
$jobData = new JobData(
17+
'23456',
18+
'http://someUrl',
19+
new DateTimeImmutable('2020-01-01T11:11:00+00:00'),
20+
new DateTimeImmutable('2020-01-01T12:11:00+00:00'),
21+
'keboola.orchestrator',
22+
'Orchestrator',
23+
'my-configuration',
24+
'My configuration'
25+
);
26+
$failedEventData = new PhaseJobSucceededEventData(
27+
'1234',
28+
'My project',
29+
'Lithium Extractors',
30+
'123',
31+
$jobData
32+
);
33+
34+
self::assertSame(
35+
[
36+
'job' => [
37+
'id' => '23456',
38+
'url' => 'http://someUrl',
39+
'component' => [
40+
'id' => 'keboola.orchestrator',
41+
'name' => 'Orchestrator',
42+
],
43+
'tasks' => [],
44+
'startTime' => '2020-01-01T11:11:00+00:00',
45+
'endTime' => '2020-01-01T12:11:00+00:00',
46+
'configuration' => [
47+
'id' => 'my-configuration',
48+
'name' => 'My configuration',
49+
],
50+
],
51+
'phase' => [
52+
'id' => '123',
53+
'name' => 'Lithium Extractors',
54+
],
55+
'project' => [
56+
'id' => '1234',
57+
'name' => 'My project',
58+
],
59+
],
60+
$failedEventData->jsonSerialize()
61+
);
62+
}
63+
}

tests/Requests/SubscriptionTest.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,77 @@ public function testPhaseJobSucceededWithWarningSubscription(): void
139139
);
140140
}
141141

142+
public function testJobSucceededSubscription(): void
143+
{
144+
$subscriptionRequest = new Subscription(
145+
'job-succeeded',
146+
new EmailRecipient('john.doe@example.com'),
147+
[
148+
new Filter('job.component.id', 'my.component'),
149+
new Filter('job.configuration.id', '12345'),
150+
]
151+
);
152+
153+
self::assertSame(
154+
[
155+
'event' => 'job-succeeded',
156+
'filters' => [
157+
[
158+
'field' => 'job.component.id',
159+
'value' => 'my.component',
160+
],
161+
[
162+
'field' => 'job.configuration.id',
163+
'value' => '12345',
164+
],
165+
],
166+
'recipient' => [
167+
'channel' => 'email',
168+
'address' => 'john.doe@example.com',
169+
],
170+
],
171+
$subscriptionRequest->jsonSerialize()
172+
);
173+
}
174+
175+
public function testPhaseJobSucceededSubscription(): void
176+
{
177+
$subscriptionRequest = new Subscription(
178+
'phase-job-succeeded',
179+
new EmailRecipient('john.doe@example.com'),
180+
[
181+
new Filter('job.component.id', 'my.component'),
182+
new Filter('job.configuration.id', '12345'),
183+
new Filter('phase.id', '123'),
184+
]
185+
);
186+
187+
self::assertSame(
188+
[
189+
'event' => 'phase-job-succeeded',
190+
'filters' => [
191+
[
192+
'field' => 'job.component.id',
193+
'value' => 'my.component',
194+
],
195+
[
196+
'field' => 'job.configuration.id',
197+
'value' => '12345',
198+
],
199+
[
200+
'field' => 'phase.id',
201+
'value' => '123',
202+
],
203+
],
204+
'recipient' => [
205+
'channel' => 'email',
206+
'address' => 'john.doe@example.com',
207+
],
208+
],
209+
$subscriptionRequest->jsonSerialize()
210+
);
211+
}
212+
142213
public function testPhaseJobProcessingLongSubscription(): void
143214
{
144215
$subscriptionRequest = new Subscription(

tests/SubscriptionClientFunctionalTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public function testCreateInvalidSubscription(): void
4646
self::expectException(ClientException::class);
4747
self::expectExceptionMessage(
4848
'Invalid event type "dummy-event", valid types are: ' .
49-
'"job-failed, job-succeeded-with-warning, job-processing-long, phase-job-failed, ' .
50-
'phase-job-succeeded-with-warning, phase-job-processing-long".'
49+
'"job-failed, job-succeeded, job-succeeded-with-warning, job-processing-long, phase-job-failed, ' .
50+
'phase-job-succeeded, phase-job-succeeded-with-warning, phase-job-processing-long".'
5151
);
5252
$client->createSubscription(new Subscription(
5353
'dummy-event',

0 commit comments

Comments
 (0)