cloudtasker 0.12.rc7 → 0.12.rc8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96524dc4a6825a3760a462277f7b0a710d779521e759bce44374ea044dbd649d
4
- data.tar.gz: 908f1497b7ad316549f4f347c363b183181f0e0a17a92bda3f50ac9c34e2247c
3
+ metadata.gz: 6ac7405c882f6cc73a1d18d5f0ffd4aaf1032d2b22973b03ac0c05b579321d47
4
+ data.tar.gz: ab4e12890ba7f1cf2f8cfde952a532f8563998352ba3c0ba348f8253c0f562b4
5
5
  SHA512:
6
- metadata.gz: e18579d27321e09f1e997ad3fdd3e3e0d1d0c344cd5fc553b64f665937fbe510cd11957381eee1fee5c100e2f14d8390434f26c60307fec4ecf4a681b15885d8
7
- data.tar.gz: 3b688838f1a518f2f5c7b914a590f035d8a828c2c2b67838173a1712b8765e2ce34cddb8ddf1214aaefc26ce8ec43b7cc1dbe4eb450ccb24feb9e06bcd19bac7
6
+ metadata.gz: 99a740769048aa11f4a7b2a3710ed98973c44c7d9fa5e059b37027f408d10e5c731cd01e28bbf7e0e2cc4df49290384fdbc073d4a7869d511af661d8c5363e1b
7
+ data.tar.gz: 4214ca35db358f7f027cad6fe0e36353034789c3969726484c2af50cc019a34ce03840718609aa6941ab5a8d1d6b312f174d884a9c88a2e112c4219f6e1a26d8
data/.rubocop.yml CHANGED
@@ -12,7 +12,7 @@ Metrics/ModuleLength:
12
12
  Max: 150
13
13
 
14
14
  Metrics/AbcSize:
15
- Max: 20
15
+ Max: 25
16
16
  Exclude:
17
17
  - 'spec/support/*'
18
18
 
data/CHANGELOG.md CHANGED
@@ -1,11 +1,12 @@
1
1
  # Changelog
2
2
 
3
- ## Latest RC [v0.12.rc7](https://github.com/keypup-io/cloudtasker/tree/v0.12.rc7) (2021-03-31)
3
+ ## Latest RC [v0.12.rc8](https://github.com/keypup-io/cloudtasker/tree/v0.12.rc8) (2021-04-06)
4
4
 
5
- [Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.11.0...v0.12.rc7)
5
+ [Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.11.0...v0.12.rc8)
6
6
 
7
7
  **Improvements:**
8
8
  - ActiveJob: do not double log errors (ActiveJob has its own error logging)
9
+ - Configuration: allow configuration of Cloud Tasks `dispatch deadline` at global and worker level
9
10
  - Cron jobs: Use Redis Sets instead of key pattern matching for resource listing
10
11
  - Error logging: Use worker logger so as to include context (job args etc.)
11
12
  - Error logging: Do not log exception and stack trace separately, combine them instead.
