Skip to content

Commit 1e6202f

Browse files
Added support for task status step function actions (#1109)
* Added support for task status step function actions * Fixed typos * Fixed tests
1 parent d9377a0 commit 1e6202f

19 files changed

+819
-3
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace AsyncAws\StepFunctions\Exception;
4+
5+
use AsyncAws\Core\Exception\Http\ClientException;
6+
use Symfony\Contracts\HttpClient\ResponseInterface;
7+
8+
/**
9+
* The provided JSON output data is invalid.
10+
*/
11+
final class InvalidOutputException extends ClientException
12+
{
13+
protected function populateResult(ResponseInterface $response): void
14+
{
15+
$data = $response->toArray(false);
16+
17+
if (null !== $v = (isset($data['message']) ? (string) $data['message'] : null)) {
18+
$this->message = $v;
19+
}
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace AsyncAws\StepFunctions\Exception;
4+
5+
use AsyncAws\Core\Exception\Http\ClientException;
6+
use Symfony\Contracts\HttpClient\ResponseInterface;
7+
8+
/**
9+
* The provided token is invalid.
10+
*/
11+
final class InvalidTokenException extends ClientException
12+
{
13+
protected function populateResult(ResponseInterface $response): void
14+
{
15+
$data = $response->toArray(false);
16+
17+
if (null !== $v = (isset($data['message']) ? (string) $data['message'] : null)) {
18+
$this->message = $v;
19+
}
20+
}
21+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace AsyncAws\StepFunctions\Exception;
4+
5+
use AsyncAws\Core\Exception\Http\ClientException;
6+
use Symfony\Contracts\HttpClient\ResponseInterface;
7+
8+
final class TaskDoesNotExistException extends ClientException
9+
{
10+
protected function populateResult(ResponseInterface $response): void
11+
{
12+
$data = $response->toArray(false);
13+
14+
if (null !== $v = (isset($data['message']) ? (string) $data['message'] : null)) {
15+
$this->message = $v;
16+
}
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace AsyncAws\StepFunctions\Exception;
4+
5+
use AsyncAws\Core\Exception\Http\ClientException;
6+
use Symfony\Contracts\HttpClient\ResponseInterface;
7+
8+
final class TaskTimedOutException extends ClientException
9+
{
10+
protected function populateResult(ResponseInterface $response): void
11+
{
12+
$data = $response->toArray(false);
13+
14+
if (null !== $v = (isset($data['message']) ? (string) $data['message'] : null)) {
15+
$this->message = $v;
16+
}
17+
}
18+
}

src/Input/SendTaskFailureInput.php

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?php
2+
3+
namespace AsyncAws\StepFunctions\Input;
4+
5+
use AsyncAws\Core\Exception\InvalidArgument;
6+
use AsyncAws\Core\Input;
7+
use AsyncAws\Core\Request;
8+
use AsyncAws\Core\Stream\StreamFactory;
9+
10+
final class SendTaskFailureInput extends Input
11+
{
12+
/**
13+
* The token that represents this task. Task tokens are generated by Step Functions when tasks are assigned to a worker,
14+
* or in the context object when a workflow enters a task state. See GetActivityTaskOutput$taskToken.
15+
*
16+
* @see https://docs.aws.amazon.com/step-functions/latest/dg/input-output-contextobject.html
17+
* @required
18+
*
19+
* @var string|null
20+
*/
21+
private $taskToken;
22+
23+
/**
24+
* The error code of the failure.
25+
*
26+
* @var string|null
27+
*/
28+
private $error;
29+
30+
/**
31+
* A more detailed explanation of the cause of the failure.
32+
*
33+
* @var string|null
34+
*/
35+
private $cause;
36+
37+
/**
38+
* @param array{
39+
* taskToken?: string,
40+
* error?: string,
41+
* cause?: string,
42+
* @region?: string,
43+
* } $input
44+
*/
45+
public function __construct(array $input = [])
46+
{
47+
$this->taskToken = $input['taskToken'] ?? null;
48+
$this->error = $input['error'] ?? null;
49+
$this->cause = $input['cause'] ?? null;
50+
parent::__construct($input);
51+
}
52+
53+
public static function create($input): self
54+
{
55+
return $input instanceof self ? $input : new self($input);
56+
}
57+
58+
public function getCause(): ?string
59+
{
60+
return $this->cause;
61+
}
62+
63+
public function getError(): ?string
64+
{
65+
return $this->error;
66+
}
67+
68+
public function getTaskToken(): ?string
69+
{
70+
return $this->taskToken;
71+
}
72+
73+
/**
74+
* @internal
75+
*/
76+
public function request(): Request
77+
{
78+
// Prepare headers
79+
$headers = [
80+
'Content-Type' => 'application/x-amz-json-1.0',
81+
'X-Amz-Target' => 'AWSStepFunctions.SendTaskFailure',
82+
];
83+
84+
// Prepare query
85+
$query = [];
86+
87+
// Prepare URI
88+
$uriString = '/';
89+
90+
// Prepare Body
91+
$bodyPayload = $this->requestBody();
92+
$body = empty($bodyPayload) ? '{}' : json_encode($bodyPayload, 4194304);
93+
94+
// Return the Request
95+
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($body));
96+
}
97+
98+
public function setCause(?string $value): self
99+
{
100+
$this->cause = $value;
101+
102+
return $this;
103+
}
104+
105+
public function setError(?string $value): self
106+
{
107+
$this->error = $value;
108+
109+
return $this;
110+
}
111+
112+
public function setTaskToken(?string $value): self
113+
{
114+
$this->taskToken = $value;
115+
116+
return $this;
117+
}
118+
119+
private function requestBody(): array
120+
{
121+
$payload = [];
122+
if (null === $v = $this->taskToken) {
123+
throw new InvalidArgument(sprintf('Missing parameter "taskToken" for "%s". The value cannot be null.', __CLASS__));
124+
}
125+
$payload['taskToken'] = $v;
126+
if (null !== $v = $this->error) {
127+
$payload['error'] = $v;
128+
}
129+
if (null !== $v = $this->cause) {
130+
$payload['cause'] = $v;
131+
}
132+
133+
return $payload;
134+
}
135+
}

src/Input/SendTaskHeartbeatInput.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
namespace AsyncAws\StepFunctions\Input;
4+
5+
use AsyncAws\Core\Exception\InvalidArgument;
6+
use AsyncAws\Core\Input;
7+
use AsyncAws\Core\Request;
8+
use AsyncAws\Core\Stream\StreamFactory;
9+
10+
final class SendTaskHeartbeatInput extends Input
11+
{
12+
/**
13+
* The token that represents this task. Task tokens are generated by Step Functions when tasks are assigned to a worker,
14+
* or in the context object when a workflow enters a task state. See GetActivityTaskOutput$taskToken.
15+
*
16+
* @see https://docs.aws.amazon.com/step-functions/latest/dg/input-output-contextobject.html
17+
* @required
18+
*
19+
* @var string|null
20+
*/
21+
private $taskToken;
22+
23+
/**
24+
* @param array{
25+
* taskToken?: string,
26+
* @region?: string,
27+
* } $input
28+
*/
29+
public function __construct(array $input = [])
30+
{
31+
$this->taskToken = $input['taskToken'] ?? null;
32+
parent::__construct($input);
33+
}
34+
35+
public static function create($input): self
36+
{
37+
return $input instanceof self ? $input : new self($input);
38+
}
39+
40+
public function getTaskToken(): ?string
41+
{
42+
return $this->taskToken;
43+
}
44+
45+
/**
46+
* @internal
47+
*/
48+
public function request(): Request
49+
{
50+
// Prepare headers
51+
$headers = [
52+
'Content-Type' => 'application/x-amz-json-1.0',
53+
'X-Amz-Target' => 'AWSStepFunctions.SendTaskHeartbeat',
54+
];
55+
56+
// Prepare query
57+
$query = [];
58+
59+
// Prepare URI
60+
$uriString = '/';
61+
62+
// Prepare Body
63+
$bodyPayload = $this->requestBody();
64+
$body = empty($bodyPayload) ? '{}' : json_encode($bodyPayload, 4194304);
65+
66+
// Return the Request
67+
return new Request('POST', $uriString, $query, $headers, StreamFactory::create($body));
68+
}
69+
70+
public function setTaskToken(?string $value): self
71+
{
72+
$this->taskToken = $value;
73+
74+
return $this;
75+
}
76+
77+
private function requestBody(): array
78+
{
79+
$payload = [];
80+
if (null === $v = $this->taskToken) {
81+
throw new InvalidArgument(sprintf('Missing parameter "taskToken" for "%s". The value cannot be null.', __CLASS__));
82+
}
83+
$payload['taskToken'] = $v;
84+
85+
return $payload;
86+
}
87+
}

0 commit comments

Comments
 (0)