cloudtasker 0.11.rc1 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +1 -5
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +32 -0
- data/README.md +94 -0
- data/app/controllers/cloudtasker/worker_controller.rb +4 -1
- data/cloudtasker.gemspec +1 -0
- data/docs/BATCH_JOBS.md +1 -1
- data/gemfiles/google_cloud_tasks_1.0.gemfile.lock +200 -147
- data/gemfiles/google_cloud_tasks_1.1.gemfile.lock +200 -147
- data/gemfiles/google_cloud_tasks_1.2.gemfile.lock +200 -147
- data/gemfiles/google_cloud_tasks_1.3.gemfile.lock +200 -147
- data/gemfiles/rails_5.2.gemfile.lock +136 -82
- data/gemfiles/rails_6.0.gemfile.lock +137 -83
- data/lib/active_job/queue_adapters/cloudtasker_adapter.rb +82 -0
- data/lib/cloudtasker/batch/job.rb +4 -0
- data/lib/cloudtasker/batch/middleware.rb +2 -0
- data/lib/cloudtasker/cli.rb +1 -0
- data/lib/cloudtasker/engine.rb +5 -1
- data/lib/cloudtasker/version.rb +1 -1
- data/lib/cloudtasker.rb +1 -0
- metadata +22 -8
- data/app/controllers/cloudtasker/application_controller.rb +0 -8
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# ActiveJob docs: http://guides.rubyonrails.org/active_job_basics.html
|
4
|
+
# Example adapters ref: https://github.com/rails/rails/tree/master/activejob/lib/active_job/queue_adapters
|
5
|
+
|
6
|
+
module ActiveJob
|
7
|
+
module QueueAdapters
|
8
|
+
# == Cloudtasker adapter for Active Job
|
9
|
+
#
|
10
|
+
# To use Cloudtasker set the queue_adapter config to +:cloudtasker+.
|
11
|
+
#
|
12
|
+
# Rails.application.config.active_job.queue_adapter = :cloudtasker
|
13
|
+
class CloudtaskerAdapter
|
14
|
+
SERIALIZATION_FILTERED_KEYS = [
|
15
|
+
'executions', # Given by the worker at processing
|
16
|
+
'provider_job_id', # Also given by the worker at processing
|
17
|
+
'priority' # Not used
|
18
|
+
].freeze
|
19
|
+
|
20
|
+
# Enqueues the given ActiveJob instance for execution
|
21
|
+
#
|
22
|
+
# @param job [ActiveJob::Base] The ActiveJob instance
|
23
|
+
#
|
24
|
+
# @return [Cloudtasker::CloudTask] The Google Task response
|
25
|
+
#
|
26
|
+
def enqueue(job)
|
27
|
+
build_worker(job).schedule
|
28
|
+
end
|
29
|
+
|
30
|
+
# Enqueues the given ActiveJob instance for execution at a given time
|
31
|
+
#
|
32
|
+
# @param job [ActiveJob::Base] The ActiveJob instance
|
33
|
+
# @param precise_timestamp [Integer] The timestamp at which the job must be executed
|
34
|
+
#
|
35
|
+
# @return [Cloudtasker::CloudTask] The Google Task response
|
36
|
+
#
|
37
|
+
def enqueue_at(job, precise_timestamp)
|
38
|
+
build_worker(job).schedule(time_at: Time.at(precise_timestamp))
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def build_worker(job)
|
44
|
+
job_serialization = job.serialize.except(*SERIALIZATION_FILTERED_KEYS)
|
45
|
+
|
46
|
+
JobWrapper.new(
|
47
|
+
job_id: job_serialization.delete('job_id'),
|
48
|
+
job_queue: job_serialization.delete('queue_name'),
|
49
|
+
job_args: [job_serialization]
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
# == Job Wrapper for the Cloudtasker adapter
|
54
|
+
#
|
55
|
+
# Executes jobs scheduled by the Cloudtasker ActiveJob adapter
|
56
|
+
class JobWrapper #:nodoc:
|
57
|
+
include Cloudtasker::Worker
|
58
|
+
|
59
|
+
# Executes the given serialized ActiveJob call.
|
60
|
+
# - See https://api.rubyonrails.org/classes/ActiveJob/Core.html#method-i-serialize
|
61
|
+
#
|
62
|
+
# @param [Hash] job_serialization The serialized ActiveJob call
|
63
|
+
#
|
64
|
+
# @return [any] The execution of the ActiveJob call
|
65
|
+
#
|
66
|
+
def perform(job_serialization, *_extra_options)
|
67
|
+
job_executions = job_retries < 1 ? 0 : (job_retries + 1)
|
68
|
+
|
69
|
+
job_serialization.merge!(
|
70
|
+
'job_id' => job_id,
|
71
|
+
'queue_name' => job_queue,
|
72
|
+
'provider_job_id' => task_id,
|
73
|
+
'executions' => job_executions,
|
74
|
+
'priority' => nil
|
75
|
+
)
|
76
|
+
|
77
|
+
Base.execute job_serialization
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -62,6 +62,10 @@ module Cloudtasker
|
|
62
62
|
# @return [Cloudtasker::Batch::Job] The attached batch.
|
63
63
|
#
|
64
64
|
def self.for(worker)
|
65
|
+
# Load extension if not loaded already on the worker class
|
66
|
+
worker.class.include(Extension::Worker) unless worker.class <= Extension::Worker
|
67
|
+
|
68
|
+
# Add batch capability
|
65
69
|
worker.batch = new(worker)
|
66
70
|
end
|
67
71
|
|
data/lib/cloudtasker/cli.rb
CHANGED
data/lib/cloudtasker/engine.rb
CHANGED
@@ -5,10 +5,14 @@ module Cloudtasker
|
|
5
5
|
class Engine < ::Rails::Engine
|
6
6
|
isolate_namespace Cloudtasker
|
7
7
|
|
8
|
-
|
8
|
+
config.before_initialize do
|
9
|
+
# Mount cloudtasker processing endpoint
|
9
10
|
Rails.application.routes.append do
|
10
11
|
mount Cloudtasker::Engine, at: '/cloudtasker'
|
11
12
|
end
|
13
|
+
|
14
|
+
# Add ActiveJob adapter
|
15
|
+
require 'active_job/queue_adapters/cloudtasker_adapter' if defined?(::ActiveJob::Railtie)
|
12
16
|
end
|
13
17
|
|
14
18
|
config.generators do |g|
|
data/lib/cloudtasker/version.rb
CHANGED
data/lib/cloudtasker.rb
CHANGED
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.11.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnaud Lachaume
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -178,6 +178,20 @@ dependencies:
|
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '3.0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: rspec-json_expectations
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '2.2'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '2.2'
|
181
195
|
- !ruby/object:Gem::Dependency
|
182
196
|
name: rubocop
|
183
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -310,7 +324,6 @@ files:
|
|
310
324
|
- README.md
|
311
325
|
- Rakefile
|
312
326
|
- _config.yml
|
313
|
-
- app/controllers/cloudtasker/application_controller.rb
|
314
327
|
- app/controllers/cloudtasker/worker_controller.rb
|
315
328
|
- bin/console
|
316
329
|
- bin/setup
|
@@ -343,6 +356,7 @@ files:
|
|
343
356
|
- gemfiles/semantic_logger_4.7.0.gemfile
|
344
357
|
- gemfiles/semantic_logger_4.7.2.gemfile
|
345
358
|
- gemfiles/semantic_logger_4.7.gemfile
|
359
|
+
- lib/active_job/queue_adapters/cloudtasker_adapter.rb
|
346
360
|
- lib/cloudtasker.rb
|
347
361
|
- lib/cloudtasker/authentication_error.rb
|
348
362
|
- lib/cloudtasker/authenticator.rb
|
@@ -401,7 +415,7 @@ metadata:
|
|
401
415
|
homepage_uri: https://github.com/keypup-io/cloudtasker
|
402
416
|
source_code_uri: https://github.com/keypup-io/cloudtasker
|
403
417
|
changelog_uri: https://github.com/keypup-io/cloudtasker/master/tree/CHANGELOG.md
|
404
|
-
post_install_message:
|
418
|
+
post_install_message:
|
405
419
|
rdoc_options: []
|
406
420
|
require_paths:
|
407
421
|
- lib
|
@@ -412,12 +426,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
412
426
|
version: '0'
|
413
427
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
414
428
|
requirements:
|
415
|
-
- - "
|
429
|
+
- - ">="
|
416
430
|
- !ruby/object:Gem::Version
|
417
|
-
version:
|
431
|
+
version: '0'
|
418
432
|
requirements: []
|
419
433
|
rubygems_version: 3.0.0
|
420
|
-
signing_key:
|
434
|
+
signing_key:
|
421
435
|
specification_version: 4
|
422
436
|
summary: Background jobs for Ruby using Google Cloud Tasks (beta)
|
423
437
|
test_files: []
|