cloudtasker 0.12.rc11 → 0.13.rc1

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/lint_rubocop.yml +20 -0
  3. data/.github/workflows/{test.yml → test_ruby_2.5_2.6.yml} +8 -13
  4. data/.github/workflows/test_ruby_2.7.yml +40 -0
  5. data/.github/workflows/test_ruby_3.x.yml +39 -0
  6. data/.rubocop.yml +5 -0
  7. data/Appraisals +20 -0
  8. data/CHANGELOG.md +52 -3
  9. data/README.md +15 -7
  10. data/Rakefile +0 -6
  11. data/app/controllers/cloudtasker/worker_controller.rb +4 -1
  12. data/cloudtasker.gemspec +0 -5
  13. data/docs/BATCH_JOBS.md +2 -2
  14. data/docs/CRON_JOBS.md +39 -0
  15. data/gemfiles/google_cloud_tasks_1.0.gemfile +1 -0
  16. data/gemfiles/google_cloud_tasks_1.0.gemfile.lock +43 -205
  17. data/gemfiles/google_cloud_tasks_1.1.gemfile +1 -0
  18. data/gemfiles/google_cloud_tasks_1.1.gemfile.lock +43 -205
  19. data/gemfiles/google_cloud_tasks_1.2.gemfile +1 -0
  20. data/gemfiles/google_cloud_tasks_1.2.gemfile.lock +43 -205
  21. data/gemfiles/google_cloud_tasks_1.3.gemfile +1 -0
  22. data/gemfiles/google_cloud_tasks_1.3.gemfile.lock +43 -205
  23. data/gemfiles/rails_5.2.gemfile +1 -0
  24. data/gemfiles/rails_5.2.gemfile.lock +54 -96
  25. data/gemfiles/rails_6.0.gemfile +1 -0
  26. data/gemfiles/rails_6.0.gemfile.lock +55 -97
  27. data/gemfiles/rails_6.1.gemfile +8 -0
  28. data/gemfiles/rails_7.0.gemfile +8 -0
  29. data/gemfiles/semantic_logger_3.4.gemfile +1 -0
  30. data/gemfiles/semantic_logger_4.6.gemfile +1 -0
  31. data/gemfiles/semantic_logger_4.7.0.gemfile +1 -0
  32. data/gemfiles/semantic_logger_4.7.2.gemfile +1 -0
  33. data/lib/cloudtasker/backend/google_cloud_task.rb +12 -8
  34. data/lib/cloudtasker/backend/memory_task.rb +1 -1
  35. data/lib/cloudtasker/backend/redis_task.rb +7 -3
  36. data/lib/cloudtasker/cloud_task.rb +2 -2
  37. data/lib/cloudtasker/cron/schedule.rb +7 -7
  38. data/lib/cloudtasker/local_server.rb +1 -1
  39. data/lib/cloudtasker/redis_client.rb +39 -14
  40. data/lib/cloudtasker/unique_job/job.rb +3 -2
  41. data/lib/cloudtasker/unique_job/middleware/client.rb +2 -1
  42. data/lib/cloudtasker/version.rb +1 -1
  43. data/lib/cloudtasker/worker.rb +4 -4
  44. data/lib/cloudtasker/worker_wrapper.rb +1 -1
  45. data/lib/cloudtasker.rb +1 -0
  46. metadata +9 -61
  47. data/app/controllers/cloudtasker/application_controller.rb +0 -8
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- cloudtasker (0.12.rc11)
4
+ cloudtasker (0.13.rc1)
5
5
  activesupport
6
6
  connection_pool
7
7
  fugit
@@ -68,111 +68,86 @@ GEM
68
68
  minitest (~> 5.1)
69
69
  tzinfo (~> 1.1)
70
70
  zeitwerk (~> 2.1, >= 2.1.8)
71
- addressable (2.7.0)
71
+ addressable (2.8.0)
72
72
  public_suffix (>= 2.0.2, < 5.0)
73
- appraisal (2.4.0)
73
+ appraisal (2.4.1)
74
74
  bundler
75
75
  rake
76
76
  thor (>= 0.14.0)
77
77
  ast (2.4.2)
