cloudtasker 0.12.2 → 0.13.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/lint_rubocop.yml +20 -0
- data/.github/workflows/{test.yml → test_ruby_2.5_2.6.yml} +7 -8
- data/.github/workflows/test_ruby_2.7.yml +40 -0
- data/.github/workflows/test_ruby_3.x.yml +39 -0
- data/.rubocop.yml +5 -0
- data/Appraisals +20 -0
- data/CHANGELOG.md +9 -0
- data/README.md +10 -2
- data/Rakefile +0 -6
- data/cloudtasker.gemspec +0 -5
- data/gemfiles/google_cloud_tasks_1.0.gemfile +1 -0
- data/gemfiles/google_cloud_tasks_1.0.gemfile.lock +4 -173
- data/gemfiles/google_cloud_tasks_1.1.gemfile +1 -0
- data/gemfiles/google_cloud_tasks_1.1.gemfile.lock +4 -173
- data/gemfiles/google_cloud_tasks_1.2.gemfile +1 -0
- data/gemfiles/google_cloud_tasks_1.2.gemfile.lock +4 -173
- data/gemfiles/google_cloud_tasks_1.3.gemfile +1 -0
- data/gemfiles/google_cloud_tasks_1.3.gemfile.lock +4 -173
- data/gemfiles/rails_5.2.gemfile +1 -0
- data/gemfiles/rails_5.2.gemfile.lock +4 -53
- data/gemfiles/rails_6.0.gemfile +1 -0
- data/gemfiles/rails_6.0.gemfile.lock +4 -53
- data/gemfiles/rails_6.1.gemfile +8 -0
- data/gemfiles/rails_7.0.gemfile +8 -0
- data/gemfiles/semantic_logger_3.4.gemfile +1 -0
- data/gemfiles/semantic_logger_4.6.gemfile +1 -0
- data/gemfiles/semantic_logger_4.7.0.gemfile +1 -0
- data/gemfiles/semantic_logger_4.7.2.gemfile +1 -0
- data/lib/cloudtasker/backend/google_cloud_task.rb +12 -8
- data/lib/cloudtasker/backend/memory_task.rb +1 -1
- data/lib/cloudtasker/backend/redis_task.rb +7 -3
- data/lib/cloudtasker/cloud_task.rb +2 -2
- data/lib/cloudtasker/cron/schedule.rb +7 -7
- data/lib/cloudtasker/redis_client.rb +39 -14
- data/lib/cloudtasker/unique_job/job.rb +3 -2
- data/lib/cloudtasker/unique_job/middleware/client.rb +2 -1
- data/lib/cloudtasker/version.rb +1 -1
- data/lib/cloudtasker/worker.rb +3 -3
- data/lib/cloudtasker/worker_wrapper.rb +1 -1
- metadata +11 -62
@@ -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,
|
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]
|
254
|
+
# @param [Hash] opts The attributes to edit.
|
255
255
|
#
|
256
|
-
def assign_attributes(
|
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]
|
265
|
+
# @param [Hash] opts The attributes to edit.
|
266
266
|
#
|
267
|
-
def update(
|
267
|
+
def update(opts)
|
268
268
|
assign_attributes(opts)
|
269
269
|
save
|
270
270
|
end
|
@@ -132,22 +132,47 @@ module Cloudtasker
|
|
132
132
|
list
|
133
133
|
end
|
134
134
|
|
135
|
-
#
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
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,
|
19
|
+
def initialize(worker, opts = {})
|
19
20
|
@worker = worker
|
20
|
-
@call_opts =
|
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,
|
9
|
+
def call(worker, _opts = {})
|
9
10
|
Job.new(worker).lock_instance.schedule { yield }
|
10
11
|
end
|
11
12
|
end
|
data/lib/cloudtasker/version.rb
CHANGED
data/lib/cloudtasker/worker.rb
CHANGED
@@ -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
|
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.
|
4
|
+
version: 0.13.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnaud Lachaume
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -136,20 +136,6 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '2.0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: github_changelog_generator
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ">="
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '0'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '0'
|
153
139
|
- !ruby/object:Gem::Dependency
|
154
140
|
name: rake
|
155
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -262,48 +248,6 @@ dependencies:
|
|
262
248
|
- - ">="
|
263
249
|
- !ruby/object:Gem::Version
|
264
250
|
version: '0'
|
265
|
-
- !ruby/object:Gem::Dependency
|
266
|
-
name: rails
|
267
|
-
requirement: !ruby/object:Gem::Requirement
|
268
|
-
requirements:
|
269
|
-
- - ">="
|
270
|
-
- !ruby/object:Gem::Version
|
271
|
-
version: '0'
|
272
|
-
type: :development
|
273
|
-
prerelease: false
|
274
|
-
version_requirements: !ruby/object:Gem::Requirement
|
275
|
-
requirements:
|
276
|
-
- - ">="
|
277
|
-
- !ruby/object:Gem::Version
|
278
|
-
version: '0'
|
279
|
-
- !ruby/object:Gem::Dependency
|
280
|
-
name: rspec-rails
|
281
|
-
requirement: !ruby/object:Gem::Requirement
|
282
|
-
requirements:
|
283
|
-
- - ">="
|
284
|
-
- !ruby/object:Gem::Version
|
285
|
-
version: '0'
|
286
|
-
type: :development
|
287
|
-
prerelease: false
|
288
|
-
version_requirements: !ruby/object:Gem::Requirement
|
289
|
-
requirements:
|
290
|
-
- - ">="
|
291
|
-
- !ruby/object:Gem::Version
|
292
|
-
version: '0'
|
293
|
-
- !ruby/object:Gem::Dependency
|
294
|
-
name: sqlite3
|
295
|
-
requirement: !ruby/object:Gem::Requirement
|
296
|
-
requirements:
|
297
|
-
- - ">="
|
298
|
-
- !ruby/object:Gem::Version
|
299
|
-
version: '0'
|
300
|
-
type: :development
|
301
|
-
prerelease: false
|
302
|
-
version_requirements: !ruby/object:Gem::Requirement
|
303
|
-
requirements:
|
304
|
-
- - ">="
|
305
|
-
- !ruby/object:Gem::Version
|
306
|
-
version: '0'
|
307
251
|
description: Background jobs for Ruby using Google Cloud Tasks (beta)
|
308
252
|
email:
|
309
253
|
- arnaud.lachaume@keypup.io
|
@@ -312,7 +256,10 @@ executables:
|
|
312
256
|
extensions: []
|
313
257
|
extra_rdoc_files: []
|
314
258
|
files:
|
315
|
-
- ".github/workflows/
|
259
|
+
- ".github/workflows/lint_rubocop.yml"
|
260
|
+
- ".github/workflows/test_ruby_2.5_2.6.yml"
|
261
|
+
- ".github/workflows/test_ruby_2.7.yml"
|
262
|
+
- ".github/workflows/test_ruby_3.x.yml"
|
316
263
|
- ".gitignore"
|
317
264
|
- ".rspec"
|
318
265
|
- ".rubocop.yml"
|
@@ -351,6 +298,8 @@ files:
|
|
351
298
|
- gemfiles/rails_5.2.gemfile.lock
|
352
299
|
- gemfiles/rails_6.0.gemfile
|
353
300
|
- gemfiles/rails_6.0.gemfile.lock
|
301
|
+
- gemfiles/rails_6.1.gemfile
|
302
|
+
- gemfiles/rails_7.0.gemfile
|
354
303
|
- gemfiles/semantic_logger_3.4.gemfile
|
355
304
|
- gemfiles/semantic_logger_4.6.gemfile
|
356
305
|
- gemfiles/semantic_logger_4.7.0.gemfile
|
@@ -426,11 +375,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
426
375
|
version: '0'
|
427
376
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
428
377
|
requirements:
|
429
|
-
- - "
|
378
|
+
- - ">"
|
430
379
|
- !ruby/object:Gem::Version
|
431
|
-
version:
|
380
|
+
version: 1.3.1
|
432
381
|
requirements: []
|
433
|
-
rubygems_version: 3.
|
382
|
+
rubygems_version: 3.2.3
|
434
383
|
signing_key:
|
435
384
|
specification_version: 4
|
436
385
|
summary: Background jobs for Ruby using Google Cloud Tasks (beta)
|