rails-cloud-tasks 0.0.4rc2 → 0.0.7

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: febc18d459ee7372959661d7fdf6361700deeb6777663049f1ec3c3cadd9519a
4
- data.tar.gz: c5f01e5ab5f4c42d923de94e6e94a04cb36d7e3c46905eec51f74f5f77689869
3
+ metadata.gz: e5c0ccb60060c536355871363149f8de556e58b02d291df55d97523eb7bbf19f
4
+ data.tar.gz: 001f4d65d8bd99f50ff8dd26effb28d20627deff7377dd3b33aaed3bd1418e3a
5
5
  SHA512:
6
- metadata.gz: fa9a92c2aa4bb52b64d327b86d18b0fa421f487f396858ad2a03c5735441ecd5402b2da7923c30938962c2d743bb93ce366bb26db04f79c5b8951d5f9d96abac
7
- data.tar.gz: c882b97485494659e62ddca4855f64899b1629e27ae1714f861c754d8e78dbadbfde69bff0d9487dd47da62c88422acdf46cf1250efefe4e50c06f4bb9394d5b
6
+ metadata.gz: dbefd470b602eadb6e0a5b4089eb8a690fde6176a221d3c6909f2ac51778c9b5233f8a77315551355f633df46c9c430c3a1e7d68c70ebc4e39f4799c7bdfdfc2
7
+ data.tar.gz: 104087dd434acb527c79044db63ad6ddd947062b69d833db7ad1984333850083b198d67dd4c5dcd33b381fe0999362173ccdd79aa36058528e8f90f5dc024eef
@@ -23,7 +23,7 @@ jobs:
23
23
  run: gem install bundler
24
24
 
25
25
  - name: Cache dependencies
26
- uses: actions/cache@v1
26
+ uses: actions/cache@v2
27
27
  with:
28
28
  path: vendor/bundle
29
29
  key: ${{ runner.os }}-gem-${{ hashFiles('**/rails-cloud-tasks.gemspec') }}
@@ -48,7 +48,7 @@ jobs:
48
48
  run: gem install bundler
49
49
 
50
50
  - name: Cache dependencies
51
- uses: actions/cache@v1
51
+ uses: actions/cache@v2
52
52
  with:
53
53
  path: vendor/bundle
54
54
  key: ${{ runner.os }}-gem-${{ hashFiles('**/rails-cloud-tasks.gemspec') }}
@@ -73,7 +73,7 @@ jobs:
73
73
  run: gem install bundler
74
74
 
75
75
  - name: Cache dependencies
76
- uses: actions/cache@v1
76
+ uses: actions/cache@v2
77
77
  with:
78
78
  path: vendor/bundle
79
79
  key: ${{ runner.os }}-gem-${{ hashFiles('**/rails-cloud-tasks.gemspec') }}
@@ -25,7 +25,7 @@ jobs:
25
25
  run: gem install bundler
26
26
 
27
27
  - name: Cache dependencies
28
- uses: actions/cache@v1
28
+ uses: actions/cache@v2
29
29
  with:
30
30
  path: vendor/bundle
31
31
  key: ${{ runner.os }}-gem-${{ hashFiles('**/rails-cloud-tasks.gemspec') }}-2.7
@@ -67,7 +67,7 @@ jobs:
67
67
  run: gem install bundler
68
68
 
69
69
  - name: Cache dependencies
70
- uses: actions/cache@v1
70
+ uses: actions/cache@v2
71
71
  with:
72
72
  path: vendor/bundle
73
73
  key: ${{ runner.os }}-gem-${{ hashFiles('**/rails-cloud-tasks.gemspec') }}-2.7
data/README.md CHANGED
@@ -105,23 +105,29 @@ We have support to Google Cloud Schedule. It's based on Cloud tasks, the jobs ar
105
105
  Check out the follow sample of config file:
106
106
  ```yaml
107
107
  # config/scheduler.yml
108
- - name: Users::SyncJob
108
+ - name: UsersSyncJob
109
109
  schedule: 0 8 * * *
110
110
  description: Sync user data
111
111
  time_zone: "America/Los_Angeles"
112
+ class_name: Users::SyncJob
112
113
  args:
113
- arg1: 100
114
- arg2: 200
114
+ - this_first: argument
115
+ is_a: hash
116
+ - - this second argument
117
+ - is an array
118
+ - this third argument is a string
115
119
  ```
116
120
 
117
- | attribute | description | required |
118
- |------------- |---------------------------------------------------------------- |---------- |
119
- | name | The Job class namespace | ✓ |
120
- | schedule | The frequency to run your job. It should be a unix-cron format | ✓ |
121
- | description | What this job does | ✓ |
122
- | time_zone | Choose which one timezone your job must run | ✓ |
123
- | args | What are the job's arguments | |
121
+ | attribute | description | required |
122
+ |------------- |---------------------------------------------------------------------------------- |---------- |
123
+ | name | Any descriptive name, following [Tasks naming restrictions][1] | ✓ |
124
+ | schedule | The frequency to run your job. It should be a unix-cron format | ✓ |
125
+ | description | What this job does | ✓ |
126
+ | time_zone | Choose which one timezone your job must run | ✓ |
127
+ | args | Arguments to the job execution. Important: if present, this must be an array of items. Check out the example above | 𐄂 |
128
+ | class_name | The Job class name (including namespace) | ✓ |
124
129
 