78
- async (1.29.1)
79
- console (~> 1.10)
80
- nio4r (~> 2.3)
81
- timers (~> 4.1)
82
- async-http (0.56.3)
83
- async (~> 1.25)
84
- async-io (~> 1.28)
85
- async-pool (~> 0.2)
86
- protocol-http (~> 0.22.0)
87
- protocol-http1 (~> 0.14.0)
88
- protocol-http2 (~> 0.14.0)
89
- async-http-faraday (0.11.0)
90
- async-http (~> 0.42)
91
- faraday
92
- async-io (1.32.1)
93
- async (~> 1.14)
94
- async-pool (0.3.7)
95
- async (~> 1.25)
96
78
  builder (3.2.4)
97
79
  concurrent-ruby (1.1.9)
98
80
  connection_pool (2.2.5)
99
- console (1.13.1)
100
- fiber-local
101
81
  crack (0.4.5)
102
82
  rexml
103
83
  crass (1.0.6)
104
- diff-lcs (1.4.4)
84
+ diff-lcs (1.5.0)
105
85
  erubi (1.10.0)
106
- et-orbi (1.2.4)
86
+ et-orbi (1.2.6)
107
87
  tzinfo
108
- faraday (1.4.3)
88
+ faraday (1.8.0)
109
89
  faraday-em_http (~> 1.0)
110
90
  faraday-em_synchrony (~> 1.0)
111
91
  faraday-excon (~> 1.1)
92
+ faraday-httpclient (~> 1.0.1)
112
93
  faraday-net_http (~> 1.0)
113
94
  faraday-net_http_persistent (~> 1.1)
95
+ faraday-patron (~> 1.0)
96
+ faraday-rack (~> 1.0)
114
97
  multipart-post (>= 1.2, < 3)
115
98
  ruby2_keywords (>= 0.0.4)
116
99
  faraday-em_http (1.0.0)
117
100
  faraday-em_synchrony (1.0.0)
118
101
  faraday-excon (1.1.0)
119
- faraday-http-cache (2.2.0)
120
- faraday (>= 0.8)
102
+ faraday-httpclient (1.0.1)
121
103
  faraday-net_http (1.0.1)
122
- faraday-net_http_persistent (1.1.0)
123
- fiber-local (1.0.0)
124
- fugit (1.5.0)
104
+ faraday-net_http_persistent (1.2.0)
105
+ faraday-patron (1.0.0)
106
+ faraday-rack (1.0.0)
107
+ fugit (1.5.2)
125
108
  et-orbi (~> 1.1, >= 1.1.8)
126
109
  raabro (~> 1.4)
127
- github_changelog_generator (1.16.4)
128
- activesupport
129
- async (>= 1.25.0)
130
- async-http-faraday
131
- faraday-http-cache
132
- multi_json
133
- octokit (~> 4.6)
134
- rainbow (>= 2.2.1)
135
- rake (>= 10.0)
136
- globalid (0.4.2)
137
- activesupport (>= 4.2.0)
110
+ globalid (1.0.0)
111
+ activesupport (>= 5.0)
138
112
  google-cloud-tasks (1.5.1)
139
113
  google-gax (~> 1.8)
140
114
  googleapis-common-protos (>= 1.3.9, < 2.0)
141
115
  googleapis-common-protos-types (>= 1.0.4, < 2.0)
142
116
  grpc-google-iam-v1 (~> 0.6.9)
143
- google-gax (1.8.1)
117
+ google-gax (1.8.2)
144
118
  google-protobuf (~> 3.9)
145
119
  googleapis-common-protos (>= 1.3.9, < 2.0)
120
+ googleapis-common-protos-types (>= 1.0.4, < 2.0)
146
121
  googleauth (~> 0.9)
147
122
  grpc (~> 1.24)
148
123
  rly (~> 0.2.3)
149
- google-protobuf (3.17.3)
150
- googleapis-common-protos (1.3.11)
124
+ google-protobuf (3.19.1-x86_64-darwin)
125
+ googleapis-common-protos (1.3.12)
151
126
  google-protobuf (~> 3.14)
152
- googleapis-common-protos-types (>= 1.0.6, < 2.0)
127
+ googleapis-common-protos-types (~> 1.2)
153
128
  grpc (~> 1.27)
154
- googleapis-common-protos-types (1.0.6)
129
+ googleapis-common-protos-types (1.3.0)
155
130
  google-protobuf (~> 3.14)
