workato-connector-sdk 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/VERSION +1 -0
- data/lib/workato/cli/edit_command.rb +3 -1
- data/lib/workato/cli/exec_command.rb +76 -10
- data/lib/workato/cli/generate_command.rb +2 -2
- data/lib/workato/cli/main.rb +17 -10
- data/lib/workato/cli/oauth2_command.rb +4 -4
- data/lib/workato/cli/push_command.rb +2 -2
- data/lib/workato/cli/schema_command.rb +2 -2
- data/lib/workato/connector/sdk/account_properties.rb +2 -2
- data/lib/workato/connector/sdk/action.rb +20 -70
- data/lib/workato/connector/sdk/block_invocation_refinements.rb +2 -10
- data/lib/workato/connector/sdk/connection.rb +36 -19
- data/lib/workato/connector/sdk/connector.rb +65 -77
- data/lib/workato/connector/sdk/core.rb +62 -0
- data/lib/workato/connector/sdk/dsl/aws.rb +3 -3
- data/lib/workato/connector/sdk/dsl/call.rb +1 -1
- data/lib/workato/connector/sdk/dsl/csv_package.rb +133 -0
- data/lib/workato/connector/sdk/dsl/execution_context.rb +1 -0
- data/lib/workato/connector/sdk/dsl/http.rb +1 -1
- data/lib/workato/connector/sdk/dsl/reinvoke_after.rb +84 -0
- data/lib/workato/connector/sdk/dsl/stream_package.rb +65 -0
- data/lib/workato/connector/sdk/dsl/time.rb +0 -14
- data/lib/workato/connector/sdk/dsl/workato_package.rb +146 -0
- data/lib/workato/connector/sdk/dsl.rb +63 -10
- data/lib/workato/connector/sdk/errors.rb +28 -11
- data/lib/workato/connector/sdk/operation.rb +9 -2
- data/lib/workato/connector/sdk/request.rb +63 -25
- data/lib/workato/connector/sdk/schema/field/convertors.rb +2 -2
- data/lib/workato/connector/sdk/schema/type/unicode_string.rb +1 -1
- data/lib/workato/connector/sdk/schema.rb +7 -5
- data/lib/workato/connector/sdk/settings.rb +10 -1
- data/lib/workato/connector/sdk/stream.rb +243 -0
- data/lib/workato/connector/sdk/streams.rb +71 -0
- data/lib/workato/connector/sdk/summarize.rb +2 -2
- data/lib/workato/connector/sdk/trigger.rb +14 -7
- data/lib/workato/connector/sdk/version.rb +1 -1
- data/lib/workato/connector/sdk.rb +19 -46
- data/lib/workato/extension/array.rb +2 -0
- data/lib/workato/extension/case_sensitive_headers.rb +0 -1
- data/lib/workato/extension/content_encoding_decoder.rb +2 -0
- data/lib/workato/extension/currency/countries.rb +79 -0
- data/lib/workato/extension/currency/countries.yml +18433 -0
- data/lib/workato/extension/currency/currencies.rb +55 -0
- data/lib/workato/extension/currency/currencies.yml +479 -0
- data/lib/workato/extension/currency.rb +73 -5
- data/lib/workato/extension/enumerable.rb +2 -2
- data/lib/workato/extension/metadata_fix_wrap_kw_args.rb +11 -0
- data/lib/workato/extension/string.rb +14 -111
- data/lib/workato/testing/vcr_encrypted_cassette_serializer.rb +2 -0
- data/lib/workato/types/binary.rb +55 -0
- metadata +46 -61
- data/lib/workato/connector/sdk/dsl/csv.rb +0 -125
- data/lib/workato/connector/sdk/dsl/workato_code_lib.rb +0 -167
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e0a739fc6bc5fe15228d209dc24ac4858c3815b4252b5f6d9abd9ae0644b15d
|
4
|
+
data.tar.gz: d4089c8dc7f6c8f9bd171730797a7b82eeb3192883d4b5883a5998985a20001a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6a00086288382c03c024f351e69ca79749d6ef41a833141140274926bec885a7382ce505e9b4981c05a465efa2f1c97cb30697906b8ba6c63d02709dedc9de7
|
7
|
+
data.tar.gz: b5b289bf86ac5970420e20762609256a6280f00a76ae604fcff206f65f40abb517f22c2207f93f1d439b250e4d725e4a5a91865904bf32c93459c52c932e70b3
|
data/README.md
CHANGED
@@ -13,7 +13,7 @@ This guide below showcases how you can do the following things:
|
|
13
13
|
|
14
14
|
## Prerequisites
|
15
15
|
1. Install [RVM ("Ruby Version Manager")](http://rvm.io/) or a Ruby manager of your choice. You can find more at [here](https://www.ruby-lang.org/en/documentation/installation/)
|
16
|
-
2. Choose between Ruby versions `2.
|
16
|
+
2. Choose between Ruby versions `2.7.X`, `3.0.X`, `3.1.X`. Our preferred version is `2.7.6`.
|
17
17
|
3. Verify you're running a valid ruby version. Do this by running either `ruby -v` or the commands within your version manager. i.e., `rvm current` if you have installed RVM.
|
18
18
|
4. For Windows you need tzinfo-data gem installed as well. `gem install tzinfo-data`
|
19
19
|
5. SDK depends on `charlock_holmes` gem. Check [gem's documentation](https://github.com/brianmario/charlock_holmes#installing) if you have troubles when install this dependency. Additional [details for Windows](https://github.com/brianmario/charlock_holmes/issues/84#issuecomment-652877605)
|
@@ -1124,7 +1124,7 @@ jobs:
|
|
1124
1124
|
runs-on: ubuntu-latest
|
1125
1125
|
strategy:
|
1126
1126
|
matrix:
|
1127
|
-
ruby-version: ['2.
|
1127
|
+
ruby-version: ['2.7', '3.0', '3.1']
|
1128
1128
|
|
1129
1129
|
steps:
|
1130
1130
|
- uses: actions/checkout@v2
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.3.0
|
@@ -3,6 +3,8 @@
|
|
3
3
|
|
4
4
|
require 'active_support/encrypted_configuration'
|
5
5
|
|
6
|
+
require_relative '../extension/metadata_fix_wrap_kw_args'
|
7
|
+
|
6
8
|
module Workato
|
7
9
|
module CLI
|
8
10
|
class EditCommand
|
@@ -23,7 +25,7 @@ module Workato
|
|
23
25
|
|
24
26
|
catch_editing_exceptions do
|
25
27
|
encrypted_config.change do |tmp_path|
|
26
|
-
system("#{ENV
|
28
|
+
system("#{ENV.fetch('EDITOR', nil)} #{tmp_path}")
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
@@ -1,9 +1,12 @@
|
|
1
|
-
# typed:
|
1
|
+
# typed: true
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'thor'
|
5
|
+
require 'active_support/json'
|
5
6
|
require_relative './multi_auth_selected_fallback'
|
6
7
|
|
8
|
+
Method.prepend(T::CompatibilityPatches::MethodExtensions)
|
9
|
+
|
7
10
|
module Workato
|
8
11
|
module CLI
|
9
12
|
class ExecCommand
|
@@ -21,7 +24,7 @@ module Workato
|
|
21
24
|
load_from_default_files
|
22
25
|
inspect_params(params)
|
23
26
|
output = with_progress { execute_path }
|
24
|
-
show_output(output)
|
27
|
+
show_output(output.as_json)
|
25
28
|
output
|
26
29
|
end
|
27
30
|
|
@@ -65,8 +68,12 @@ module Workato
|
|
65
68
|
oauth2_code: options[:oauth2_code],
|
66
69
|
redirect_url: options[:redirect_url],
|
67
70
|
refresh_token: options[:refresh_token],
|
71
|
+
from: options[:from].to_i,
|
72
|
+
frame_size: options[:frame_size]&.to_i || Workato::Connector::Sdk::Stream::DEFAULT_FRAME_SIZE,
|
68
73
|
recipe_id: Workato::Connector::Sdk::Operation.recipe_id!
|
69
|
-
}
|
74
|
+
}.tap do |h|
|
75
|
+
h[:to] = h[:from] + h[:frame_size] - 1
|
76
|
+
end
|
70
77
|
end
|
71
78
|
|
72
79
|
def connector
|
@@ -94,9 +101,10 @@ module Workato
|
|
94
101
|
end
|
95
102
|
end
|
96
103
|
|
97
|
-
Workato::Connector::Sdk::Connection.on_settings_update = lambda do |message,
|
104
|
+
Workato::Connector::Sdk::Connection.on_settings_update = lambda do |message, _settings_before, refresher|
|
98
105
|
new_settings = refresher.call
|
99
106
|
break unless new_settings
|
107
|
+
break new_settings if @settings == new_settings
|
100
108
|
|
101
109
|
with_user_interaction do
|
102
110
|
loop do
|
@@ -105,6 +113,7 @@ module Workato
|
|
105
113
|
break new_settings if %w[n no].include?(answer)
|
106
114
|
next unless %w[y yes].include?(answer)
|
107
115
|
|
116
|
+
@settings.merge!(new_settings)
|
108
117
|
settings_store.update(new_settings)
|
109
118
|
break new_settings
|
110
119
|
end
|
@@ -135,11 +144,11 @@ module Workato
|
|
135
144
|
end
|
136
145
|
|
137
146
|
def execute_path
|
138
|
-
|
147
|
+
InvokePath.new(path: path, connector: connector, params: params).call
|
139
148
|
rescue Workato::Connector::Sdk::InvalidMultiAuthDefinition => e
|
140
|
-
raise "#{e.message}. Please ensure:\n"\
|
149
|
+
raise "#{e.message}. Please ensure:\n" \
|
141
150
|
"- 'selected' block is defined and returns value from 'options' list\n" \
|
142
|
-
"- settings file contains value expected by 'selected' block\n\n"\
|
151
|
+
"- settings file contains value expected by 'selected' block\n\n" \
|
143
152
|
'See more: https://docs.workato.com/developing-connectors/sdk/guides/authentication/multi_auth.html'
|
144
153
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
145
154
|
raise DebugExceptionError, e if options[:debug]
|
@@ -149,9 +158,7 @@ module Workato
|
|
149
158
|
|
150
159
|
def show_output(output)
|
151
160
|
if options[:output].present?
|
152
|
-
File.
|
153
|
-
f.write(JSON.dump(output))
|
154
|
-
end
|
161
|
+
File.write(options[:output], JSON.dump(output))
|
155
162
|
elsif options[:output].nil?
|
156
163
|
say('OUTPUT') if verbose?
|
157
164
|
jj output
|
@@ -214,6 +221,65 @@ module Workato
|
|
214
221
|
alias puts log
|
215
222
|
alias print log
|
216
223
|
end
|
224
|
+
|
225
|
+
class InvokePath
|
226
|
+
extend T::Sig
|
227
|
+
|
228
|
+
sig do
|
229
|
+
params(
|
230
|
+
path: String,
|
231
|
+
connector: Workato::Connector::Sdk::Connector,
|
232
|
+
params: T::Hash[Symbol, T.untyped]
|
233
|
+
).void
|
234
|
+
end
|
235
|
+
def initialize(path:, connector:, params:)
|
236
|
+
@path = T.let(path, String)
|
237
|
+
@connector = T.let(connector, Workato::Connector::Sdk::Connector)
|
238
|
+
@params = T.let(params, T::Hash[Symbol, T.untyped])
|
239
|
+
end
|
240
|
+
|
241
|
+
sig { returns(T.untyped) }
|
242
|
+
def call
|
243
|
+
invoke_path
|
244
|
+
end
|
245
|
+
|
246
|
+
private
|
247
|
+
|
248
|
+
sig { returns(String) }
|
249
|
+
attr_reader :path
|
250
|
+
|
251
|
+
sig { returns(Workato::Connector::Sdk::Connector) }
|
252
|
+
attr_reader :connector
|
253
|
+
|
254
|
+
sig { returns(T::Hash[Symbol, T.untyped]) }
|
255
|
+
attr_reader :params
|
256
|
+
|
257
|
+
sig { returns(T.untyped) }
|
258
|
+
def invoke_path
|
259
|
+
methods = path.split('.')
|
260
|
+
method = methods.pop
|
261
|
+
raise ArgumentError, 'path is not found' unless method
|
262
|
+
|
263
|
+
object = methods.inject(connector) { |obj, m| obj.public_send(m) }
|
264
|
+
output = invoke_method(object, method)
|
265
|
+
if output.respond_to?(:invoke)
|
266
|
+
invoke_method(output, :invoke)
|
267
|
+
else
|
268
|
+
output
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
sig { params(object: T.untyped, method: T.any(Symbol, String)).returns(T.untyped) }
|
273
|
+
def invoke_method(object, method)
|
274
|
+
parameters = object.method(method).parameters.reject { |p| p[0] == :block }.map(&:second)
|
275
|
+
args = params.values_at(*parameters)
|
276
|
+
if parameters.last == :args
|
277
|
+
args = args.take(args.length - 1) + Array.wrap(args.last).flatten(1)
|
278
|
+
end
|
279
|
+
object.public_send(method, *args)
|
280
|
+
end
|
281
|
+
end
|
282
|
+
private_constant :InvokePath
|
217
283
|
end
|
218
284
|
end
|
219
285
|
end
|
@@ -51,7 +51,7 @@ module Workato
|
|
51
51
|
default: 'comma'
|
52
52
|
method_option :api_email,
|
53
53
|
type: :string,
|
54
|
-
desc: 'Email for accessing Workato API or '\
|
54
|
+
desc: 'Email for accessing Workato API or ' \
|
55
55
|
"set #{Workato::Connector::Sdk::WORKATO_API_EMAIL_ENV} environment variable"
|
56
56
|
method_option :api_token,
|
57
57
|
type: :string,
|
@@ -125,7 +125,7 @@ module Workato
|
|
125
125
|
end
|
126
126
|
|
127
127
|
def sanitized_filename(name)
|
128
|
-
name.downcase.gsub(/[^0-9A-z
|
128
|
+
name.downcase.gsub(/[^0-9A-z.-]/, '_')
|
129
129
|
end
|
130
130
|
end
|
131
131
|
end
|
data/lib/workato/cli/main.rb
CHANGED
@@ -34,14 +34,14 @@ module Workato
|
|
34
34
|
method_option :connector, type: :string, aliases: '-c', desc: 'Path to connector source code',
|
35
35
|
lazy_default: Workato::Connector::Sdk::DEFAULT_CONNECTOR_PATH
|
36
36
|
method_option :settings, type: :string, aliases: '-s',
|
37
|
-
desc: 'Path to plain or encrypted file with connection configs, '\
|
37
|
+
desc: 'Path to plain or encrypted file with connection configs, ' \
|
38
38
|
'passwords, tokens, secrets etc',
|
39
39
|
lazy_default: Workato::Connector::Sdk::DEFAULT_ENCRYPTED_SETTINGS_PATH
|
40
40
|
method_option :connection, type: :string, aliases: '-n',
|
41
41
|
desc: 'Connection name if settings file contains multiple settings'
|
42
42
|
method_option :key, type: :string, aliases: '-k',
|
43
43
|
lazy_default: Workato::Connector::Sdk::DEFAULT_MASTER_KEY_PATH,
|
44
|
-
desc: "Path to file with encrypt/decrypt key.\n"\
|
44
|
+
desc: "Path to file with encrypt/decrypt key.\n" \
|
45
45
|
"NOTE: key from #{Workato::Connector::Sdk::DEFAULT_MASTER_KEY_ENV} has higher priority"
|
46
46
|
method_option :input, type: :string, aliases: '-i', desc: 'Path to file with input JSON'
|
47
47
|
method_option :closure, type: :string, desc: 'Path to file with next poll closure JSON'
|
@@ -61,6 +61,8 @@ module Workato
|
|
61
61
|
method_option :oauth2_code, type: :string, desc: 'OAuth2 code exchange to tokens pair'
|
62
62
|
method_option :redirect_url, type: :string, desc: 'OAuth2 callback url'
|
63
63
|
method_option :refresh_token, type: :string, desc: 'OAuth2 refresh token'
|
64
|
+
method_option :from, type: :numeric, desc: 'Stream byte offset to read from'
|
65
|
+
method_option :frame_size, type: :numeric, desc: 'Stream chunk read size in bytes. Should be positive'
|
64
66
|
|
65
67
|
method_option :debug, type: :boolean
|
66
68
|
|
@@ -75,7 +77,7 @@ module Workato
|
|
75
77
|
|
76
78
|
method_option :key, type: :string, aliases: '-k',
|
77
79
|
lazy_default: Workato::Connector::Sdk::DEFAULT_MASTER_KEY_PATH,
|
78
|
-
desc: "Path to file with encrypt/decrypt key.\n"\
|
80
|
+
desc: "Path to file with encrypt/decrypt key.\n" \
|
79
81
|
"NOTE: key from #{Workato::Connector::Sdk::DEFAULT_MASTER_KEY_ENV} has higher priority"
|
80
82
|
|
81
83
|
def edit(path)
|
@@ -127,19 +129,19 @@ module Workato
|
|
127
129
|
lazy_default: Workato::Connector::Sdk::DEFAULT_CONNECTOR_PATH
|
128
130
|
method_option :api_email,
|
129
131
|
type: :string,
|
130
|
-
desc: "Email for accessing Workato API.\n"\
|
131
|
-
"If present overrides value from #{Workato::Connector::Sdk::WORKATO_API_EMAIL_ENV} "\
|
132
|
+
desc: "Email for accessing Workato API.\n" \
|
133
|
+
"If present overrides value from #{Workato::Connector::Sdk::WORKATO_API_EMAIL_ENV} " \
|
132
134
|
'environment variable.'
|
133
135
|
method_option :api_token,
|
134
136
|
type: :string,
|
135
137
|
desc: "Token for accessing Workato API.\n" \
|
136
|
-
"If present overrides value from #{Workato::Connector::Sdk::WORKATO_API_TOKEN_ENV} "\
|
138
|
+
"If present overrides value from #{Workato::Connector::Sdk::WORKATO_API_TOKEN_ENV} " \
|
137
139
|
'environment variable.'
|
138
140
|
method_option :environment,
|
139
141
|
type: :string,
|
140
|
-
desc: "Data center specific URL to push connector code.\n"\
|
141
|
-
"If present overrides value from #{Workato::Connector::Sdk::WORKATO_BASE_URL_ENV} "\
|
142
|
-
"environment variable.\n"\
|
142
|
+
desc: "Data center specific URL to push connector code.\n" \
|
143
|
+
"If present overrides value from #{Workato::Connector::Sdk::WORKATO_BASE_URL_ENV} " \
|
144
|
+
"environment variable.\n" \
|
143
145
|
"Examples: 'https://app.workato.com', 'https://app.eu.workato.com'"
|
144
146
|
method_option :folder,
|
145
147
|
type: :string,
|
@@ -171,7 +173,7 @@ module Workato
|
|
171
173
|
type: :string,
|
172
174
|
aliases: '-k',
|
173
175
|
lazy_default: Workato::Connector::Sdk::DEFAULT_MASTER_KEY_PATH,
|
174
|
-
desc: "Path to file with encrypt/decrypt key.\n"\
|
176
|
+
desc: "Path to file with encrypt/decrypt key.\n" \
|
175
177
|
"NOTE: key from #{Workato::Connector::Sdk::DEFAULT_MASTER_KEY_ENV} has higher priority"
|
176
178
|
method_option :port,
|
177
179
|
type: :string,
|
@@ -191,6 +193,11 @@ module Workato
|
|
191
193
|
).call
|
192
194
|
end
|
193
195
|
|
196
|
+
desc 'version', 'Shows gem version'
|
197
|
+
def version
|
198
|
+
puts Workato::Connector::Sdk::VERSION
|
199
|
+
end
|
200
|
+
|
194
201
|
class << self
|
195
202
|
def print_options(shell, options, group_name = nil)
|
196
203
|
return if options.empty?
|
@@ -105,14 +105,14 @@ module Workato
|
|
105
105
|
|
106
106
|
def ensure_oauth2_type
|
107
107
|
unless connector.connection.authorization.oauth2?
|
108
|
-
raise 'Authorization type is not OAuth2. '\
|
109
|
-
'For multi-auth connector ensure correct auth type was used. '\
|
108
|
+
raise 'Authorization type is not OAuth2. ' \
|
109
|
+
'For multi-auth connector ensure correct auth type was used. ' \
|
110
110
|
"Expected: 'oauth2', got: '#{connector.connection.authorization.type}''"
|
111
111
|
end
|
112
112
|
rescue Workato::Connector::Sdk::InvalidMultiAuthDefinition => e
|
113
|
-
raise "#{e.message}. Please ensure:\n"\
|
113
|
+
raise "#{e.message}. Please ensure:\n" \
|
114
114
|
"- 'selected' block is defined and returns value from 'options' list\n" \
|
115
|
-
"- settings file contains value expected by 'selected' block\n\n"\
|
115
|
+
"- settings file contains value expected by 'selected' block\n\n" \
|
116
116
|
'See more: https://docs.workato.com/developing-connectors/sdk/guides/authentication/multi_auth.html'
|
117
117
|
end
|
118
118
|
|
@@ -35,8 +35,8 @@ module Workato
|
|
35
35
|
@api_base_url = ENVIRONMENTS.fetch(options[:environment]) do
|
36
36
|
options[:environment].presence || Workato::Connector::Sdk::WORKATO_BASE_URL
|
37
37
|
end
|
38
|
-
@api_email = options[:api_email] || ENV
|
39
|
-
@api_token = options[:api_token] || ENV
|
38
|
+
@api_email = options[:api_email] || ENV.fetch(Workato::Connector::Sdk::WORKATO_API_EMAIL_ENV, nil)
|
39
|
+
@api_token = options[:api_token] || ENV.fetch(Workato::Connector::Sdk::WORKATO_API_TOKEN_ENV, nil)
|
40
40
|
@folder_id = options[:folder]
|
41
41
|
end
|
42
42
|
|
@@ -12,8 +12,8 @@ module Workato
|
|
12
12
|
API_GENERATE_SCHEMA_PATH = '/api/sdk/generate_schema'
|
13
13
|
|
14
14
|
def initialize(options:)
|
15
|
-
@api_email = options[:api_email] || ENV
|
16
|
-
@api_token = options[:api_token] || ENV
|
15
|
+
@api_email = options[:api_email] || ENV.fetch(Workato::Connector::Sdk::WORKATO_API_EMAIL_ENV, nil)
|
16
|
+
@api_token = options[:api_token] || ENV.fetch(Workato::Connector::Sdk::WORKATO_API_TOKEN_ENV, nil)
|
17
17
|
@options = options
|
18
18
|
end
|
19
19
|
|
@@ -29,9 +29,9 @@ module Workato
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def self.from_csv(path = './account_properties.csv')
|
32
|
-
props = CSV.foreach(path, headers: true, return_headers: false).
|
32
|
+
props = CSV.foreach(path, headers: true, return_headers: false).to_h do |row|
|
33
33
|
[row[0], row[1]]
|
34
|
-
end
|
34
|
+
end
|
35
35
|
instance.load_data(props)
|
36
36
|
end
|
37
37
|
|
@@ -11,29 +11,34 @@ module Workato
|
|
11
11
|
extend T::Sig
|
12
12
|
using BlockInvocationRefinements
|
13
13
|
|
14
|
+
include Dsl::ReinvokeAfter
|
15
|
+
|
14
16
|
RETRY_DEFAULT_CODES = T.let([429, 500, 502, 503, 504, 507].freeze, T::Array[Integer])
|
15
17
|
RETRY_DEFAULT_METHODS = T.let(%i[get head].freeze, T::Array[Symbol])
|
16
18
|
RETRY_DELAY = T.let(5, Integer) # seconds
|
19
|
+
RETRY_DELAY_EXP_BASE = T.let(2, Integer)
|
17
20
|
MAX_RETRIES = 3
|
18
21
|
|
19
|
-
MAX_REINVOKES = 5
|
20
|
-
|
21
22
|
sig do
|
22
23
|
params(
|
23
24
|
action: SorbetTypes::SourceHash,
|
24
25
|
methods: SorbetTypes::SourceHash,
|
25
26
|
connection: Connection,
|
26
|
-
object_definitions: T.nilable(ObjectDefinitions)
|
27
|
+
object_definitions: T.nilable(ObjectDefinitions),
|
28
|
+
streams: Streams
|
27
29
|
).void
|
28
30
|
end
|
29
|
-
def initialize(action:, methods: {}, connection: Connection.new, object_definitions: nil
|
31
|
+
def initialize(action:, methods: {}, connection: Connection.new, object_definitions: nil,
|
32
|
+
streams: ProhibitedStreams.new)
|
30
33
|
super(
|
31
34
|
operation: action,
|
32
35
|
connection: connection,
|
33
36
|
methods: methods,
|
34
|
-
object_definitions: object_definitions
|
37
|
+
object_definitions: object_definitions,
|
38
|
+
streams: streams
|
35
39
|
)
|
36
40
|
|
41
|
+
@retry_delay_factor = T.let(1, Integer)
|
37
42
|
@retries_left = T.let(0, Integer)
|
38
43
|
@retry_codes = T.let([], T::Array[Integer])
|
39
44
|
@retry_methods = T.let([], T::Array[String])
|
@@ -58,33 +63,21 @@ module Workato
|
|
58
63
|
&block)
|
59
64
|
raise InvalidDefinitionError, "'execute' block is required for action" unless block || action[:execute]
|
60
65
|
|
61
|
-
|
62
|
-
|
63
|
-
raise "Max number of reinvokes on SDK Gem reached. Current limit is #{reinvoke_limit}"
|
64
|
-
end
|
65
|
-
|
66
|
-
reinvoke_sleep if @reinvoke_after
|
67
|
-
|
68
|
-
reinvoke_reset
|
69
|
-
|
70
|
-
result = super(
|
66
|
+
loop_reinvoke_after(continue) do |next_continue|
|
67
|
+
return super(
|
71
68
|
settings,
|
72
69
|
input,
|
73
70
|
extended_input_schema,
|
74
71
|
extended_output_schema,
|
75
|
-
|
72
|
+
next_continue,
|
76
73
|
&(block || action[:execute])
|
77
74
|
)
|
78
|
-
|
79
|
-
break result unless @reinvoke_after
|
80
|
-
|
81
|
-
continue = @reinvoke_after.continue
|
82
75
|
end
|
83
|
-
rescue
|
76
|
+
rescue RequestFailedError => e
|
84
77
|
raise e unless retry?(e)
|
85
78
|
|
86
79
|
@retries_left -= 1
|
87
|
-
|
80
|
+
retry_sleep
|
88
81
|
retry
|
89
82
|
end
|
90
83
|
|
@@ -100,32 +93,6 @@ module Workato
|
|
100
93
|
apply_output_schema(output, output_schema)
|
101
94
|
end
|
102
95
|
|
103
|
-
sig do
|
104
|
-
params(
|
105
|
-
continue: T::Hash[T.untyped, T.untyped],
|
106
|
-
temp_output: T.nilable(T::Hash[T.untyped, T.untyped])
|
107
|
-
).void
|
108
|
-
end
|
109
|
-
def checkpoint!(continue:, temp_output: nil)
|
110
|
-
# no-op
|
111
|
-
end
|
112
|
-
|
113
|
-
sig do
|
114
|
-
params(
|
115
|
-
seconds: Integer,
|
116
|
-
continue: T::Hash[T.untyped, T.untyped],
|
117
|
-
temp_output: T.nilable(T::Hash[T.untyped, T.untyped])
|
118
|
-
).void
|
119
|
-
end
|
120
|
-
def reinvoke_after(seconds:, continue:, temp_output: nil) # rubocop:disable Lint/UnusedMethodArgument
|
121
|
-
@reinvokes_remaining = T.let(@reinvokes_remaining, T.nilable(Integer))
|
122
|
-
@reinvokes_remaining = (@reinvokes_remaining ? @reinvokes_remaining - 1 : reinvoke_limit)
|
123
|
-
@reinvoke_after = ReinvokeAfter.new(
|
124
|
-
seconds: seconds,
|
125
|
-
continue: continue
|
126
|
-
)
|
127
|
-
end
|
128
|
-
|
129
96
|
private
|
130
97
|
|
131
98
|
sig { returns(T::Array[T.any(Symbol, String, Regexp, Integer)]) }
|
@@ -150,10 +117,10 @@ module Workato
|
|
150
117
|
retry_on_response.each { |m| m.is_a?(::Integer) ? @retry_codes << m : @retry_matchers << m }
|
151
118
|
@retry_codes = RETRY_DEFAULT_CODES if @retry_codes.empty?
|
152
119
|
@retry_methods = (retry_on_request.presence || RETRY_DEFAULT_METHODS).map(&:to_s).map(&:downcase)
|
153
|
-
@retries_left = [[max_retries.is_a?(::Integer) && max_retries || MAX_RETRIES, MAX_RETRIES].min, 0].max
|
120
|
+
@retries_left = [[(max_retries.is_a?(::Integer) && max_retries) || MAX_RETRIES, MAX_RETRIES].min, 0].max
|
154
121
|
end
|
155
122
|
|
156
|
-
sig { params(exception:
|
123
|
+
sig { params(exception: RequestFailedError).returns(T::Boolean) }
|
157
124
|
def retry?(exception)
|
158
125
|
return false unless @retries_left.positive?
|
159
126
|
return false unless @retry_codes.include?(exception.code.to_i)
|
@@ -165,28 +132,11 @@ module Workato
|
|
165
132
|
end
|
166
133
|
|
167
134
|
sig { void }
|
168
|
-
def
|
169
|
-
sleep(
|
170
|
-
|
171
|
-
|
172
|
-
sig { returns(Integer) }
|
173
|
-
def reinvoke_limit
|
174
|
-
@reinvoke_limit = T.let(@reinvoke_limit, T.nilable(Integer))
|
175
|
-
@reinvoke_limit ||= (ENV['MAX_REINVOKES'].presence || MAX_REINVOKES).to_i
|
176
|
-
end
|
177
|
-
|
178
|
-
sig { void }
|
179
|
-
def reinvoke_reset
|
180
|
-
@reinvoke_after = T.let(nil, T.nilable(ReinvokeAfter))
|
135
|
+
def retry_sleep
|
136
|
+
sleep(@retry_delay_factor * RETRY_DELAY)
|
137
|
+
@retry_delay_factor *= RETRY_DELAY_EXP_BASE
|
181
138
|
end
|
182
139
|
|
183
|
-
class ReinvokeAfter < T::Struct
|
184
|
-
prop :seconds, T.any(Float, Integer)
|
185
|
-
prop :continue, T::Hash[T.untyped, T.untyped]
|
186
|
-
end
|
187
|
-
|
188
|
-
private_constant :ReinvokeAfter
|
189
|
-
|
190
140
|
alias action operation
|
191
141
|
end
|
192
142
|
end
|
@@ -6,25 +6,17 @@ module Workato
|
|
6
6
|
module Sdk
|
7
7
|
# match proc's arguments, even if it's a lambda.
|
8
8
|
module BlockInvocationRefinements
|
9
|
-
|
9
|
+
refine Proc do
|
10
10
|
def call(*args, &block)
|
11
11
|
super(*args.take(parameters.length), &block)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
refine
|
16
|
-
prepend CallRefinement
|
17
|
-
end
|
18
|
-
|
19
|
-
module InstanceExecRefinement
|
15
|
+
refine BasicObject do
|
20
16
|
def instance_exec(*args, &block)
|
21
17
|
super(*args.take(block.parameters.length), &block)
|
22
18
|
end
|
23
19
|
end
|
24
|
-
|
25
|
-
refine BasicObject do
|
26
|
-
prepend InstanceExecRefinement
|
27
|
-
end
|
28
20
|
end
|
29
21
|
end
|
30
22
|
end
|