130
+ [1]: https://cloud.google.com/tasks/docs/reference/rpc/google.cloud.tasks.v2
125
131
 
126
132
 
127
133
 
@@ -2,14 +2,8 @@ require 'google-cloud-tasks'
2
2
 
3
3
  module RailsCloudTasks
4
4
  class Adapter
5
- attr_reader :client
6
-
7
5
  delegate :project_id, :location_id, :host, :tasks_path, :auth, to: 'RailsCloudTasks.config'
8
6
 
9
- def initialize(client = Google::Cloud::Tasks.cloud_tasks)
10
- @client = client
11
- end
12
-
13
7
  def enqueue(job, timestamp = nil)
14
8
  path = client.queue_path(project: project_id, location: location_id, queue: job.queue_name)
15
9
  task = build_task(job, timestamp)
@@ -28,6 +22,10 @@ module RailsCloudTasks
28
22
  enqueue(job, timestamp.to_i)
29
23
  end
30
24
 
25
+ def client
26
+ @client ||= Google::Cloud::Tasks.cloud_tasks
27
+ end
28
+
31
29
  private
32
30
 
33
31
  def url
@@ -15,17 +15,11 @@ module RailsCloudTasks
15
15
  request = ::Rack::Request.new(env)
16
16
  job_args = extract_args(request)
17
17
 
18
- if job_args
19
- job_class.perform_now(job_args)
20
- else
21
- job_class.perform_now
22
- end
18
+ job_class.perform_now(*job_args)
23
19
 
24
20
  response(200, {})
25
21
  rescue Rack::InvalidPayloadError => e
26
22
  response(422, { error: e.message })
27
- rescue StandardError => e
28
- response(500, { error: e.message })
29
23
  end
30
24
 
31
25
  private
@@ -37,7 +31,7 @@ module RailsCloudTasks
37
31
 
38
32
  def extract_args(request)
39
33
  body = request.body.read
40
- JSON.parse(body)
34
+ JSON.parse(body) || []
41
35
  rescue JSON::ParserError, KeyError
42
36
  raise Rack::InvalidPayloadError
43
37
  end
@@ -17,8 +17,6 @@ module RailsCloudTasks
17
17
  response(200, {})
18
18
  rescue Rack::InvalidPayloadError => e
19
19
  response(400, { error: e.cause.message })
20
- rescue StandardError => e
21
- response(500, { error: e.message })
22
20
  end
23
21
 
24
22
  private
@@ -4,17 +4,13 @@ module RailsCloudTasks
4
4
  :scheduler_file_path, :scheduler_prefix_name,
5
5
  :service_account_email, to: 'RailsCloudTasks.config'
6
6
 
7
- attr_reader :client, :credentials, :logger
7
+ attr_reader :credentials, :logger
8
8
 
9
9
  def initialize(
10
- client: Google::Cloud::Scheduler.cloud_scheduler,
11
10
  credentials: RailsCloudTasks::Credentials.new,
12
11
  logger: RailsCloudTasks.logger
13
12
  )
14
- client.configure do |config|
15
- config.credentials = credentials.generate(service_account_email)
16
- end
17
- @client = client
13
+ @credentials = credentials
18
14
  @logger = logger
19
15
  end
20
16
 
@@ -28,6 +24,12 @@ module RailsCloudTasks
28
24
  log_output(result)
29
25
  end
30
26
 
27
+ def client
28
+ @client ||= Google::Cloud::Scheduler.cloud_scheduler.configure do |config|
29
+ config.credentials = credentials.generate(service_account_email)
30
+ end
31
+ end
32
+
31
33
  protected
32
34
 
33
35
  def location_path
@@ -45,7 +47,7 @@ module RailsCloudTasks
45
47
  description: job[:description],
46
48
  time_zone: job[:time_zone],
47
49
  http_target: {
48
- uri: "#{host}#{tasks_path}/#{job[:class_name] || job[:name]}",
50
+ uri: "#{host}#{tasks_path}/#{job[:class_name]}",
49
51
  http_method: 'POST',
50
52
  body: job[:args].to_json
51
53
  }.merge(auth)
@@ -1,3 +1,3 @@
1
1
  module RailsCloudTasks
2
- VERSION = '0.0.4rc2'.freeze
2
+ VERSION = '0.0.7'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-cloud-tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4rc2
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilherme Araújo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-09 00:00:00.000000000 Z
11
+ date: 2021-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -312,9 +312,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
312
312
  version: '2.4'
313
313
  required_rubygems_version: !ruby/object:Gem::Requirement
314
314
  requirements:
315
- - - ">"
315
+ - - ">="
316
316
  - !ruby/object:Gem::Version
317
- version: 1.3.1
317
+ version: '0'
318
318
  requirements: []
319
319
  rubygems_version: 3.1.4
320
320
  signing_key: