Skip to content

Commit

Permalink
Merge pull request #355: Eager Workflow start client option
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk authored Sep 13, 2023
2 parents a1f6fee + d669f7d commit da97d7a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
27 changes: 27 additions & 0 deletions src/Client/WorkflowOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ final class WorkflowOptions extends Options
#[Marshal(name: 'TaskQueue')]
public string $taskQueue = WorkerFactoryInterface::DEFAULT_TASK_QUEUE;

/**
* Eager Workflow Dispatch is a mechanism that minimizes the duration from starting a workflow to the
* processing of the first workflow task, making Temporal more suitable for latency sensitive applications.
*/
#[Marshal(name: 'EnableEagerStart')]
public bool $eagerStart = false;

/**
* The timeout for duration of workflow execution.
*
Expand Down Expand Up @@ -199,6 +206,26 @@ public function withTaskQueue(string $taskQueue): self
return $self;
}

/**
* Eager Workflow Dispatch is a mechanism that minimizes the duration from starting a workflow to the
* processing of the first workflow task, making Temporal more suitable for latency sensitive applications.
*
* Eager Workflow Dispatch can be enabled if the server supports it and a local worker
* is available the task is fed directly to the worker.
*
* @param bool $value
* @return $this
*/
#[Pure]
public function withEagerStart(bool $value = true): self
{
$self = clone $this;

$self->eagerStart = $value;

return $self;
}

/**
* The maximum time that parent workflow is willing to wait for a child
* execution (which includes retries and continue as new calls). If exceeded
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/Failure/FailureConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public static function mapExceptionToFailure(\Throwable $e, DataConverterInterfa

default:
$info = new ApplicationFailureInfo();
$info->setType(get_class($e));
$info->setType($e::class);
$info->setNonRetryable(false);
$failure->setApplicationFailureInfo($info);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Internal/Client/WorkflowStarter.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public function start(
->setWorkflowExecutionTimeout(DateInterval::toDuration($options->workflowExecutionTimeout))
->setWorkflowTaskTimeout(DateInterval::toDuration($options->workflowTaskTimeout))
->setMemo($options->toMemo($this->converter))
->setSearchAttributes($options->toSearchAttributes($this->converter));
->setSearchAttributes($options->toSearchAttributes($this->converter))
->setRequestEagerExecution($options->eagerStart);

$input = EncodedValues::fromValues($args, $this->converter);
if (!$input->isEmpty()) {
Expand Down
9 changes: 9 additions & 0 deletions tests/Functional/SimpleWorkflowTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Temporal\Client\GRPC\ServiceClient;
use Temporal\Client\WorkflowClient;
use Temporal\Client\WorkflowOptions;
use Temporal\Testing\ActivityMocker;
use Temporal\Tests\TestCase;
use Temporal\Tests\Workflow\SimpleWorkflow;
Expand Down Expand Up @@ -38,4 +39,12 @@ public function testWorkflowReturnsUpperCasedInput(): void
$run = $this->workflowClient->start($workflow, 'hello');
$this->assertSame('world', $run->getResult('string'));
}

public function testEagerStartDoesntFail(): void
{
$workflow = $this->workflowClient
->newWorkflowStub(SimpleWorkflow::class, WorkflowOptions::new()->withEagerStart());
$run = $this->workflowClient->start($workflow, 'hello');
$this->assertSame('HELLO', $run->getResult('string'));
}
}
10 changes: 10 additions & 0 deletions tests/Unit/DTO/WorkflowOptionsTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function testMarshalling(): void
$expected = [
'WorkflowID' => $dto->workflowId,
'TaskQueue' => 'default',
'EnableEagerStart' => false,
'WorkflowExecutionTimeout' => 0,
'WorkflowRunTimeout' => 0,
'WorkflowTaskTimeout' => 0,
Expand Down Expand Up @@ -59,6 +60,15 @@ public function testTaskQueueChangesNotMutateState(): void
$this->assertNotSame($dto, $dto->withTaskQueue(Uuid::v4()));
}

public function testEagerStateNotMutateState(): void
{
$dto = new WorkflowOptions();

$this->assertNotSame($dto, $newDto = $dto->withEagerStart());
$this->assertFalse($dto->eagerStart);
$this->assertTrue($newDto->eagerStart);
}

public function testWorkflowExecutionTimeoutChangesNotMutateState(): void
{
$dto = new WorkflowOptions();
Expand Down
1 change: 0 additions & 1 deletion tests/Unit/Exception/FailureConverterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ public function testApplicationFailureCanTransferData(): void

$this->assertSame('abc', $restoredDetails->getValue(0));
$this->assertSame(123, $restoredDetails->getValue(1));

}
}

0 comments on commit da97d7a

Please sign in to comment.