Skip to content

Commit 6a69c95

Browse files
authored
Merge pull request #10 from keboola/odin-PS-2972
Add Phase job failed event
2 parents 8117dcd + fede4e4 commit 6a69c95

5 files changed

Lines changed: 158 additions & 1 deletion

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 PhaseJobFailedEventData implements EventDataInterface
10+
{
11+
private string $projectId;
12+
private string $projectName;
13+
private string $errorMessage;
14+
private JobData $jobData;
15+
private string $phaseName;
16+
private string $phaseId;
17+
18+
public function __construct(
19+
string $projectId,
20+
string $projectName,
21+
string $phaseName,
22+
string $phaseId,
23+
string $errorMessage,
24+
JobData $jobData
25+
) {
26+
$this->projectId = $projectId;
27+
$this->projectName = $projectName;
28+
$this->errorMessage = $errorMessage;
29+
$this->jobData = $jobData;
30+
$this->phaseName = $phaseName;
31+
$this->phaseId = $phaseId;
32+
}
33+
34+
public function jsonSerialize(): array
35+
{
36+
return [
37+
'errorMessage' => $this->errorMessage,
38+
'job' => $this->jobData->jsonSerialize(),
39+
'phase' => [
40+
'id' => $this->phaseId,
41+
'name' => $this->phaseName,
42+
],
43+
'project' => [
44+
'id' => $this->projectId,
45+
'name' => $this->projectName,
46+
],
47+
];
48+
}
49+
50+
public static function getEventTypeName(): string
51+
{
52+
return 'phase-job-failed';
53+
}
54+
}

src/Requests/Subscription.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Keboola\NotificationClient\Requests\PostEvent\JobFailedEventData;
1111
use Keboola\NotificationClient\Requests\PostEvent\JobProcessingLongEventData;
1212
use Keboola\NotificationClient\Requests\PostEvent\JobSucceededWithWarningEventData;
13+
use Keboola\NotificationClient\Requests\PostEvent\PhaseJobFailedEventData;
1314
use Keboola\NotificationClient\Requests\PostSubscription\EmailRecipient;
1415
use Keboola\NotificationClient\Requests\PostSubscription\Filter;
1516

@@ -56,6 +57,7 @@ private function checkEventType(string $eventType): void
5657
JobFailedEventData::getEventTypeName(),
5758
JobSucceededWithWarningEventData::getEventTypeName(),
5859
JobProcessingLongEventData::getEventTypeName(),
60+
PhaseJobFailedEventData::getEventTypeName(),
5961
];
6062

6163
if (!in_array($eventType, $validEventTypes)) {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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\PhaseJobFailedEventData;
10+
use PHPUnit\Framework\TestCase;
11+
12+
class PhaseJobFailedEventDataTest 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 PhaseJobFailedEventData(
27+
'1234',
28+
'My project',
29+
'Lithium Extractors',
30+
'123',
31+
'someMessage',
32+
$jobData
33+
);
34+
self::assertSame(
35+
[
36+
'errorMessage' => 'someMessage',
37+
'job' => [
38+
'id' => '23456',
39+
'url' => 'http://someUrl',
40+
'component' => [
41+
'id' => 'keboola.orchestrator',
42+
'name' => 'Orchestrator',
43+
],
44+
'tasks' => [],
45+
'startTime' => '2020-01-01T11:11:00+00:00',
46+
'endTime' => '2020-01-01T12:11:00+00:00',
47+
'configuration' => [
48+
'id' => 'my-configuration',
49+
'name' => 'My configuration',
50+
],
51+
],
52+
'phase' => [
53+
'id' => '123',
54+
'name' => 'Lithium Extractors',
55+
],
56+
'project' => [
57+
'id' => '1234',
58+
'name' => 'My project',
59+
],
60+
],
61+
$failedEventData->jsonSerialize()
62+
);
63+
}
64+
}

tests/Requests/SubscriptionTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,41 @@ public function testJsonSerializeStrangeFilters(): void
6464
$subscriptionRequest->jsonSerialize()
6565
);
6666
}
67+
68+
public function testPhaseJobSubscription(): void
69+
{
70+
$subscriptionRequest = new Subscription(
71+
'phase-job-failed',
72+
new EmailRecipient('john.doe@example.com'),
73+
[
74+
new Filter('job.component.id', 'my.component'),
75+
new Filter('job.configuration.id', '12345'),
76+
new Filter('phase.id', '123'),
77+
]
78+
);
79+
self::assertSame(
80+
[
81+
'event' => 'phase-job-failed',
82+
'filters' => [
83+
[
84+
'field' => 'job.component.id',
85+
'value' => 'my.component',
86+
],
87+
[
88+
'field' => 'job.configuration.id',
89+
'value' => '12345',
90+
],
91+
[
92+
'field' => 'phase.id',
93+
'value' => '123',
94+
],
95+
],
96+
'recipient' => [
97+
'channel' => 'email',
98+
'address' => 'john.doe@example.com',
99+
],
100+
],
101+
$subscriptionRequest->jsonSerialize()
102+
);
103+
}
67104
}

tests/SubscriptionClientFunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ 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".'
49+
'"job-failed, job-succeeded-with-warning, job-processing-long, phase-job-failed".'
5050
);
5151
$client->createSubscription(new Subscription(
5252
'dummy-event',

0 commit comments

Comments
 (0)