rails-cloud-tasks 0.0.3 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yaml +3 -3
- data/.github/workflows/release.yml +2 -2
- data/README.md +16 -10
- data/lib/rails_cloud_tasks/rack/jobs.rb +3 -4
- data/lib/rails_cloud_tasks/rack/tasks.rb +0 -2
- data/lib/rails_cloud_tasks/scheduler.rb +17 -10
- data/lib/rails_cloud_tasks/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04d8c81b125d6c5a31fc5058b0a363615a39a5c96ae091df89a383055938b294
|
4
|
+
data.tar.gz: 40d5e7c7dea249786c94a3933e8d77e4baf29364bdceb3a2f4c30e652544e05e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a851899a7195a2280ab19b5b9276c993c143782b7756362b48f04731dcca769db99c765f889c5c255f33c87e15255e4263de285a6c45ec4fafb02759b6037db0
|
7
|
+
data.tar.gz: fba16fe2a21f0466216fd1eabb901ef657e53356f33ec8e1fc005533a875ac45e1280926fa2090d2f69e03c1ab71bebbf0bd90739fa324dc70f9a257c8f705e7
|
data/.github/workflows/main.yaml
CHANGED
@@ -23,7 +23,7 @@ jobs:
|
|
23
23
|
run: gem install bundler
|
24
24
|
|
25
25
|
- name: Cache dependencies
|
26
|
-
uses: actions/cache@
|
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@
|
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@
|
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@
|
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@
|
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:
|
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
|
-
|
114
|
-
|
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
|
118
|
-
|-------------
|
119
|
-
| name |
|
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 |
|
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
|
|
@@ -14,13 +14,12 @@ module RailsCloudTasks
|
|
14
14
|
|
15
15
|
request = ::Rack::Request.new(env)
|
16
16
|
job_args = extract_args(request)
|
17
|
-
|
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
|
@@ -23,15 +23,7 @@ module RailsCloudTasks
|
|
23
23
|
def upsert
|
24
24
|
result = { success: [], failure: [] }
|
25
25
|
scheduler_jobs.each do |job|
|
26
|
-
success
|
27
|
-
begin
|
28
|
-
client.create_job parent: location_path, job: job
|
29
|
-
rescue Google::Cloud::AlreadyExistsError
|
30
|
-
client.update_job job: job
|
31
|
-
rescue StandardError
|
32
|
-
success = false
|
33
|
-
end
|
34
|
-
success ? (result[:success] << job[:name]) : (result[:failure] << job[:name])
|
26
|
+
upsert_job(job) ? (result[:success] << job[:name]) : (result[:failure] << job[:name])
|
35
27
|
end
|
36
28
|
log_output(result)
|
37
29
|
end
|
@@ -53,7 +45,7 @@ module RailsCloudTasks
|
|
53
45
|
description: job[:description],
|
54
46
|
time_zone: job[:time_zone],
|
55
47
|
http_target: {
|
56
|
-
uri: "#{host}#{tasks_path}/#{job[:
|
48
|
+
uri: "#{host}#{tasks_path}/#{job[:class_name]}",
|
57
49
|
http_method: 'POST',
|
58
50
|
body: job[:args].to_json
|
59
51
|
}.merge(auth)
|
@@ -84,5 +76,20 @@ module RailsCloudTasks
|
|
84
76
|
logger.info(desc)
|
85
77
|
logger.info(prefix + tasks.join("\n #{prefix}"))
|
86
78
|
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def upsert_job(job)
|
83
|
+
success = true
|
84
|
+
begin
|
85
|
+
client.create_job parent: location_path, job: job
|
86
|
+
rescue Google::Cloud::AlreadyExistsError
|
87
|
+
client.update_job job: job
|
88
|
+
rescue StandardError => e
|
89
|
+
logger.error(e)
|
90
|
+
success = false
|
91
|
+
end
|
92
|
+
success
|
93
|
+
end
|
87
94
|
end
|
88
95
|
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
|
+
version: 0.0.6
|
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-
|
11
|
+
date: 2021-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|