You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This sample shows how to use Activity retries for infrequent polling of a third-party service (for example via REST). This method can be used for infrequent polls of one minute or slower.
3
+
This sample shows how we can implement frequent polling (1 second or faster) inside our Activity. The implementation is a loop that polls our service and then sleeps for the poll interval (1 second in the sample).
4
4
5
-
Activity retries are utilized for this option, setting the following Retry options:
6
-
7
-
-`BackoffCoefficient`: to 1
8
-
-`InitialInterval`: to the polling interval (in this sample set to 60 seconds)
9
-
10
-
This will enable the Activity to be retried on the set interval.
5
+
To ensure that polling Activity is restarted in a timely manner, we make sure that it heartbeats on every iteration. Note that heartbeating only works if we set the `HeartbeatTimeout` to a shorter value than the Activity `StartToCloseTimeout` timeout.
11
6
12
7
### Running this sample
13
8
@@ -16,5 +11,7 @@ This will enable the Activity to be retried on the set interval.
16
11
1.`npm run start.watch` to start the Worker.
17
12
1. In another shell, `npm run workflow` to run the Workflow Client.
18
13
19
-
The Workflow will call the actitity and it will fail four times, then
20
-
succeed on the fifth and log `Hello, Temporal!`
14
+
The Workflow will call the activity and it will call the test service.
15
+
The test service will either succeed or fail by generating a random number between 0 and 1:
16
+
if less than .2, then it will succeed; otherwise it will fail.
17
+
It logs the generated numbers, and when it succeeds, it will log `Hello, Temporal!`.
Copy file name to clipboardExpand all lines: polling-infrequent/README.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ This sample shows how to use Activity retries for infrequent polling of a third-
5
5
Activity retries are utilized for this option, setting the following Retry options:
6
6
7
7
-`BackoffCoefficient`: to 1
8
-
-`InitialInterval`: to the polling interval (in this sample set to 60 seconds)
8
+
-`InitialInterval`: to the polling interval (in this sample set to 5 seconds for convenience, but would be at least 60 seconds in real world situations)
9
9
10
10
This will enable the Activity to be retried on the set interval.
11
11
@@ -16,5 +16,7 @@ This will enable the Activity to be retried on the set interval.
16
16
1.`npm run start.watch` to start the Worker.
17
17
1. In another shell, `npm run workflow` to run the Workflow Client.
18
18
19
-
The Workflow will call the actitity and it will fail four times, then
20
-
succeed on the fifth and log `Hello, Temporal!`
19
+
The Workflow will call the activity and it will call the test service.
20
+
The test service will either succeed or fail by generating a random number between 0 and 1:
21
+
if less than .2, then it will succeed; otherwise it will fail.
22
+
It logs the generated numbers, and when it succeeds, it will log `Hello, Temporal!`.
0 commit comments