156
- googleauth (0.16.2)
131
+ googleauth (0.17.1)
157
132
  faraday (>= 0.17.3, < 2.0)
158
133
  jwt (>= 1.4, < 3.0)
159
134
  memoist (~> 0.16)
160
135
  multi_json (~> 1.11)
161
136
  os (>= 0.9, < 2.0)
162
- signet (~> 0.14)
163
- grpc (1.38.0)
164
- google-protobuf (~> 3.15)
137
+ signet (~> 0.15)
138
+ grpc (1.42.0-x86_64-darwin)
139
+ google-protobuf (~> 3.18)
165
140
  googleapis-common-protos-types (~> 1.0)
166
141
  grpc-google-iam-v1 (0.6.11)
167
142
  google-protobuf (~> 3.14)
168
143
  googleapis-common-protos (>= 1.3.11, < 2.0)
169
144
  grpc (~> 1.27)
170
145
  hashdiff (1.0.1)
171
- i18n (1.8.10)
146
+ i18n (1.8.11)
172
147
  concurrent-ruby (~> 1.0)
173
148
  jaro_winkler (1.5.4)
174
- jwt (2.2.3)
175
- loofah (2.10.0)
149
+ jwt (2.3.0)
150
+ loofah (2.13.0)
176
151
  crass (~> 1.0.2)
177
152
  nokogiri (>= 1.5.9)
178
153
  mail (2.7.1)
@@ -184,32 +159,22 @@ GEM
184
159
  mimemagic (0.3.10)
185
160
  nokogiri (~> 1)
186
161
  rake
187
- mini_mime (1.1.0)
188
- mini_portile2 (2.5.3)
189
- minitest (5.14.4)
162
+ mini_mime (1.1.2)
163
+ mini_portile2 (2.6.1)
164
+ minitest (5.15.0)
190
165
  multi_json (1.15.0)
191
166
  multipart-post (2.1.1)
192
- nio4r (2.5.7)
193
- nokogiri (1.11.7)
194
- mini_portile2 (~> 2.5.0)
167
+ nio4r (2.5.8)
168
+ nokogiri (1.12.5)
169
+ mini_portile2 (~> 2.6.1)
195
170
  racc (~> 1.4)
196
- octokit (4.21.0)
197
- faraday (>= 0.9)
198
- sawyer (~> 0.8.0, >= 0.5.3)
199
- os (1.1.1)
200
- parallel (1.20.1)
201
- parser (3.0.1.1)
171
+ os (1.1.4)
172
+ parallel (1.21.0)
173
+ parser (3.0.3.2)
202
174
  ast (~> 2.4.1)
203
- protocol-hpack (1.4.2)
204
- protocol-http (0.22.4)
205
- protocol-http1 (0.14.1)
206
- protocol-http (~> 0.22)
207
- protocol-http2 (0.14.2)
208
- protocol-hpack (~> 1.4)
209
- protocol-http (~> 0.18)
210
175
  public_suffix (4.0.6)
211
176
  raabro (1.4.0)
212
- racc (1.5.2)
177
+ racc (1.6.0)
213
178
  rack (2.2.3)
214
179
  rack-test (1.1.0)
215
180
  rack (>= 1.0, < 3)
@@ -231,7 +196,7 @@ GEM
231
196
  rails-dom-testing (2.0.3)
232
197
  activesupport (>= 4.2.0)
233
198
  nokogiri (>= 1.6)
234
- rails-html-sanitizer (1.3.0)
199
+ rails-html-sanitizer (1.4.2)
235
200
  loofah (~> 2.3)
236
201
  railties (6.0.0)
237
202
  actionpack (= 6.0.0)
@@ -240,8 +205,8 @@ GEM
240
205
  rake (>= 0.8.7)
241
206
  thor (>= 0.20.3, < 2.0)
242
207
  rainbow (3.0.0)
243
- rake (13.0.3)
244
- redis (4.3.1)
208
+ rake (13.0.6)
209
+ redis (4.5.1)
245
210
  retriable (3.1.2)
246
211
  rexml (3.2.5)
247
212
  rly (0.2.3)
@@ -258,7 +223,7 @@ GEM
258
223
  rspec-mocks (3.10.2)
259
224
  diff-lcs (>= 1.2.0, < 2.0)
260
225
  rspec-support (~> 3.10.0)
261
- rspec-rails (5.0.1)
226
+ rspec-rails (5.0.2)
262
227
  actionpack (>= 5.2)
263
228
  activesupport (>= 5.2)
264
229
  railties (>= 5.2)
@@ -266,7 +231,7 @@ GEM
266
231
  rspec-expectations (~> 3.10)
267
232
  rspec-mocks (~> 3.10)
268
233
  rspec-support (~> 3.10)
269
- rspec-support (3.10.2)
234
+ rspec-support (3.10.3)
270
235
  rubocop (0.76.0)
271
236
  jaro_winkler (~> 1.5.1)
272
237
  parallel (~> 1.10)
@@ -277,40 +242,35 @@ GEM
277
242
  rubocop-rspec (1.37.0)
278
243
  rubocop (>= 0.68.1)
279
244
  ruby-progressbar (1.11.0)
280
- ruby2_keywords (0.0.4)
281
- sawyer (0.8.2)
282
- addressable (>= 2.3.5)
283
- faraday (> 0.8, < 2.0)
284
- semantic_logger (4.8.0)
245
+ ruby2_keywords (0.0.5)
246
+ semantic_logger (4.9.0)
285
247
  concurrent-ruby (~> 1.0)
286
- signet (0.15.0)
287
- addressable (~> 2.3)
248
+ signet (0.16.0)
249
+ addressable (~> 2.8)
288
250
  faraday (>= 0.17.3, < 2.0)
289
251
  jwt (>= 1.5, < 3.0)
290
252
  multi_json (~> 1.10)
291
253
  sprockets (4.0.2)
292
254
  concurrent-ruby (~> 1.0)
293
255
  rack (> 1, < 3)
294
- sprockets-rails (3.2.2)
295
- actionpack (>= 4.0)
296
- activesupport (>= 4.0)
256
+ sprockets-rails (3.4.2)
257
+ actionpack (>= 5.2)
258
+ activesupport (>= 5.2)
297
259
  sprockets (>= 3.0.0)
298
- sqlite3 (1.4.2)
299
260
  thor (1.1.0)
300
261
  thread_safe (0.3.6)
301
262
  timecop (0.9.4)
302
- timers (4.3.3)
303
263
  tzinfo (1.2.9)
304
264
  thread_safe (~> 0.1)
305
265
  unicode-display_width (1.6.1)
306
- webmock (3.13.0)
307
- addressable (>= 2.3.6)
266
+ webmock (3.14.0)
267
+ addressable (>= 2.8.0)
308
268
  crack (>= 0.3.2)
309
269
  hashdiff (>= 0.4.0, < 2.0.0)
310
270
  websocket-driver (0.7.5)
311
271
  websocket-extensions (>= 0.1.0)
312
272
  websocket-extensions (0.1.5)
313
- zeitwerk (2.4.2)
273
+ zeitwerk (2.5.3)
314
274
 
315
275
  PLATFORMS
316
276
  ruby
@@ -319,7 +279,6 @@ DEPENDENCIES
319
279
  appraisal
320
280
  bundler (~> 2.0)
321
281
  cloudtasker!
322
- github_changelog_generator
323
282
  rails (= 6.0)
324
283
  rake (>= 12.3.3)
325
284
  rspec (~> 3.0)
@@ -328,9 +287,8 @@ DEPENDENCIES
328
287
  rubocop (= 0.76.0)
329
288
  rubocop-rspec (= 1.37.0)
330
289
  semantic_logger
331
- sqlite3
332
290
  timecop
333
291
  webmock
334
292
 
335
293
  BUNDLED WITH
336
- 2.2.9
294
+ 2.3.4
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "6.1"
6
+ gem "rspec-rails"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "7.0"
6
+ gem "rspec-rails"
7
+
8
+ gemspec path: "../"
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "activesupport", "6.1"
5
6
  gem "semantic_logger", "3.4.1"
6
7
 
7
8
  gemspec path: "../"
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "activesupport", "6.1"
5
6
  gem "semantic_logger", "4.6.1"
6
7
 
7
8
  gemspec path: "../"
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "activesupport", "6.1"
5
6
  gem "semantic_logger", "4.7.0"
6
7
 
7
8
  gemspec path: "../"
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
+ gem "activesupport", "6.1"
5
6
  gem "semantic_logger", "4.7.2"
