Skip to content

Commit eba156e

Browse files
authored
Merge pull request #6 from keboola/odin-PS-2489
add long processing event
2 parents be7a946 + 0f82c78 commit eba156e

3 files changed

Lines changed: 110 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Notification API PHP Client [![Build Status]
1+
# Notification API PHP Client [![Build Status](https://dev.azure.com/keboola-dev/notification-api-php-client/_apis/build/status/keboola.notification-api-php-client?branchName=main)](https://dev.azure.com/keboola-dev/notification-api-php-client/_build/latest?definitionId=82&branchName=main)
22

33
PHP client for the Notification API ([API docs](https://app.swaggerhub.com/apis/odinuv/notifications-service/1.0.0)).
44

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 JobProcessingLongEventData implements EventDataInterface
10+
{
11+
private string $projectId;
12+
private string $projectName;
13+
private float $durationOvertimePercentage;
14+
private float $averageDuration;
15+
private float $currentDuration;
16+
private JobData $jobData;
17+
18+
public function __construct(
19+
string $projectId,
20+
string $projectName,
21+
float $durationOvertimePercentage,
22+
float $averageDuration,
23+
float $currentDuration,
24+
JobData $jobData
25+
) {
26+
$this->projectId = $projectId;
27+
$this->projectName = $projectName;
28+
$this->durationOvertimePercentage = $durationOvertimePercentage;
29+
$this->jobData = $jobData;
30+
$this->averageDuration = $averageDuration;
31+
$this->currentDuration = $currentDuration;
32+
}
33+
34+
public function jsonSerialize(): array
35+
{
36+
return [
37+
'averageDuration' => $this->averageDuration,
38+
'currentDuration' => $this->currentDuration,
39+
'durationOvertimePercentage' => $this->durationOvertimePercentage,
40+
'job' => $this->jobData->jsonSerialize(),
41+
'project' => [
42+
'id' => $this->projectId,
43+
'name' => $this->projectName,
44+
],
45+
];
46+
}
47+
48+
public static function getEventTypeName(): string
49+
{
50+
return 'job-processing-long';
51+
}
52+
}
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\JobFailedEventData;
10+
use Keboola\NotificationClient\Requests\PostEvent\JobProcessingLongEventData;
11+
use PHPUnit\Framework\TestCase;
12+
13+
class JobProcessingLongEventDataTest extends TestCase
14+
{
15+
public function testJsonSerialize(): void
16+
{
17+
$jobData = new JobData(
18+
'23456',
19+
'http://someUrl',
20+
new DateTimeImmutable('2020-01-01T11:11:00+00:00'),
21+
new DateTimeImmutable('2020-01-01T12:11:00+00:00'),
22+
'keboola.orchestrator',
23+
'Orchestrator',
24+
'my-configuration',
25+
'My configuration'
26+
);
27+
$failedEventData = new JobProcessingLongEventData('1234', 'My project', 12.534, 23.854, 12.0, $jobData);
28+
self::assertSame(
29+
[
30+
'averageDuration' => 23.854,
31+
'currentDuration' => 12.0,
32+
'durationOvertimePercentage' => 12.534,
33+
'job' => [
34+
'id' => '23456',
35+
'url' => 'http://someUrl',
36+
'component' => [
37+
'id' => 'keboola.orchestrator',
38+
'name' => 'Orchestrator',
39+
],
40+
'tasks' => [],
41+
'startTime' => '2020-01-01T11:11:00+00:00',
42+
'endTime' => '2020-01-01T12:11:00+00:00',
43+
'configuration' => [
44+
'id' => 'my-configuration',
45+
'name' => 'My configuration',
46+
],
47+
],
48+
'project' => [
49+
'id' => '1234',
50+
'name' => 'My project',
51+
],
52+
],
53+
$failedEventData->jsonSerialize()
54+
);
55+
self::assertEquals('job-processing-long', $failedEventData::getEventTypeName());
56+
}
57+
}

0 commit comments

Comments
 (0)