cloudtasker 0.13.rc1 → 0.13.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test_ruby_2.5_2.6.yml +4 -0
  3. data/.github/workflows/test_ruby_2.7.yml +4 -0
  4. data/.github/workflows/test_ruby_3.x.yml +5 -1
  5. data/.gitignore +1 -0
  6. data/Appraisals +37 -13
  7. data/CHANGELOG.md +3 -2
  8. data/README.md +4 -1
  9. data/cloudtasker.gemspec +1 -1
  10. data/gemfiles/google_cloud_tasks_1.0.gemfile +1 -1
  11. data/gemfiles/google_cloud_tasks_1.1.gemfile +1 -1
  12. data/gemfiles/google_cloud_tasks_1.2.gemfile +1 -1
  13. data/gemfiles/google_cloud_tasks_1.3.gemfile +1 -1
  14. data/gemfiles/{semantic_logger_4.7.gemfile → google_cloud_tasks_1.4.gemfile} +2 -1
  15. data/gemfiles/google_cloud_tasks_1.5.gemfile +8 -0
  16. data/gemfiles/google_cloud_tasks_2.0.gemfile +8 -0
  17. data/gemfiles/google_cloud_tasks_2.1.gemfile +8 -0
  18. data/lib/cloudtasker/backend/{google_cloud_task.rb → google_cloud_task_v1.rb} +3 -3
  19. data/lib/cloudtasker/backend/google_cloud_task_v2.rb +210 -0
  20. data/lib/cloudtasker/cloud_task.rb +41 -3
  21. data/lib/cloudtasker/version.rb +1 -1
  22. data/lib/tasks/setup_queue.rake +2 -2
  23. metadata +12 -19
  24. data/gemfiles/google_cloud_tasks_1.0.gemfile.lock +0 -173
  25. data/gemfiles/google_cloud_tasks_1.1.gemfile.lock +0 -173
  26. data/gemfiles/google_cloud_tasks_1.2.gemfile.lock +0 -173
  27. data/gemfiles/google_cloud_tasks_1.3.gemfile.lock +0 -174
  28. data/gemfiles/rails_4.0.gemfile +0 -10
  29. data/gemfiles/rails_4.1.gemfile +0 -9
  30. data/gemfiles/rails_4.2.gemfile +0 -9
  31. data/gemfiles/rails_5.0.gemfile +0 -9
  32. data/gemfiles/rails_5.1.gemfile +0 -9
  33. data/gemfiles/rails_5.2.gemfile.lock +0 -278
  34. data/gemfiles/rails_6.0.gemfile.lock +0 -294
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bad50ce6f1fb0a4293c26d53530b47dae74a577f7bcddaa9a3d3092e5baeec56
4
- data.tar.gz: 484a11cbfb894334d2b3dc17bbf06877a0b4002852066d197fd0e038dbe8918e
3
+ metadata.gz: 1ea79ae390a67c57e19fade2cd70235dab2cc2b2d115c40510489f93e8ecd509
4
+ data.tar.gz: 20760c5bffa058a32678bd07778f3fa375361cf6fc7bb1e57dfa54ed49b6cd72
5
5
  SHA512:
6
- metadata.gz: c865c34712cdc8fc97d33563a1450daa9705d75458687c04e74e15f26e7180f8534e107c6994e6402de703a3b7060fbc29f1a0e1f00c2361084f3613dfbb9ae5
7
- data.tar.gz: 31fd6ebc1b253db4f6accd747ae871c97d521c089b7682ac0755be8c0a4a17ea504c4b38db9fd84a35a8cdd78f407714e266a58d3a8f19919abbed8ea5378ebb
6
+ metadata.gz: fce5e6ddf114647299a6ffded2a43c07417bbd5e58fc62d1eb1bd4d2d0d93ae4ff13a2beb952286a3a761fb6551c422aef3b10707f4121681540372e4da2a23b
7
+ data.tar.gz: a4f828a6780d506067fd0d8207e140a1f0473252a1444020cbae1c7cc278260700ea5fe3111ab07f415a14b0790a4833b43939ad80695bf1525e530794668b96
@@ -15,6 +15,10 @@ jobs:
15
15
  - 'google-cloud-tasks-1.1'
16
16
  - 'google-cloud-tasks-1.2'
17
17
  - 'google-cloud-tasks-1.3'