6
7
 
7
8
  gemspec path: "../"
@@ -12,28 +12,32 @@ module Cloudtasker
12
12
  #
13
13
  # Create the queue configured in Cloudtasker if it does not already exist.
14
14
  #
15
- # @param [String] queue_name The relative name of the queue.
15
+ # @param [String] :name The queue name
16
+ # @param [Integer] :concurrency The queue concurrency
17
+ # @param [Integer] :retries The number of retries for the queue
16
18
  #
17
19
  # @return [Google::Cloud::Tasks::V2beta3::Queue] The queue
18
20
  #
19
- def self.setup_queue(**opts)
21
+ def self.setup_queue(name: nil, concurrency: nil, retries: nil)
20
22
  # Build full queue path
21
- queue_name = opts[:name] || Cloudtasker::Config::DEFAULT_JOB_QUEUE
23
+ queue_name = name || Cloudtasker::Config::DEFAULT_JOB_QUEUE
22
24
  full_queue_name = queue_path(queue_name)
23
25
 
24
26
  # Try to get existing queue
25
27
  client.get_queue(full_queue_name)
26
28
  rescue Google::Gax::RetryError
27
29
  # Extract options
28
- concurrency = (opts[:concurrency] || Cloudtasker::Config::DEFAULT_QUEUE_CONCURRENCY).to_i
29
- retries = (opts[:retries] || Cloudtasker::Config::DEFAULT_QUEUE_RETRIES).to_i
30
+ queue_concurrency = (concurrency || Cloudtasker::Config::DEFAULT_QUEUE_CONCURRENCY).to_i
31
+ queue_retries = (retries || Cloudtasker::Config::DEFAULT_QUEUE_RETRIES).to_i
30
32
 
31
33
  # Create queue on 'not found' error
32
34
  client.create_queue(
33
35
  client.location_path(config.gcp_project_id, config.gcp_location_id),
34
- name: full_queue_name,
35
- retry_config: { max_attempts: retries },
36
- rate_limits: { max_concurrent_dispatches: concurrency }
36
+ {
37
+ name: full_queue_name,
38
+ retry_config: { max_attempts: queue_retries },
39
+ rate_limits: { max_concurrent_dispatches: queue_concurrency }
40
+ }
37
41
  )
38
42
  end
39
43
 
@@ -62,7 +62,7 @@ module Cloudtasker
62
62
  payload = payload.merge(schedule_time: payload[:schedule_time].to_i)
63
63
 
64
64
  # Save task
65
- task = new(payload.merge(id: id))
65
+ task = new(**payload.merge(id: id))
66
66
  queue << task
67
67
 
68
68
  # Execute task immediately if in testing and inline mode enabled
@@ -89,7 +89,7 @@ module Cloudtasker
89
89
  # Save job
90
90
  redis.write(key(id), payload)
91
91
  redis.sadd(key, id)
92
- new(payload.merge(id: id))
92
+ new(**payload.merge(id: id))
93
93
  end
94
94
 
95
95
  #
@@ -103,7 +103,7 @@ module Cloudtasker
103
103
  gid = key(id)
104
104
  return nil unless (payload = redis.fetch(gid))
105
105
 
106
- new(payload.merge(id: id))
106
+ new(**payload.merge(id: id))
107
107
  end
108
108
 
109
109
  #
@@ -172,8 +172,12 @@ module Cloudtasker
172
172
  # Retry the task later.
173
173
  #
174
174
  # @param [Integer] interval The delay in seconds before retrying the task
175
+ # @param [Hash] opts Additional options
176
+ # @option opts [Boolean] :is_error Increase number of retries. Default to true.
175
177
  #
