Skip to content

Commit

Permalink
Merge pull request #381: Fix Schedule RetryPolicy marshalling
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk authored Jan 5, 2024
2 parents 403baf4 + 95dd56f commit bab54b6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 0 additions & 4 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -728,16 +728,12 @@
<RedundantCondition>
<code><![CDATA[$action->header?->setDataConverter($this->converter)]]></code>
<code><![CDATA[$action->input?->setDataConverter($this->converter)]]></code>
<code><![CDATA[$action->input?->setDataConverter($this->converter)]]></code>
<code><![CDATA[$action->input?->toPayloads()]]></code>
<code><![CDATA[$action->memo?->setDataConverter($this->converter)]]></code>
<code><![CDATA[$action->searchAttributes?->setDataConverter($this->converter)]]></code>
</RedundantCondition>
<TypeDoesNotContainNull>
<code><![CDATA[$action->header]]></code>
<code><![CDATA[$action->input]]></code>
<code><![CDATA[$action->input]]></code>
<code><![CDATA[$action->input]]></code>
<code><![CDATA[$action->memo]]></code>
<code><![CDATA[$action->searchAttributes]]></code>
</TypeDoesNotContainNull>
Expand Down
1 change: 1 addition & 0 deletions src/Common/RetryOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* @psalm-type ExceptionsList = array<class-string<\Throwable>>
* @psalm-import-type DateIntervalValue from DateInterval
* @psalm-immutable
* @see RetryPolicy
*/
class RetryOptions extends Options
{
Expand Down
5 changes: 4 additions & 1 deletion src/Internal/Mapper/ScheduleMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public function toMessage(Schedule $dto): \Temporal\Api\Schedule\V1\Schedule
return new \Temporal\Api\Schedule\V1\Schedule($array);
}

/**
* @psalm-suppress TypeDoesNotContainNull,RedundantCondition
*/
private function prepareAction(ScheduleAction $action, array $array): \Temporal\Api\Schedule\V1\ScheduleAction
{
$result = new \Temporal\Api\Schedule\V1\ScheduleAction();
Expand All @@ -64,7 +67,7 @@ private function prepareAction(ScheduleAction $action, array $array): \Temporal\
$action->input?->setDataConverter($this->converter);
$values['input'] = $action->input?->toPayloads() ?? new Payloads();
$values['workflow_id_reuse_policy'] = $action->workflowIdReusePolicy->value;
$values['retry_policy'] = new RetryPolicy($values['retry_policy'] ?? []);
$values['retry_policy'] = $action->retryPolicy?->toWorkflowRetryPolicy();

$result->setStartWorkflow(
new \Temporal\Api\Workflow\V1\NewWorkflowExecutionInfo($values),
Expand Down
11 changes: 10 additions & 1 deletion tests/Unit/Schedule/Mapper/WorkflowExecutionInfoMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ public function testFromPayload(): void
Schedule\Action\StartWorkflowAction::new('PingSite')
->withInput(['google.com'])
->withTaskQueue('default')
->withRetryPolicy(RetryOptions::new()->withMaximumAttempts(3))
->withRetryPolicy(RetryOptions::new()
->withMaximumAttempts(3)
->withInitialInterval(\Carbon\CarbonInterval::seconds(10))
->withMaximumInterval(\Carbon\CarbonInterval::seconds(20))
)
->withHeader(['foo' => 'bar'])
->withWorkflowExecutionTimeout('40m')
->withWorkflowRunTimeout('30m')
Expand Down Expand Up @@ -96,6 +100,11 @@ public function testFromPayload(): void
$this->assertInstanceOf(NewWorkflowExecutionInfo::class, $startWorkflow);
$this->assertSame('PingSite', $startWorkflow->getWorkflowType()->getName());
$this->assertSame('default', $startWorkflow->getTaskQueue()->getName());
// Retry Policy
$this->assertSame(3, $startWorkflow->getRetryPolicy()->getMaximumAttempts());
$this->assertSame(10, $startWorkflow->getRetryPolicy()->getInitialInterval()->getSeconds());
$this->assertSame(20, $startWorkflow->getRetryPolicy()->getMaximumInterval()->getSeconds());
// Header
$this->assertSame(
['foo' => 'bar'],
EncodedCollection::fromPayloadCollection(
Expand Down

0 comments on commit bab54b6

Please sign in to comment.