Skip to content

Commit

Permalink
[PHP Describe Schedule API (#2824)
Browse files Browse the repository at this point in the history
* Add documentation about Schedule API in PHP SDK

* Fix typo on Java features page

---------

Co-authored-by: Cully <cully@temporal.io>
  • Loading branch information
roxblnfk and Cully authored May 20, 2024
1 parent 7522795 commit 95cdad5
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/dev-guide/javalang/features.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ In this section you can find the following:
- [How to develop Signals](#signals)
- [How to develop Queries](#queries)
- [How to start a Child Workflow Execution](#child-workflows)
- [How to Schedule a Workflow](#schedule-a-workflow)
- [How to start a Temporal Cron Job](#cron-schedule)
- [How to use Continue-As-New](#continue-as-new)
- [How to set Workflow timeouts & retries](#workflow-timeouts)
Expand Down Expand Up @@ -1222,7 +1223,7 @@ ScheduleHandle handle = client.getHandle("schedule-id")
ScheduleDescription description = handle.describe();
```
### How to describe a Schedule in Java {#describe-schedule}
### How to List a Scheduled Workflow in Java {#list-schedule}
The list action lists all the available Schedules. This command is useful when you want to view a list of all the Schedules and their respective Schedule IDs.
Expand Down
145 changes: 144 additions & 1 deletion docs/dev-guide/phplang/features.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ In this section you can find the following:
- [How to develop Queries](#queries)
- [How to develop with Updates](#updates)
- [How to start a Child Workflow Execution](#child-workflows)
- [How to Schedule a Workflow](#schedule-a-workflow)
- [How to start a Temporal Cron Job](#temporal-cron-jobs)
- [How to use Continue-As-New](#continue-as-new)
- [How to set Workflow timeouts & retries](#workflow-timeouts)
Expand Down Expand Up @@ -491,7 +492,7 @@ use Temporal\Client\Update\UpdateOptions;
use Temporal\Client\Update\WaitPolicy;
use Temporal\Client\Update\LifecycleStage;

// Create a typed Workflow stub for GreetingsWorkflow
// Create an untyped Workflow stub for GreetingsWorkflow
$stub = $client->newUntypedWorkflowStub('GreetingWorkflow', $workflowOptions);

// Start the Workflow
Expand Down Expand Up @@ -1006,6 +1007,148 @@ yield Workflow::timer(300); // sleep for 5 minutes

You cannot set a Timer invocation inside the `await` or `awaitWithTimeout` methods.

## How to Schedule a Workflow {#schedule-a-workflow}

Scheduling Workflows is a crucial aspect of any automation process, especially when dealing with time-sensitive tasks. By scheduling a Workflow, you can automate repetitive tasks, reduce the need for manual intervention, and ensure timely execution of your business processes

Use any of the following action to help Schedule a Workflow Execution and take control over your automation process.

### How to create a Schedule in PHP {#create-schedule}

The create action enables you to create a new Schedule. When you create a new Schedule, a unique Schedule ID is generated, which you can use to reference the Schedule in other Schedule commands.

To create a Scheduled Workflow Execution in PHP, use the `createSchedule()` method on the `ScheduleClient`. Schedules must be initialized with a Schedule ID,

```php
use Temporal\Client\Schedule;

/** @var \Temporal\Client\ScheduleClient $scheduleClient */

// Create a Schedule
$handle = $scheduleClient->createSchedule(
Schedule\Schedule::new()->withAction(
Schedule\Action\StartWorkflowAction::new('GreetingWorkflow')
->withInput(['World'])
->withTaskQueue('TaskQueue')
->withWorkflowExecutionTimeout('4 minutes')
)->withSpec(
Schedule\Spec\ScheduleSpec::new()
->withIntervalList(5 * 60) // every 5 minutes
->withJitter(60) // with jitter of 1 minute
),
scheduleId: 'my-schedule-id',
);
```

### How to backfill a Schedule in PHP {#backfill-schedule}

The backfill action executes Actions ahead of their specified time range. This command is useful when you need to execute a missed or delayed Action, or when you want to test the Workflow before its scheduled time.

To Backfill a Scheduled Workflow Execution in PHP, use the `backfill()` method on the `ScheduleHandle`.

```php
use Temporal\Client\Schedule;

/** @var \Temporal\Client\ScheduleClient $scheduleClient */

$handle = $scheduleClient->getHandle('my-schedule-id');

$now = new DateTimeImmutable();
$handle->backfill([
Schedule\BackfillPeriod::new($now->modify('-5000ms'), $now->modify('-2500ms')),
Schedule\BackfillPeriod::new($now->modify('-2500ms'), $now),
]);
```

### How to delete a Schedule in PHP {#delete-schedule}

The delete action enables you to delete a Schedule. When you delete a Schedule, it does not affect any Workflows that were started by the Schedule.

To delete a Scheduled Workflow Execution in PHP, use the `delete()` method on the `Schedule Handle`.

```php
/** @var \Temporal\Client\ScheduleClient $scheduleClient */

$handle = $scheduleClient->getHandle('my-schedule-id');
$handle->delete();
```

### How to describe a Schedule in PHP {#describe-schedule}

The describe action shows the current Schedule configuration, including information about past, current, and future Workflow Runs. This command is helpful when you want to get a detailed view of the Schedule and its associated Workflow Runs.

To describe a Scheduled Workflow Execution in PHP, use the `describe()` method on the `ScheduleHandle`.

```php
/** @var \Temporal\Client\ScheduleClient $scheduleClient */

$handle = $scheduleClient->getHandle('my-schedule-id');
$description = $handle->describe();
```

### How to List a Scheduled Workflow in PHP {#list-schedule}

The list action lists all the available Schedules. This command is useful when you want to view a list of all the Schedules and their respective Schedule IDs.

To list all schedules, use the `listSchedules()` asynchronous method on the `ScheduleClient`.
If a schedule is added or deleted, it may not be available in the list immediately.

```php
/** @var \Temporal\Client\ScheduleClient $scheduleClient */

$schedules = $scheduleClient->listSchedules();
```

### How to pause a Schedule in PHP {#pause-schedule}

The pause action enables you to pause and unpause a Schedule. When you pause a Schedule, all the future Workflow Runs associated with the Schedule are temporarily stopped. This command is useful when you want to temporarily halt a Workflow due to maintenance or any other reason.

To pause a Scheduled Workflow Execution in PHP, use the `pause()` method on the `ScheduleHandle`.
You can pass a `note` to the `pause()` method to provide a reason for pausing the schedule.

```php
/** @var \Temporal\Client\ScheduleClient $scheduleClient */

$handle = $scheduleClient->getHandle('my-schedule-id');
$handle->pause("Pausing the schedule for now");
```

### How to trigger a Schedule in PHP {#trigger-schedule}

The trigger action triggers an immediate action with a given Schedule. By default, this action is subject to the Overlap Policy of the Schedule. This command is helpful when you want to execute a Workflow outside of its scheduled time.

To trigger a Scheduled Workflow Execution in PHP, use the `trigger()` method on the `ScheduleHandle`.

```php
/** @var \Temporal\Client\ScheduleClient $scheduleClient */

$handle = $scheduleClient->getHandle('my-schedule-id');
$handle->trigger();
```

### How to update a Schedule in PHP {#update-schedule}

The update action enables you to update an existing Schedule. This command is useful when you need to modify the Schedule's configuration, such as changing the start time, end time, or interval.

Create a function that takes `ScheduleUpdateInput` and returns `ScheduleUpdate`.
To update a Schedule, use a callback to build the update from the description.
The following example updates the Schedule to set a limited number of actions.

```php
use Temporal\Client\Schedule;
/** @var \Temporal\Client\ScheduleClient $scheduleClient */

$handle = $scheduleClient->getHandle('my-schedule-id');
$handle->update(
Schedule\Schedule::new()
->withState(
Schedule\Spec\ScheduleState::new()
->withLimitedActions(true)
->withRemainingActions(10)
)
);
```

## How to use Temporal Cron Jobs {#temporal-cron-jobs}

A [Temporal Cron Job](/workflows#temporal-cron-job) is the series of Workflow Executions that occur when a Cron Schedule is provided in the call to spawn a Workflow Execution.
Expand Down
1 change: 1 addition & 0 deletions docs/dev-guide/phplang/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ The Features section of the Temporal Developer's guide provides basic implementa
- [How to start a Child Workflow Execution](/dev-guide/php/features#child-workflows): A Child Workflow Execution is a Workflow Execution that is scheduled from within another Workflow using a Child Workflow API.
- [How to Continue-As-New](/dev-guide/php/features#continue-as-new): Continue-As-New enables a Workflow Execution to close successfully and create a new Workflow Execution in a single atomic operation if the number of Events in the Event History is becoming too large.
- [What is a Timer?](/dev-guide/php/features#timers): A Timer lets a Workflow sleep for a fixed time period.
- [How to Schedule a Workflow](/dev-guide/php/features#schedule-a-workflow): Schedule a Workflow.
- [How to use Temporal Cron Jobs](/dev-guide/php/features#temporal-cron-jobs): A Temporal Cron Job is the series of Workflow Executions that occur when a Cron Schedule is provided in the call to spawn a Workflow Execution.
- [How to use Side Effects in PHP](/dev-guide/php/features#side-effects): Side Effects are used to execute non-deterministic code, such as generating a UUID or a random number, without compromising determinism in the Workflow.
- [How to use Start Delay](/dev-guide/php/features#start-delay): Set the Start Delay option in your Workflow Options.
Expand Down
2 changes: 1 addition & 1 deletion docs/encyclopedia/workflows.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ If there is any chance that the code provided to the Side Effect could fail, use
- Available in [Python SDK](/dev-guide/python/features#schedule-a-workflow) since [v1.1.0](https://github.com/temporalio/sdk-python/releases/tag/1.1.0)
- Available in [TypeScript SDK](https://github.com/temporalio/samples-typescript/tree/main/schedules#schedules) since [v1.5.0](https://github.com/temporalio/sdk-typescript/blob/main/CHANGELOG.md#150---2022-12-07)
- Available in [.NET SDK](https://dotnet.temporal.io/api/Temporalio.Client.Schedules.html) since [v0.1.0](https://github.com/temporalio/sdk-dotnet/releases/tag/0.1.0-alpha4)
- Available in PHP SDK since [v2.8.0](https://github.com/temporalio/sdk-php/releases/tag/v2.8.0)
- Available in [PHP SDK](https://php.temporal.io/classes/Temporal-Client-ScheduleClient.html) since [v2.7.0](https://github.com/temporalio/sdk-php/releases/tag/v2.7.0)
- Available in [gRPC API](https://api-docs.temporal.io/#temporal.api.workflowservice.v1.CreateScheduleRequest)

:::
Expand Down

0 comments on commit 95cdad5

Please sign in to comment.