18
+ - 'google-cloud-tasks-1.4'
19
+ - 'google-cloud-tasks-1.5'
20
+ - 'google-cloud-tasks-2.0'
21
+ - 'google-cloud-tasks-2.1'
18
22
  - 'rails-5.2'
19
23
  - 'rails-6.0'
20
24
  - 'rails-6.1'
@@ -14,6 +14,10 @@ jobs:
14
14
  - 'google-cloud-tasks-1.1'
15
15
  - 'google-cloud-tasks-1.2'
16
16
  - 'google-cloud-tasks-1.3'
17
+ - 'google-cloud-tasks-1.4'
18
+ - 'google-cloud-tasks-1.5'
19
+ - 'google-cloud-tasks-2.0'
20
+ - 'google-cloud-tasks-2.1'
17
21
  - 'rails-5.2'
18
22
  - 'rails-6.0'
19
23
  - 'rails-6.1'
@@ -9,12 +9,16 @@ jobs:
9
9
  matrix:
10
10
  ruby:
11
11
  - '3.0.1'
12
- - '3.1.0'
12
+ # - '3.1.0'
13
13
  appraisal:
14
14
  - 'google-cloud-tasks-1.0'
15
15
  - 'google-cloud-tasks-1.1'
16
16
  - 'google-cloud-tasks-1.2'
17
17
  - 'google-cloud-tasks-1.3'
18
+ - 'google-cloud-tasks-1.4'
19
+ - 'google-cloud-tasks-1.5'
20
+ - 'google-cloud-tasks-2.0'
21
+ - 'google-cloud-tasks-2.1'
18
22
  - 'rails-6.1'
19
23
  - 'rails-7.0'
20
24
  - 'semantic_logger-3.4'
data/.gitignore CHANGED
@@ -5,6 +5,7 @@
5
5
  /doc/
6
6
  /examples/rails/log/*.log
7
7
  /examples/rails/tmp/
8
+ /gemfiles/*.gemfile.lock
8
9
  /log/
9
10
  /pkg/
10
11
  /spec/reports/
data/Appraisals CHANGED
@@ -2,32 +2,54 @@
2
2
 
3
3
  appraise 'google-cloud-tasks-1.0' do
4
4
  gem 'activesupport', '6.1' # ruby 2.5 / 2.6 compatibility
5
- gem 'google-cloud-tasks', '1.0'
5
+ gem 'google-cloud-tasks', '~> 1.0.0'
6
6
  end
7
7
 
8
8
  appraise 'google-cloud-tasks-1.1' do
9
9
  gem 'activesupport', '6.1' # ruby 2.5 / 2.6 compatibility
10
- gem 'google-cloud-tasks', '1.1'
10
+ gem 'google-cloud-tasks', '~> 1.1.0'
11
11
  end
12
12
 
13
13
  appraise 'google-cloud-tasks-1.2' do
14
14
  gem 'activesupport', '6.1' # ruby 2.5 / 2.6 compatibility
15
- gem 'google-cloud-tasks', '1.2'
15
+ gem 'google-cloud-tasks', '~> 1.2.0'
16
16
  end
17
17
 
18
18
  appraise 'google-cloud-tasks-1.3' do
19
19
  gem 'activesupport', '6.1' # ruby 2.5 / 2.6 compatibility
20
- gem 'google-cloud-tasks', '1.3'
20
+ gem 'google-cloud-tasks', '~> 1.3.0'
21
21
  end
22
22
 
23
- appraise 'rails-5.2' do
24
- gem 'rails', '5.2'
25
- gem 'rspec-rails'
23
+ appraise 'google-cloud-tasks-1.4' do
24
+ gem 'activesupport', '6.1' # ruby 2.5 / 2.6 compatibility
25
+ gem 'google-cloud-tasks', '~> 1.4.0'
26
26
  end
27
27
 
28
- appraise 'rails-6.0' do
29
- gem 'rails', '6.0'
30
- gem 'rspec-rails'
28
+ appraise 'google-cloud-tasks-1.5' do
29
+ gem 'activesupport', '6.1' # ruby 2.5 / 2.6 compatibility
30
+ gem 'google-cloud-tasks', '~> 1.5.0'
31
+ end
32
+
33
+ appraise 'google-cloud-tasks-2.0' do
34
+ gem 'activesupport', '6.1' # ruby 2.5 / 2.6 compatibility
35
+ gem 'google-cloud-tasks', '~> 2.0.0'
36
+ end
37
+
38
+ appraise 'google-cloud-tasks-2.1' do
39
+ gem 'activesupport', '6.1' # ruby 2.5 / 2.6 compatibility
40
+ gem 'google-cloud-tasks', '~> 2.1.0'
41
+ end
42
+
43
+ if RUBY_VERSION < '3'
44
+ appraise 'rails-5.2' do
45
+ gem 'rails', '5.2'
46
+ gem 'rspec-rails'
47
+ end
48
+
49
+ appraise 'rails-6.0' do
50
+ gem 'rails', '6.0'
51
+ gem 'rspec-rails'
52
+ end
31
53
  end
32
54
 
33
55
  appraise 'rails-6.1' do
@@ -35,9 +57,11 @@ appraise 'rails-6.1' do
35
57
  gem 'rspec-rails'
36
58
  end
37
59
 
38
- appraise 'rails-7.0' do
39
- gem 'rails', '7.0'
40
- gem 'rspec-rails'
60
+ if RUBY_VERSION >= '2.7'
61
+ appraise 'rails-7.0' do
62
+ gem 'rails', '7.0'
63
+ gem 'rspec-rails'
64
+ end
41
65
  end
42
66
 
43
67
  appraise 'semantic_logger-3.4' do
data/CHANGELOG.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # Changelog
2
2
 
3
- ## [v0.13.rc1](https://github.com/keypup-io/cloudtasker/tree/v0.13.rc1) (2022-01-03)
3
+ ## [v0.13.rc2](https://github.com/keypup-io/cloudtasker/tree/v0.13.rc2) (2022-01-25)
4
4
 
5
- [Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.12.2...v0.13.rc1)
5
+ [Full Changelog](https://github.com/keypup-io/cloudtasker/compare/v0.12.2...v0.13.rc2)
6
6
 
7
7
  **Improvements:**
8
+ - Dependencies: add support for google-cloud-tasks v2 and while keeping backward compatibility with v1. For existing projects, you may need to run `bundle update google-cloud-tasks` after upgrading cloudtasker to update google-cloud-tasks to the latest version.
8
9
  - Ruby 3: Rework method arguments to be compatible with Ruby 3
9
10
  - Tests: Separate test environment for Ruby 2 and Ruby 3
10
11
  - Tests: Do not load Rails by default and skip Rails-specific tests in non-Rails appraisals
data/README.md CHANGED
@@ -12,7 +12,7 @@ Cloudtasker also provides optional modules for running [cron jobs](docs/CRON_JOB
12
12
 
13
13
  A local processing server is also available for development. This local server processes jobs in lieu of Cloud Tasks and allows you to work offline.
14
14
 
15
- **Maturity**: This gem is production-ready. We at Keypup have already processed millions of jobs using Cloudtasker and all related extensions (cron, batch and unique jobs). We are planning to release the official `v1.0.0` somewhere in 2021, in case we've missed any edge-case bug.
15
+ **Maturity**: This gem is production-ready. We at Keypup have already processed millions of jobs using Cloudtasker and all related extensions (cron, batch and unique jobs). We are planning to release the official `v1.0.0` somewhere in 2022, in case we've missed any edge-case bug.
16
16
 
17
17
  ## Summary
18
18
 
@@ -51,6 +51,9 @@ Add this line to your application's Gemfile:
51
51
 
52
52
  ```ruby
53
53
  gem 'cloudtasker'
54
+
55
+ # For Ruby 3 support, please use v0.13.rc1
56
+ gem 'cloudtasker, '~> 0.13.rc1'
54
57
  ```
55
58
 
56
59
  And then execute:
data/cloudtasker.gemspec CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_dependency 'activesupport'
32
32
  spec.add_dependency 'connection_pool'
33
33
  spec.add_dependency 'fugit'
34
- spec.add_dependency 'google-cloud-tasks', '~> 1.0'
34
+ spec.add_dependency 'google-cloud-tasks'
35
35
  spec.add_dependency 'jwt'
36
36
  spec.add_dependency 'redis'
37
37
  spec.add_dependency 'retriable'
@@ -3,6 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "activesupport", "6.1"
6
- gem "google-cloud-tasks", "1.0"
6
+ gem "google-cloud-tasks", "~> 1.0.0"
7
7
 
8
8
  gemspec path: "../"
@@ -3,6 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "activesupport", "6.1"
6
- gem "google-cloud-tasks", "1.1"
6
+ gem "google-cloud-tasks", "~> 1.1.0"
7
7
 
8
8
  gemspec path: "../"
@@ -3,6 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "activesupport", "6.1"
6
- gem "google-cloud-tasks", "1.2"
6
+ gem "google-cloud-tasks", "~> 1.2.0"
7
7
 
8
8
  gemspec path: "../"
@@ -3,6 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "activesupport", "6.1"
6
- gem "google-cloud-tasks", "1.3"
6
+ gem "google-cloud-tasks", "~> 1.3.0"
7
7
 
8
8
  gemspec path: "../"
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "semantic_logger", "4.7.2"
5
+ gem "activesupport", "6.1"
6
+ gem "google-cloud-tasks", "~> 1.4.0"
6
7
 
7
8
  gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "6.1"
6
+ gem "google-cloud-tasks", "~> 1.5.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "6.1"
6
+ gem "google-cloud-tasks", "~> 2.0.0"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "6.1"
6
+ gem "google-cloud-tasks", "~> 2.1.0"
7
+
8
+ gemspec path: "../"
@@ -6,7 +6,7 @@ require 'retriable'
6
6
  module Cloudtasker
7
7
  module Backend
8
8
  # Manage tasks pushed to GCP Cloud Task
9
- class GoogleCloudTask
9
+ class GoogleCloudTaskV1
10
10
  attr_accessor :gcp_task
11
11
 
12
12
  #
@@ -117,7 +117,7 @@ module Cloudtasker
117
117
  #
118
118
  # @param [String] id The task id.
119
119
  #
120
- # @return [Cloudtasker::Backend::GoogleCloudTask, nil] The retrieved task.
120
+ # @return [Cloudtasker::Backend::GoogleCloudTaskV1, nil] The retrieved task.
121
121
  #
122
122
  def self.find(id)
123
123
  resp = with_gax_retries { client.get_task(id) }
@@ -132,7 +132,7 @@ module Cloudtasker
132
132
  #
133
133
  # @param [Hash] payload The task payload.
134
134
  #
135
- # @return [Cloudtasker::Backend::GoogleCloudTask, nil] The created task.
135
+ # @return [Cloudtasker::Backend::GoogleCloudTaskV1, nil] The created task.
136
136
  #
137
137
  def self.create(payload)
138
138
  payload = format_task_payload(payload)
@@ -0,0 +1,210 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'google/cloud/tasks'
4
+ require 'google/protobuf/timestamp_pb'
5
+ require 'retriable'
6
+
7
+ module Cloudtasker
8
+ module Backend
9
+ # Manage tasks pushed to GCP Cloud Task
10
+ class GoogleCloudTaskV2
11
+ attr_accessor :gcp_task
12
+
13
+ #
14
+ # Create the queue configured in Cloudtasker if it does not already exist.
15
+ #
16
+ # @param [String] :name The queue name
17
+ # @param [Integer] :concurrency The queue concurrency
18
+ # @param [Integer] :retries The number of retries for the queue
19
+ #
20
+ # @return [Google::Cloud::Tasks::V2::Queue] The queue
21
+ #
22
+ def self.setup_queue(name: nil, concurrency: nil, retries: nil)
23
+ # Build full queue path
24
+ queue_name = name || Cloudtasker::Config::DEFAULT_JOB_QUEUE
25
+ full_queue_name = queue_path(queue_name)
26
+
27
+ # Try to get existing queue
28
+ client.get_queue(name: full_queue_name)
29
+ rescue Google::Cloud::NotFoundError
30
+ # Extract options
31
+ queue_concurrency = (concurrency || Cloudtasker::Config::DEFAULT_QUEUE_CONCURRENCY).to_i
32
+ queue_retries = (retries || Cloudtasker::Config::DEFAULT_QUEUE_RETRIES).to_i
33
+
34
+ # Create queue on 'not found' error
35
+ client.create_queue(
36
+ parent: client.location_path(project: config.gcp_project_id, location: config.gcp_location_id),
37
+ queue: {
38
+ name: full_queue_name,
39
+ retry_config: { max_attempts: queue_retries },
40
+ rate_limits: { max_concurrent_dispatches: queue_concurrency }
41
+ }
42
+ )
43
+ end
44
+
45
+ #
46
+ # Return the Google Cloud Task client.
47
+ #
48
+ # @return [Google::Cloud::Tasks::V2::CloudTasks::Client] The Google Cloud Task client.
49
+ #
50
+ def self.client
51
+ @client ||= ::Google::Cloud::Tasks.cloud_tasks
52
+ end
53
+
54
+ #
55
+ # Return the cloudtasker configuration. See Cloudtasker#configure.
56
+ #
57
+ # @return [Cloudtasker::Config] The library configuration.
58
+ #
59
+ def self.config
60
+ Cloudtasker.config
61
+ end
62
+
63
+ #
64
+ # Return the fully qualified path for the Cloud Task queue.
65
+ #
66
+ # @param [String] queue_name The relative name of the queue.
67
+ #
68
+ # @return [String] The queue path.
69
+ #
70
+ def self.queue_path(queue_name)
71
+ client.queue_path(
72
+ project: config.gcp_project_id,
73
+ location: config.gcp_location_id,
74
+ queue: [config.gcp_queue_prefix, queue_name].join('-')
75
+ )
76
+ end
77
+
78
+ #
79
+ # Return a protobuf timestamp specifying how to wait
80
+ # before running a task.
81
+ #
82
+ # @param [Integer, nil] schedule_time A unix timestamp.
83
+ #
84
+ # @return [Google::Protobuf::Timestamp, nil] The protobuff timestamp
85
+ #
86
+ def self.format_schedule_time(schedule_time)
87
+ return nil unless schedule_time
88
+
89
+ # Generate protobuf timestamp
90
+ Google::Protobuf::Timestamp.new.tap { |e| e.seconds = schedule_time.to_i }
91
+ end
92
+
93
+ #
94
+ # Format the job payload sent to Cloud Tasks.
95
+ #
96
+ # @param [Hash] hash The worker payload.
97
+ #
98
+ # @return [Hash] The Cloud Task payloadd.
99
+ #
100
+ def self.format_task_payload(payload)
101
+ payload = JSON.parse(payload.to_json, symbolize_names: true) # deep dup
102
+
103
+ # Format schedule time to Google Protobuf timestamp
104
+ payload[:schedule_time] = format_schedule_time(payload[:schedule_time])
105
+
106
+ # Encode job content to support UTF-8.
107
+ # Google Cloud Task expect content to be ASCII-8BIT compatible (binary)
108
+ payload[:http_request][:headers] ||= {}
109
+ payload[:http_request][:headers][Cloudtasker::Config::CONTENT_TYPE_HEADER] = 'text/json'
110
+ payload[:http_request][:headers][Cloudtasker::Config::ENCODING_HEADER] = 'Base64'
111
+ payload[:http_request][:body] = Base64.encode64(payload[:http_request][:body])
112
+
113
+ payload
114
+ end
115
+
116
+ #
117
+ # Find a task by id.
118
+ #
119
+ # @param [String] id The task id.
120
+ #
121
+ # @return [Cloudtasker::Backend::GoogleCloudTaskV2, nil] The retrieved task.
122
+ #
123
+ def self.find(id)
124
+ resp = with_gapi_retries { client.get_task(name: id) }
125
+ resp ? new(resp) : nil
126
+ rescue Google::Cloud::NotFoundError
127
+ # The ID does not exist
128
+ nil
129
+ end
130
+
131
+ #
132
+ # Create a new task.
133
+ #
134
+ # @param [Hash] payload The task payload.
135
+ #
136
+ # @return [Cloudtasker::Backend::GoogleCloudTaskV2, nil] The created task.
137
+ #
138
+ def self.create(payload)
139
+ payload = format_task_payload(payload)
140
+
141
+ # Infer full queue name
142
+ relative_queue = payload.delete(:queue)
143
+ full_queue = queue_path(relative_queue)
144
+
145
+ # Create task
146
+ resp = with_gapi_retries { client.create_task(parent: full_queue, task: payload) }
147
+ resp ? new(resp) : nil
148
+ end
149
+
150
+ #
151
+ # Delete a task by id.
152
+ #
153
+ # @param [String] id The id of the task.
154
+ #
155
+ def self.delete(id)
156
+ with_gapi_retries { client.delete_task(name: id) }
157
+ rescue Google::Cloud::NotFoundError, Google::Cloud::PermissionDeniedError
158
+ # The ID does not exist
159
+ nil
160
+ end
161
+
162
+ #
163
+ # Helper method encapsulating the retry strategy for Google API calls
164
+ #
165
+ def self.with_gapi_retries
166
+ Retriable.retriable(on: [Google::Cloud::UnavailableError], tries: 3) do
167
+ yield
168
+ end
169
+ end
170
+
171
+ #
172
+ # Build a new instance of the class.
173
+ #
174
+ # @param [Google::Cloud::Tasks::V2::Task] resp The GCP Cloud Task response
175
+ #
176
+ def initialize(gcp_task)
177
+ @gcp_task = gcp_task
178
+ end
179
+
180
+ #
181
+ # Return the relative queue (queue name minus prefix) the task is in.
182
+ #
183
+ # @return [String] The relative queue name
184
+ #
185
+ def relative_queue
186
+ gcp_task
187
+ .name
188
+ .match(%r{/queues/([^/]+)})
189
+ &.captures
190
+ &.first
191
+ &.sub("#{self.class.config.gcp_queue_prefix}-", '')
192
+ end
193
+
194
+ #
195
+ # Return a hash description of the task.
196
+ #
197
+ # @return [Hash] A hash description of the task.
198
+ #
199
+ def to_h
200
+ {
201
+ id: gcp_task.name,
202
+ http_request: gcp_task.to_h[:http_request],
203
+ schedule_time: gcp_task.to_h.dig(:schedule_time, :seconds).to_i,
204
+ retries: gcp_task.to_h[:response_count],
205
+ queue: relative_queue
206
+ }
207
+ end
208
+ end
209
+ end
210
+ end
@@ -8,7 +8,12 @@ module Cloudtasker
8
8
  #
9
9
  # The backend to use for cloud tasks.
10
10
  #
11
- # @return [Cloudtasker::Backend::GoogleCloudTask, Cloudtasker::Backend::RedisTask] The cloud task backend.
11
+ # @return [
12
+ # Backend::MemoryTask,
13
+ # Cloudtasker::Backend::GoogleCloudTaskV1,
14
+ # Cloudtasker::Backend::GoogleCloudTaskV2,
15
+ # Cloudtasker::Backend::RedisTask
16
+ # ] The cloud task backend.
12
17
  #
13
18
  def self.backend
14
19
  # Re-evaluate backend every time if testing mode enabled
@@ -22,12 +27,45 @@ module Cloudtasker
22
27
  require 'cloudtasker/backend/redis_task'
23
28
  Backend::RedisTask
24
29
  else
25
- require 'cloudtasker/backend/google_cloud_task'
26
- Backend::GoogleCloudTask
30
+ gct_backend
27
31
  end
28
32
  end
29
33
  end
30
34
 
35
+ #
36
+ # Return the GoogleCloudTaskV* backend to use based on the version
37
+ # of the currently installed google-cloud-tasks gem
38
+ #
39
+ # @return [
40
+ # Cloudtasker::Backend::GoogleCloudTaskV1,
41
+ # Cloudtasker::Backend::GoogleCloudTaskV2
42
+ # ] The google cloud task backend.
43
+ #
44
+ def self.gct_backend
45
+ @gct_backend ||= begin
46
+ if !defined?(Google::Cloud::Tasks::VERSION) || Google::Cloud::Tasks::VERSION < '2'
47
+ require 'cloudtasker/backend/google_cloud_task_v1'
48
+ Backend::GoogleCloudTaskV1
49
+ else
50
+ require 'cloudtasker/backend/google_cloud_task_v2'
51
+ Backend::GoogleCloudTaskV2
52
+ end
53
+ end
54
+ end
55
+
56
+ #
57
+ # Create the google cloud task queue based on provided parameters if it does not exist already.
58
+ #
59
+ # @param [String] :name The queue name
60
+ # @param [Integer] :concurrency The queue concurrency
61
+ # @param [Integer] :retries The number of retries for the queue
62
+ #
63
+ # @return [Google::Cloud::Tasks::V2::Queue, Google::Cloud::Tasks::V2beta3::Queue] The queue
64
+ #
65
+ def self.setup_production_queue(**kwargs)
66
+ gct_backend.setup_queue(**kwargs)
67
+ end
68
+
31
69
  #
32
70
  # Find a cloud task by id.
33
71
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cloudtasker
4
- VERSION = '0.13.rc1'
4
+ VERSION = '0.13.rc2'
5
5
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'cloudtasker/backend/google_cloud_task'
4
3
  require 'cloudtasker/config'
4
+ require 'cloudtasker/cloud_task'
5
5
 
6
6
  ENV['GOOGLE_AUTH_SUPPRESS_CREDENTIALS_WARNINGS'] ||= 'true'
7
7
 
@@ -11,7 +11,7 @@ namespace :cloudtasker do
11
11
  "concurrency=#{Cloudtasker::Config::DEFAULT_QUEUE_CONCURRENCY}, " \
12
12
  "retries=#{Cloudtasker::Config::DEFAULT_QUEUE_RETRIES})"
13
13
  task setup_queue: :environment do
14
- puts Cloudtasker::Backend::GoogleCloudTask.setup_queue(
14
+ puts Cloudtasker::CloudTask.setup_production_queue(
15
15
  name: ENV['name'],
16
16
  concurrency: ENV['concurrency'],
17
17
  retries: ENV['retries']
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.13.rc1
4
+ version: 0.13.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arnaud Lachaume
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-03 00:00:00.000000000 Z
11
+ date: 2022-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: google-cloud-tasks
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '1.0'
61
+ version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '1.0'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: jwt
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -282,34 +282,27 @@ files:
282
282
  - exe/cloudtasker
283
283
  - gemfiles/.bundle/config
284
284
  - gemfiles/google_cloud_tasks_1.0.gemfile
285
- - gemfiles/google_cloud_tasks_1.0.gemfile.lock
286
285
  - gemfiles/google_cloud_tasks_1.1.gemfile
287
- - gemfiles/google_cloud_tasks_1.1.gemfile.lock
288
286
  - gemfiles/google_cloud_tasks_1.2.gemfile
289
- - gemfiles/google_cloud_tasks_1.2.gemfile.lock
290
287
  - gemfiles/google_cloud_tasks_1.3.gemfile
291
- - gemfiles/google_cloud_tasks_1.3.gemfile.lock
292
- - gemfiles/rails_4.0.gemfile
293
- - gemfiles/rails_4.1.gemfile
294
- - gemfiles/rails_4.2.gemfile
295
- - gemfiles/rails_5.0.gemfile
296
- - gemfiles/rails_5.1.gemfile
288
+ - gemfiles/google_cloud_tasks_1.4.gemfile
289
+ - gemfiles/google_cloud_tasks_1.5.gemfile
290
+ - gemfiles/google_cloud_tasks_2.0.gemfile
291
+ - gemfiles/google_cloud_tasks_2.1.gemfile
297
292
  - gemfiles/rails_5.2.gemfile
298
- - gemfiles/rails_5.2.gemfile.lock
299
293
  - gemfiles/rails_6.0.gemfile
300
- - gemfiles/rails_6.0.gemfile.lock
301
294
  - gemfiles/rails_6.1.gemfile
302
295
  - gemfiles/rails_7.0.gemfile
303
296
  - gemfiles/semantic_logger_3.4.gemfile
304
297
  - gemfiles/semantic_logger_4.6.gemfile
305
298
  - gemfiles/semantic_logger_4.7.0.gemfile
306
299
  - gemfiles/semantic_logger_4.7.2.gemfile
307
- - gemfiles/semantic_logger_4.7.gemfile
308
300
  - lib/active_job/queue_adapters/cloudtasker_adapter.rb
309
301
  - lib/cloudtasker.rb
310
302
  - lib/cloudtasker/authentication_error.rb
311
303
  - lib/cloudtasker/authenticator.rb
312
- - lib/cloudtasker/backend/google_cloud_task.rb
304
+ - lib/cloudtasker/backend/google_cloud_task_v1.rb
305
+ - lib/cloudtasker/backend/google_cloud_task_v2.rb
313
306
  - lib/cloudtasker/backend/memory_task.rb
314
307
  - lib/cloudtasker/backend/redis_task.rb
315
308
  - lib/cloudtasker/batch.rb