data/README.md CHANGED
@@ -37,6 +37,7 @@ A local processing server is also available for development. This local server p
37
37
  1. [HTTP Error codes](#http-error-codes)
38
38
  2. [Error callbacks](#error-callbacks)
39
39
  3. [Max retries](#max-retries)
40
+ 4. [Dispatch deadline](#dispatch-deadline)
40
41
  10. [Testing](#testing)
41
42
  1. [Test helper setup](#test-helper-setup)
42
43
  2. [In-memory queues](#in-memory-queues)
@@ -351,6 +352,23 @@ Cloudtasker.configure do |config|
351
352
  #
352
353
  # Store all job payloads in Redis exceeding 50 KB:
353
354
  # config.store_payloads_in_redis = 50
355
+
356
+ #
357
+ # Specify the dispatch deadline for jobs in Cloud Tasks, in seconds.
358
+ # Jobs taking longer will be retried by Cloud Tasks, even if they eventually
359
+ # complete on the server side.
360
+ #
361
+ # Note that this option is applied when jobs are enqueued job. Changing this value
362
+ # will not impact already enqueued jobs.
363
+ #
364
+ # This option can also be configured on a per worker basis via
365
+ # the cloudtasker_options directive.
366
+ #
367
+ # Supported since: v0.12.rc8
368
+ #
369
+ # Default: 600 seconds (10 minutes)
370
+ #
371
+ # config.dispatch_deadline = 600
354
372
  end
355
373
  ```
356
374
 
@@ -721,6 +739,48 @@ class SomeErrorWorker
721
739
  end
722
740
  ```
723
741
 
742
+ ### Dispatch deadline
743
+ **Supported since**: `0.12.rc8`
744
+
745
+ By default Cloud Tasks will automatically timeout your jobs after 10 minutes, independently of your server HTTP timeout configuration.
746
+
747
+ You can modify the dispatch deadline for jobs at a global level or on a per job basis.
748
+
749
+ E.g. Set the default dispatch deadline to 20 minutes.
750
+ ```ruby
751
+ # config/initializers/cloudtasker.rb
752
+
753
+ Cloudtasker.configure do |config|
754
+ #
755
+ # Specify the dispatch deadline for jobs in Cloud Tasks, in seconds.
756
+ # Jobs taking longer will be retried by Cloud Tasks, even if they eventually
757
+ # complete on the server side.
758
+ #
759
+ # Note that this option is applied when jobs are enqueued job. Changing this value
760
+ # will not impact already enqueued jobs.
761
+ #
762
+ # Default: 600 (10 minutes)
763
+ #
764
+ config.dispatch_deadline = 20 * 60 # 20 minutes
765
+ end
766
+ ```
767
+
768
+ E.g. Set a dispatch deadline of 5 minutes on a specific worker
769
+ ```ruby
770
+ # app/workers/some_error_worker.rb
771
+
772
+ class SomeFasterWorker
773
+ include Cloudtasker::Worker
774
+
775
+ # This will override the global setting
776
+ cloudtasker_options dispatch_deadline: 5 * 60
777
+
778
+ def perform
779
+ # ... do things ...
780
+ end
781
+ end
782
+ ```
783
+
724
784
  ## Testing
725
785
  Cloudtasker provides several options to test your workers.
726
786
 
@@ -113,7 +113,7 @@ module Cloudtasker
113
113
  # @param [Hash] http_request The HTTP request content.
114
114
  # @param [Integer] schedule_time When to run the task (Unix timestamp)
115
115
  #
116
- def initialize(id:, http_request:, schedule_time: nil, queue: nil, job_retries: 0)
116
+ def initialize(id:, http_request:, schedule_time: nil, queue: nil, job_retries: 0, **_xargs)
117
117
  @id = id
118
118
  @http_request = http_request
119
119
  @schedule_time = Time.at(schedule_time || 0)
@@ -7,7 +7,7 @@ module Cloudtasker
7
7
  module Backend
8
8
  # Manage local tasks pushed to Redis
9
9
  class RedisTask
10
- attr_reader :id, :http_request, :schedule_time, :retries, :queue
10
+ attr_reader :id, :http_request, :schedule_time, :retries, :queue, :dispatch_deadline
11
11
 
12
12
  RETRY_INTERVAL = 20 # seconds
13
13
 
@@ -123,13 +123,15 @@ module Cloudtasker
123
123
  # @param [Hash] http_request The HTTP request content.
124
124
  # @param [Integer] schedule_time When to run the task (Unix timestamp)
125
125
  # @param [Integer] retries The number of times the job failed.
126
+ # @param [Integer] dispatch_deadline The dispatch_deadline in seconds.
126
127
  #
127
- def initialize(id:, http_request:, schedule_time: nil, retries: 0, queue: nil)
128
+ def initialize(id:, http_request:, schedule_time: nil, retries: 0, queue: nil, dispatch_deadline: nil)
128
129
  @id = id
129
130
  @http_request = http_request
130
131
  @schedule_time = Time.at(schedule_time || 0)
131
132
  @retries = retries || 0
132
- @queue = queue || Cloudtasker::Config::DEFAULT_JOB_QUEUE
133
+ @queue = queue || Config::DEFAULT_JOB_QUEUE
134
+ @dispatch_deadline = dispatch_deadline || Config::DEFAULT_DISPATCH_DEADLINE
133
135
  end
134
136
 
135
137
  #
@@ -152,7 +154,8 @@ module Cloudtasker
152
154
  http_request: http_request,
153
155
  schedule_time: schedule_time.to_i,
154
156
  retries: retries,
155
- queue: queue
157
+ queue: queue,
158
+ dispatch_deadline: dispatch_deadline
156
159
  }
157
160
  end
158
161
 
@@ -176,7 +179,8 @@ module Cloudtasker
176
179
  retries: is_error ? retries + 1 : retries,
177
180
  http_request: http_request,
178
181
  schedule_time: (Time.now + interval).to_i,
179
- queue: queue
182
+ queue: queue,
183
+ dispatch_deadline: dispatch_deadline
180
184
  )
181
185
  redis.sadd(self.class.key, id)
182
186
  end
@@ -207,6 +211,13 @@ module Cloudtasker
207
211
  end
208
212
 
209
213
  resp
214
+ rescue Net::ReadTimeout
215
+ retry_later(RETRY_INTERVAL)
216
+ Cloudtasker.logger.info(
217
+ format_log_message(
218
+ "Task deadline exceeded (#{dispatch_deadline}s) - Retry in #{RETRY_INTERVAL} seconds..."
219
+ )
220
+ )
210
221
  end
211
222
 
212
223
  #
@@ -242,7 +253,7 @@ module Cloudtasker
242
253
  @http_client ||=
243
254
  begin
244
255
  uri = URI(http_request[:url])
245
- Net::HTTP.new(uri.host, uri.port).tap { |e| e.read_timeout = 60 * 10 }
256
+ Net::HTTP.new(uri.host, uri.port).tap { |e| e.read_timeout = dispatch_deadline }
246
257
  end
247
258
  end
248
259
 
@@ -3,7 +3,7 @@
3
3
  module Cloudtasker
4
4
  # An interface class to manage tasks on the backend (Cloud Task or Redis)
5
5
  class CloudTask
6
- attr_accessor :id, :http_request, :schedule_time, :retries, :queue
6
+ attr_accessor :id, :http_request, :schedule_time, :retries, :queue, :dispatch_deadline
7
7
 
8
8
  #
9
9
  # The backend to use for cloud tasks.
@@ -73,12 +73,13 @@ module Cloudtasker
73
73
  # @param [Integer] retries The number of times the job failed.
74
74
  # @param [String] queue The queue the task is in.
75
75
  #
76
- def initialize(id:, http_request:, schedule_time: nil, retries: 0, queue: nil)
76
+ def initialize(id:, http_request:, schedule_time: nil, retries: 0, queue: nil, dispatch_deadline: nil)
77
77
  @id = id
78
78
  @http_request = http_request
79
79
  @schedule_time = schedule_time
80
80
  @retries = retries || 0
81
81
  @queue = queue
82
+ @dispatch_deadline = dispatch_deadline
82
83
  end
83
84
 
84
85
  #
@@ -7,7 +7,7 @@ module Cloudtasker
7
7
  class Config
8
8
  attr_accessor :redis, :store_payloads_in_redis
9
9
  attr_writer :secret, :gcp_location_id, :gcp_project_id,
10
- :gcp_queue_prefix, :processor_path, :logger, :mode, :max_retries
10
+ :gcp_queue_prefix, :processor_path, :logger, :mode, :max_retries, :dispatch_deadline
11
11
 
12
12
  # Max Cloud Task size in bytes
13
13
  MAX_TASK_SIZE = 100 * 1024 # 100 KB
@@ -46,6 +46,11 @@ module Cloudtasker
46
46
  DEFAULT_QUEUE_CONCURRENCY = 10
47
47
  DEFAULT_QUEUE_RETRIES = -1 # unlimited
48
48
 
49
+ # Job timeout configuration for Cloud Tasks
50
+ DEFAULT_DISPATCH_DEADLINE = 10 * 60 # 10 minutes
51
+ MIN_DISPATCH_DEADLINE = 15 # seconds
52
+ MAX_DISPATCH_DEADLINE = 30 * 60 # 30 minutes
53
+
49
54
  # The number of times jobs will be attempted before declaring them dead.
50
55
  #
51
56
  # With the default retry configuration (maxDoublings = 16 and minBackoff = 0.100s)
@@ -207,6 +212,16 @@ module Cloudtasker
207
212
  @gcp_location_id || DEFAULT_LOCATION_ID
208
213
  end
209
214
 
215
+ #
216
+ # Return the Dispatch deadline duration. Cloud Tasks will timeout the job after
217
+ # this duration is elapsed.
218
+ #
219
+ # @return [Integer] The value in seconds.
220
+ #
221
+ def dispatch_deadline
222
+ @dispatch_deadline || DEFAULT_DISPATCH_DEADLINE
223
+ end
224
+
210
225
  #
211
226
  # Return the secret to use to sign the verification tokens
212
227
  # attached to tasks.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cloudtasker
4
- VERSION = '0.12.rc7'
4
+ VERSION = '0.12.rc8'
5
5
  end
@@ -167,6 +167,22 @@ module Cloudtasker
167
167
  (@job_queue ||= self.class.cloudtasker_options_hash[:queue] || Config::DEFAULT_JOB_QUEUE).to_s
168
168
  end
169
169
 
170
+ #
171
+ # Return the Dispatch deadline duration. Cloud Tasks will timeout the job after
172
+ # this duration is elapsed.
173
+ #
174
+ # @return [Integer] The value in seconds.
175
+ #
176
+ def dispatch_deadline
177
+ @dispatch_deadline ||= [
178
+ [
179
+ Config::MIN_DISPATCH_DEADLINE,
180
+ (self.class.cloudtasker_options_hash[:dispatch_deadline] || Cloudtasker.config.dispatch_deadline).to_i
181
+ ].max,
182
+ Config::MAX_DISPATCH_DEADLINE
183
+ ].min
184
+ end
185
+
170
186
  #
171
187
  # Return the Cloudtasker logger instance.
172
188
  #
@@ -165,6 +165,7 @@ module Cloudtasker
165
165
  },
166
166
  body: worker_payload.to_json
167
167
  },
168
+ dispatch_deadline: worker.dispatch_deadline.to_i,
168
169
  queue: worker.job_queue
169
170
  }
170
171
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudtasker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.rc7
4
+ version: 0.12.rc8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arnaud Lachaume
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-31 00:00:00.000000000 Z
11
+ date: 2021-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport