rails-cloud-tasks 0.0.4.rc1 → 0.0.7.pre.rc

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec0083f5d83803a2b0bd92726e11895503c587389d1026ee44ff8756e7df323c
4
- data.tar.gz: 799198caaac170f445738b613915f4153b1e73badb5108b70e487e12d63b5992
3
+ metadata.gz: 608be671dc67ea087a4cb6dd7ac3b084b0f28ce0f2844da2922763d847e5a24c
4
+ data.tar.gz: a94fde11198f650c59026ba94bf4d6e16cb53f36881f49bbceb8590f1cbb0249
5
5
  SHA512:
6
- metadata.gz: 5720cdc6e5fdf8914c0bc176f464236297d578a2be4f63662a734e124fc27072f84115f63a76b73ae557931c85be35cb593c24a27799ddd80923e2e24a0e5151
7
- data.tar.gz: ba96fb91bc9c06fdf50d63242a2bafd73716dcca87d66ca1b0fa0f883aa07d04c4bb8fcdf82047da065de4192649279bb50b7b657f30ce06cf3d050fa0163ede
6
+ metadata.gz: 7804b19ada7acf909b5c747ad5dfb7618951c5e3f07f007298b9e7d3c4a1b279c5184e98373fce0f93ba028b642fa9d63b6b989439fcc1cfc036dc188e2f3998
7
+ data.tar.gz: 7566756661ca56eed8c8adf89838df7ce4d8e4c37087efe3eb697323e71eb04e17464d1dda6436e9b57dd509f5b2761434140b33b6f71808981146417b59754e
@@ -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
@@ -14,13 +14,12 @@ module RailsCloudTasks
14
14
 
15
15
  request = ::Rack::Request.new(env)
16
16
  job_args = extract_args(request)
17
- job_class.perform_now(job_args)
17
+
18
+ job_class.perform_now(*job_args)
18
19
 
19
20
  response(200, {})
20
21
  rescue Rack::InvalidPayloadError => e
21
22
  response(422, { error: e.message })
22
- rescue StandardError => e
23
- response(500, { error: e.message })
24
23
  end
25
24
 
26
25
  private
@@ -32,7 +31,7 @@ module RailsCloudTasks
32
31
 
33
32
  def extract_args(request)
34
33
  body = request.body.read
35
- JSON.parse(body)
34
+ JSON.parse(body) || []
36
35
  rescue JSON::ParserError, KeyError
37
36
  raise Rack::InvalidPayloadError
38
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.4.rc1'.freeze
2
+ VERSION = '0.0.7-rc'.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.4.rc1
4
+ version: 0.0.7.pre.rc
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-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport