|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | | -require 'temporalio/activity' |
| 3 | +module Polling |
| 4 | + module Infrequent |
| 5 | + # A mock external service with simulated errors. |
| 6 | + module TestService |
| 7 | + class TestServiceError < StandardError; end |
4 | 8 |
|
5 | | -# A mock external service with simulated errors. |
6 | | -module TestService |
7 | | - class TestServiceError < StandardError; end |
| 9 | + @attempts = Hash.new(0) |
| 10 | + ERROR_ATTEMPTS = 5 |
8 | 11 |
|
9 | | - @attempts = Hash.new(0) |
10 | | - ERROR_ATTEMPTS = 5 |
| 12 | + def get_service_result(input, activity_info) |
| 13 | + workflow_id = activity_info.workflow_id |
| 14 | + @attempts[workflow_id] ||= 0 |
| 15 | + @attempts[workflow_id] += 1 |
11 | 16 |
|
12 | | - ComposeGreetingInput = Struct.new(:greeting, :name) |
| 17 | + puts "Attempt #{@attempts[workflow_id]} of #{ERROR_ATTEMPTS} to invoke service" |
13 | 18 |
|
14 | | - def get_service_result(input, activity_info) |
15 | | - workflow_id = activity_info.workflow_id |
16 | | - @attempts[workflow_id] ||= 0 |
17 | | - @attempts[workflow_id] += 1 |
| 19 | + raise TestServiceError, 'service is down' unless @attempts[workflow_id] == ERROR_ATTEMPTS |
18 | 20 |
|
19 | | - puts "Attempt #{@attempts[workflow_id]} of #{ERROR_ATTEMPTS} to invoke service" |
20 | | - |
21 | | - raise TestServiceError, 'service is down' unless @attempts[workflow_id] == ERROR_ATTEMPTS |
22 | | - |
23 | | - "#{input['greeting']}, #{input['name']}!" |
| 21 | + "#{input['greeting']}, #{input['name']}!" |
| 22 | + end |
| 23 | + module_function :get_service_result |
| 24 | + end |
24 | 25 | end |
25 | | - module_function :get_service_result |
26 | 26 | end |
0 commit comments