176
- def retry_later(interval, is_error: true)
178
+ def retry_later(interval, opts = {})
179
+ is_error = opts.to_h.fetch(:is_error, true)
180
+
177
181
  redis.write(
178
182
  gid,
179
183
  retries: is_error ? retries + 1 : retries,
@@ -37,7 +37,7 @@ module Cloudtasker
37
37
  #
38
38
  def self.find(id)
39
39
  payload = backend.find(id)&.to_h
40
- payload ? new(payload) : nil
40
+ payload ? new(**payload) : nil
41
41
  end
42
42
 
43
43
  #
@@ -51,7 +51,7 @@ module Cloudtasker
51
51
  raise MaxTaskSizeExceededError if payload.to_json.bytesize > Config::MAX_TASK_SIZE
52
52
 
53
53
  resp = backend.create(payload)&.to_h
54
- resp ? new(resp) : nil
54
+ resp ? new(**resp) : nil
55
55
  end
56
56
 
57
57
  #
@@ -62,7 +62,7 @@ module Cloudtasker
62
62
  def self.load_from_hash!(hash)
63
63
  schedules = hash.map do |id, config|
64
64
  schedule_config = JSON.parse(config.to_json, symbolize_names: true).merge(id: id.to_s)
65
- create(schedule_config)
65
+ create(**schedule_config)
66
66
  end
67
67
 
68
68
  # Remove existing schedules which are not part of the list
@@ -79,7 +79,7 @@ module Cloudtasker
79
79
  def self.create(**opts)
80
80
  redis.with_lock(key(opts[:id])) do
81
81
  config = find(opts[:id]).to_h.merge(opts)
82
- new(config).tap(&:save)
82
+ new(**config).tap(&:save)
83
83
  end
84
84
  end
85
85
 
@@ -93,7 +93,7 @@ module Cloudtasker
93
93
  def self.find(id)
94
94
  return nil unless (schedule_config = redis.fetch(key(id)))
95
95
 
96
- new(schedule_config)
96
+ new(**schedule_config)
97
97
  end
98
98
 
99
99
  #
@@ -251,9 +251,9 @@ module Cloudtasker
251
251
  #
252
252
  # Buld edit the object attributes.
253
253
  #
254
- # @param [Hash] **opts The attributes to edit.
254
+ # @param [Hash] opts The attributes to edit.
255
255
  #
256
- def assign_attributes(**opts)
256
+ def assign_attributes(opts)
257
257
  opts
258
258
  .select { |k, _| instance_variables.include?("@#{k}".to_sym) }
259
259
  .each { |k, v| instance_variable_set("@#{k}", v) }
@@ -262,9 +262,9 @@ module Cloudtasker
262
262
  #
263
263
  # Edit the object attributes and save the object in Redis.
264
264
  #
265
- # @param [Hash] **opts The attributes to edit.
265
+ # @param [Hash] opts The attributes to edit.
266
266
  #
267
- def update(**opts)
267
+ def update(opts)
268
268
  assign_attributes(opts)
269
269
  save
270
270
  end
@@ -69,7 +69,7 @@ module Cloudtasker
69
69
 
70
70
  # Process tasks
71
71
  while @threads[queue].count < max_threads && (task = Cloudtasker::Backend::RedisTask.pop(queue))
72
- @threads[queue] << Thread.new { process_task(task) }
72
+ @threads[queue] << Thread.new(task) { |t| process_task(t) }
73
73
  end
74
74
  end
75
75
 
@@ -132,22 +132,47 @@ module Cloudtasker
132
132
  list
133
133
  end
134
134
 
135
- #
136
- # Delegate all methods to the redis client.
137
- #
138
- # @param [String, Symbol] name The method to delegate.
139
- # @param [Array<any>] *args The list of method arguments.
140
- # @param [Proc] &block Block passed to the method.
141
- #
142
- # @return [Any] The method return value
143
- #
144
- def method_missing(name, *args, &block)
145
- if Redis.method_defined?(name)
146
- client.with { |c| c.send(name, *args, &block) }
147
- else
148
- super
135
+ # rubocop:disable Style/MissingRespondToMissing
136
+ if RUBY_VERSION < '3'
137
+ #
138
+ # Delegate all methods to the redis client.
139
+ # Old delegation method.
140
+ #
141
+ # @param [String, Symbol] name The method to delegate.
142
+ # @param [Array<any>] *args The list of method positional arguments.
143
+ # @param [Hash<any>] *kwargs The list of method keyword arguments.
144
+ # @param [Proc] &block Block passed to the method.
145
+ #
146
+ # @return [Any] The method return value
147
+ #
148
+ def method_missing(name, *args, &block)
149
+ if Redis.method_defined?(name)
150
+ client.with { |c| c.send(name, *args, &block) }
151
+ else
152
+ super
153
+ end
154
+ end
155
+ else
156
+ #
157
+ # Delegate all methods to the redis client.
158
+ # Ruby 3 delegation method style.
159
+ #
160
+ # @param [String, Symbol] name The method to delegate.
161
+ # @param [Array<any>] *args The list of method positional arguments.
162
+ # @param [Hash<any>] *kwargs The list of method keyword arguments.
163
+ # @param [Proc] &block Block passed to the method.
164
+ #
165
+ # @return [Any] The method return value
166
+ #
167
+ def method_missing(name, *args, **kwargs, &block)
168
+ if Redis.method_defined?(name)
169
+ client.with { |c| c.send(name, *args, **kwargs, &block) }
170
+ else
171
+ super
172
+ end
149
173
  end
150
174
  end
175
+ # rubocop:enable Style/MissingRespondToMissing
151
176
 
152
177
  #
153
178
  # Check if the class respond to a certain method.
@@ -14,10 +14,11 @@ module Cloudtasker
14
14
  # Build a new instance of the class.
15
15
  #
16
16
  # @param [Cloudtasker::Worker] worker The worker at hand
17
+ # @param [Hash] worker The worker options
17
18
  #
18
- def initialize(worker, **kwargs)
19
+ def initialize(worker, opts = {})
19
20
  @worker = worker
20
- @call_opts = kwargs
21
+ @call_opts = opts
21
22
  end
22
23
 
23
24
  #
@@ -3,9 +3,10 @@
3
3
  module Cloudtasker
4
4
  module UniqueJob
5
5
  module Middleware
6
+ # TODO: kwargs to job otherwise it won't get the time_at
6
7
  # Client middleware, invoked when jobs are scheduled
7
8
  class Client
8
- def call(worker, **_kwargs)
9
+ def call(worker, _opts = {})
9
10
  Job.new(worker).lock_instance.schedule { yield }
10
11
  end
11
12
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cloudtasker
4
- VERSION = '0.12.rc11'
4
+ VERSION = '0.13.rc1'
5
5
  end
@@ -47,7 +47,7 @@ module Cloudtasker
47
47
  return nil unless worker_klass.include?(self)
48
48
 
49
49
  # Return instantiated worker
50
- worker_klass.new(payload.slice(:job_queue, :job_args, :job_id, :job_meta, :job_retries, :task_id))
50
+ worker_klass.new(**payload.slice(:job_queue, :job_args, :job_id, :job_meta, :job_retries, :task_id))
51
51
  rescue NameError
52
52
  nil
53
53
  end
@@ -121,7 +121,7 @@ module Cloudtasker
121
121
  # @return [Cloudtasker::CloudTask] The Google Task response
122
122
  #
123
123
  def schedule(args: nil, time_in: nil, time_at: nil, queue: nil)
124
- new(job_args: args, job_queue: queue).schedule({ interval: time_in, time_at: time_at }.compact)
124
+ new(job_args: args, job_queue: queue).schedule(**{ interval: time_in, time_at: time_at }.compact)
125
125
  end
126
126
 
127
127
  #
@@ -239,7 +239,7 @@ module Cloudtasker
239
239
  #
240
240
  def schedule(**args)
241
241
  # Evaluate when to schedule the job
242
- time_at = schedule_time(args)
242
+ time_at = schedule_time(**args)
243
243
 
244
244
  # Schedule job through client middlewares
245
245
  Cloudtasker.config.client_middleware.invoke(self, time_at: time_at) do
@@ -361,7 +361,7 @@ module Cloudtasker
361
361
  # @return [Boolean] True if the arguments are missing.
362
362
  #
363
363
  def arguments_missing?
364
- job_args.empty? && [0, -1].exclude?(method(:perform).arity)
364
+ job_args.empty? && ![0, -1].include?(method(:perform).arity)
365
365
  end
366
366
 
367
367
  #
@@ -27,7 +27,7 @@ module Cloudtasker
27
27
  #
28
28
  def initialize(worker_name:, **opts)
29
29
  @worker_name = worker_name
30
- super(opts)
30
+ super(**opts)
31
31
  end
32
32
 
33
33
  #
data/lib/cloudtasker.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_support/core_ext/string/inflections'
4
+ require 'active_support/core_ext/object/try'
4
5
 
5
6
  require 'cloudtasker/version'
6
7
  require 'cloudtasker/config'