rails-cloud-tasks 0.0.1 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +65 -4
- data/README.md +58 -0
- data/Rakefile +4 -0
- data/lib/rails-cloud-tasks.rb +32 -0
- data/lib/rails_cloud_tasks/adapter.rb +1 -1
- data/lib/rails_cloud_tasks/configuration.rb +26 -10
- data/lib/rails_cloud_tasks/credentials.rb +38 -0
- data/lib/rails_cloud_tasks/instrumentation.rb +19 -0
- data/lib/rails_cloud_tasks/instrumentation/default.rb +7 -0
- data/lib/rails_cloud_tasks/instrumentation/factory.rb +11 -0
- data/lib/rails_cloud_tasks/instrumentation/new_relic.rb +13 -0
- data/lib/rails_cloud_tasks/rack/jobs.rb +8 -3
- data/lib/rails_cloud_tasks/rack/tasks.rb +5 -2
- data/lib/rails_cloud_tasks/scheduler.rb +95 -0
- data/lib/rails_cloud_tasks/version.rb +1 -1
- data/lib/railtie.rb +15 -0
- data/lib/tasks/scheduler.rake +6 -0
- data/rails-cloud-tasks.gemspec +4 -1
- data/renovate.json +5 -0
- metadata +55 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ab8eda2821b2bba5e155d3444c4cdf5fca633dd468753f4d177354e6ec1207b
|
4
|
+
data.tar.gz: 71a5080bcc0693ea95b68b416246da57e671d7fb24d3bc46a95a895e96c521a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4ed01e0744ec482ad3d3015f92b35eee118601b1d95b7e7d5e3d030a1ff5f243224f35c527574aa8f3a6e8470fab3f2981fd39607e3f4456601501dfeb636b3
|
7
|
+
data.tar.gz: 33b16e211328e0123c85381640087b2d4e1cfca7c0a0fdab0e7777cd20fb3dc148892762eebbf4ec269751b2bf0edb6c1b1f7f2e978962e8ba0d92012e05205c
|
@@ -1,13 +1,60 @@
|
|
1
|
-
name: Release
|
1
|
+
name: Tag & Release Package
|
2
2
|
|
3
3
|
on:
|
4
4
|
push:
|
5
|
-
|
6
|
-
-
|
5
|
+
branches:
|
6
|
+
- main
|
7
7
|
|
8
8
|
jobs:
|
9
|
+
checks:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
outputs:
|
12
|
+
pre_release: ${{ steps.versioning.outputs.pre_release }}
|
13
|
+
upgraded: ${{ steps.versioning.outputs.upgraded }}
|
14
|
+
package_version: ${{ steps.versioning.outputs.package_version }}
|
15
|
+
release_message: ${{ steps.versioning.outputs.release_message }}
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
|
19
|
+
- name: Set up Ruby 2.7
|
20
|
+
uses: actions/setup-ruby@v1
|
21
|
+
with:
|
22
|
+
ruby-version: 2.7
|
23
|
+
|
24
|
+
- name: Install bundler
|
25
|
+
run: gem install bundler
|
26
|
+
|
27
|
+
- name: Cache dependencies
|
28
|
+
uses: actions/cache@v1
|
29
|
+
with:
|
30
|
+
path: vendor/bundle
|
31
|
+
key: ${{ runner.os }}-gem-${{ hashFiles('**/rails-cloud-tasks.gemspec') }}-2.7
|
32
|
+
|
33
|
+
- name: Install dependencies
|
34
|
+
run: |
|
35
|
+
bundle config set without 'development test'
|
36
|
+
bundle install
|
37
|
+
|
38
|
+
- name: Fetching Tags
|
39
|
+
run: git fetch -t
|
40
|
+
|
41
|
+
- name: Detect version upgrade
|
42
|
+
id: versioning
|
43
|
+
run: |
|
44
|
+
pkg='rails-cloud-tasks'
|
45
|
+
package_version=$(bundle info $pkg | grep -o "$pkg \(.*\)" | sed "s/$pkg (\(.*\))/\1/")
|
46
|
+
echo "::set-output name=package_version::"$package_version
|
47
|
+
upgraded=$(git tag --list | grep -q "${package_version}$" && echo "false" || echo "true")
|
48
|
+
echo "::set-output name=upgraded::"$upgraded
|
49
|
+
pre_release=$([[ $package_version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && echo "false" || echo "true")
|
50
|
+
echo "::set-output name=pre_release::"$pre_release
|
51
|
+
release_message=$(git log HEAD ^$(git describe --tags `git rev-list --tags --max-count=1`) --pretty=format:'* %C(green)%h%C(reset) %s')
|
52
|
+
echo "::set-output name=release_message::"$release_message
|
53
|
+
|
9
54
|
release:
|
10
55
|
runs-on: ubuntu-latest
|
56
|
+
needs: checks
|
57
|
+
if: needs.checks.outputs.upgraded == 'true'
|
11
58
|
steps:
|
12
59
|
- uses: actions/checkout@v2
|
13
60
|
|
@@ -26,7 +73,21 @@ jobs:
|
|
26
73
|
key: ${{ runner.os }}-gem-${{ hashFiles('**/rails-cloud-tasks.gemspec') }}-2.7
|
27
74
|
|
28
75
|
- name: Install dependencies
|
29
|
-
run:
|
76
|
+
run: |
|
77
|
+
bundle config set without 'development test'
|
78
|
+
bundle install
|
79
|
+
|
80
|
+
- name: Create Release
|
81
|
+
uses: actions/create-release@v1
|
82
|
+
env:
|
83
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
84
|
+
with:
|
85
|
+
tag_name: ${{ needs.checks.outputs.package_version }}
|
86
|
+
release_name: Release ${{ needs.checks.outputs.package_version }}
|
87
|
+
body: |
|
88
|
+
${{ needs.checks.outputs.release_message }}
|
89
|
+
draft: false
|
90
|
+
prerelease: ${{ needs.checks.outputs.pre_release }}
|
30
91
|
|
31
92
|
- name: Build package
|
32
93
|
run: bundle exec gem build -o rails-cloud-tasks.gem
|
data/README.md
CHANGED
@@ -36,8 +36,11 @@ gem 'rails-cloud-tasks'
|
|
36
36
|
require 'rails-cloud-tasks'
|
37
37
|
|
38
38
|
RailsCloudTasks.configure do |config|
|
39
|
+
config.service_account_email = 'test-account@test-project.iam.gserviceaccount.com'
|
39
40
|
config.project_id = 'my-gcp-project' # This is not needed if running on GCE
|
40
41
|
config.location_id = 'us-central1'
|
42
|
+
config.scheduler_file_path = './custom_path/scheduler_jobs.yml'
|
43
|
+
config.scheduler_prefix_name = 'my-app-name'
|
41
44
|
|
42
45
|
# Base url used by Cloud Tasks to reach your application and run the tasks
|
43
46
|
config.host = 'https://myapplication.host.com'
|
@@ -48,6 +51,27 @@ RailsCloudTasks.configure do |config|
|
|
48
51
|
end
|
49
52
|
```
|
50
53
|
|
54
|
+
Check out the available configs and its usage description:
|
55
|
+
|
56
|
+
| attribute | description | env support | app engine fallback | default value |
|
57
|
+
|----------------------- |------------------------------------------------------------------------------------------------------------- |--------------------- |-------------------- |-------------------------- |
|
58
|
+
| service_account_email | The app service account email. It''s used to impersonate an user on schedule job | GCP_SERVICE_ACCOUNT | ✓ | |
|
59
|
+
| project_id | The Project ID | GCP_PROJECT | ✓ | |
|
60
|
+
| location_id | The region where you app is running (eg: us-central1, us-east1...) | GCP_LOCATION | ✓ | |
|
61
|
+
| host | The app endpoint which the app is running. *Do not use custom domain* Use the generated domain by Cloud Run | GCP_APP_ENDPOINT | | |
|
62
|
+
| scheduler_file_path | Path which the scheduler file is located | 𐄂 | | './config/scheduler.yml' |
|
63
|
+
| scheduler_prefix_name | The prefix to be set into scheduler job name | 𐄂 | | 'rails-cloud' |
|
64
|
+
| tasks_path | The path to run tasks | 𐄂 | | '/tasks' |
|
65
|
+
|
66
|
+
|
67
|
+
- Configure ActiveJob queue_adapter
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
# ./config/application.rb
|
71
|
+
|
72
|
+
config.active_job.queue_adapter = RailsCloudTasks.queue_adapter
|
73
|
+
```
|
74
|
+
|
51
75
|
- Add a Job class:
|
52
76
|
```ruby
|
53
77
|
# ./app/jobs/application_job.rb
|
@@ -73,6 +97,40 @@ end
|
|
73
97
|
```ruby
|
74
98
|
MyJob.perform_later(attrs)
|
75
99
|
```
|
100
|
+
|
101
|
+
### Scheduled Jobs
|
102
|
+
|
103
|
+
We have support to Google Cloud Schedule. It's based on Cloud tasks, the jobs are scheduled with HTTP Target. We do not support Pub/Sub or App Engine HTTP for now.
|
104
|
+
|
105
|
+
Check out the follow sample of config file:
|
106
|
+
```yaml
|
107
|
+
# config/scheduler.yml
|
108
|
+
- name: UsersSyncJob
|
109
|
+
schedule: 0 8 * * *
|
110
|
+
description: Sync user data
|
111
|
+
time_zone: "America/Los_Angeles"
|
112
|
+
class_name: Users::SyncJob
|
113
|
+
args:
|
114
|
+
- this_first: argument
|
115
|
+
is_a: hash
|
116
|
+
- - this second argument
|
117
|
+
- is an array
|
118
|
+
- this third argument is a string
|
119
|
+
```
|
120
|
+
|
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) | ✓ |
|
129
|
+
|
130
|
+
[1]: https://cloud.google.com/tasks/docs/reference/rpc/google.cloud.tasks.v2
|
131
|
+
|
132
|
+
|
133
|
+
|
76
134
|
## Tests
|
77
135
|
|
78
136
|
To run tests:
|
data/Rakefile
ADDED
data/lib/rails-cloud-tasks.rb
CHANGED
@@ -1,13 +1,18 @@
|
|
1
|
+
require_relative './railtie'
|
2
|
+
|
1
3
|
require 'active_support'
|
2
4
|
require 'rails_cloud_tasks/rack/errors'
|
3
5
|
|
4
6
|
module RailsCloudTasks
|
5
7
|
extend ActiveSupport::Autoload
|
6
8
|
|
9
|
+
autoload :Scheduler
|
10
|
+
autoload :Credentials
|
7
11
|
autoload :Adapter
|
8
12
|
autoload :AppEngine
|
9
13
|
autoload :Configuration
|
10
14
|
autoload :Version
|
15
|
+
autoload :Instrumentation
|
11
16
|
|
12
17
|
module Rack
|
13
18
|
extend ActiveSupport::Autoload
|
@@ -25,4 +30,31 @@ module RailsCloudTasks
|
|
25
30
|
def self.config
|
26
31
|
@config ||= Configuration.new
|
27
32
|
end
|
33
|
+
|
34
|
+
def self.logger
|
35
|
+
return @logger if @logger
|
36
|
+
|
37
|
+
@logger ||= (Rails.logger || Logger.new($stdout)).tap do |logger|
|
38
|
+
logger.formatter = proc do |severity, datetime, _progname, msg|
|
39
|
+
"[#{datetime}] #{severity} [rails-cloud-tasks]: #{msg}\n"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
@queue_adapter = nil
|
45
|
+
|
46
|
+
def queue_adapter
|
47
|
+
@@queue_adapter
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.queue_adapter
|
51
|
+
@queue_adapter ||= Adapter.new
|
52
|
+
rescue Errno::EHOSTDOWN => e
|
53
|
+
raise e unless Rails.env.development?
|
54
|
+
|
55
|
+
logger.warn('unable to setup adapter, falling back to :inline')
|
56
|
+
logger.warn(e)
|
57
|
+
|
58
|
+
:inline
|
59
|
+
end
|
28
60
|
end
|
@@ -39,7 +39,7 @@ module RailsCloudTasks
|
|
39
39
|
http_request: {
|
40
40
|
http_method: :POST,
|
41
41
|
url: url,
|
42
|
-
body: { job: job.serialize }.to_json
|
42
|
+
body: { job: job.serialize }.to_json.force_encoding('ASCII-8BIT')
|
43
43
|
}.merge(auth),
|
44
44
|
schedule_time: timestamp && Google::Protobuf::Timestamp.new.tap do |ts|
|
45
45
|
ts.seconds = timestamp
|
@@ -1,12 +1,22 @@
|
|
1
1
|
module RailsCloudTasks
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :
|
3
|
+
attr_accessor :location_id, :host, :tasks_path, :service_account_email, :scheduler_file_path,
|
4
|
+
:scheduler_prefix_name
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
attr_writer :project_id
|
7
|
+
attr_reader :app_engine, :google_auth
|
8
|
+
|
9
|
+
def initialize(app_engine = AppEngine, google_auth = Google::Auth)
|
10
|
+
@service_account_email = ENV['GCP_SERVICE_ACCOUNT']
|
11
|
+
@location_id = ENV['GCP_LOCATION']
|
12
|
+
@project_id = ENV['GCP_PROJECT']
|
13
|
+
@host = ENV['GCP_APP_ENDPOINT']
|
8
14
|
@tasks_path = '/tasks'
|
9
|
-
@
|
15
|
+
@scheduler_file_path = './config/scheduler.yml'
|
16
|
+
@scheduler_prefix_name = 'rails-cloud'
|
17
|
+
|
18
|
+
@app_engine = app_engine
|
19
|
+
@google_auth = google_auth
|
10
20
|
end
|
11
21
|
|
12
22
|
def inject_routes
|
@@ -18,20 +28,26 @@ module RailsCloudTasks
|
|
18
28
|
end
|
19
29
|
end
|
20
30
|
|
31
|
+
def project_id
|
32
|
+
@project_id ||= app_engine.project_id
|
33
|
+
end
|
34
|
+
|
35
|
+
def auth
|
36
|
+
@auth ||= authenticate
|
37
|
+
end
|
38
|
+
|
21
39
|
private
|
22
40
|
|
23
41
|
def authenticate
|
24
|
-
email =
|
42
|
+
email = service_account_email ||
|
43
|
+
app_engine.service_account_email ||
|
44
|
+
google_auth.get_application_default.issuer
|
25
45
|
|
26
46
|
{
|
27
47
|
oidc_token: {
|
28
48
|
service_account_email: email
|
29
49
|
}
|
30
50
|
}
|
31
|
-
rescue RuntimeError, Errno::EHOSTDOWN
|
32
|
-
# EHOSTDOWN occurs sporadically when trying to resolve the metadata endpoint
|
33
|
-
# locally. It is unlikely to occur when running on GCE.
|
34
|
-
{}
|
35
51
|
end
|
36
52
|
end
|
37
53
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module RailsCloudTasks
|
2
|
+
class Credentials
|
3
|
+
require 'googleauth'
|
4
|
+
require 'google/apis/cloudscheduler_v1'
|
5
|
+
require 'google/apis/iamcredentials_v1'
|
6
|
+
|
7
|
+
DEFAULT_SCOPES = ['https://www.googleapis.com/auth/cloud-platform'].freeze
|
8
|
+
attr_reader :request_options, :iam_credential, :token_request, :auth
|
9
|
+
|
10
|
+
def initialize(
|
11
|
+
request_options: Google::Apis::RequestOptions.new,
|
12
|
+
iam_credential: Google::Apis::IamcredentialsV1::IAMCredentialsService.new,
|
13
|
+
token_request: Google::Apis::IamcredentialsV1::GenerateAccessTokenRequest,
|
14
|
+
auth: Google::Auth
|
15
|
+
)
|
16
|
+
@auth = auth
|
17
|
+
@request_options = request_options
|
18
|
+
@iam_credential = iam_credential
|
19
|
+
@token_request = token_request
|
20
|
+
end
|
21
|
+
|
22
|
+
def generate(impersonate_account = nil, scopes = [])
|
23
|
+
current_scopes = DEFAULT_SCOPES + scopes
|
24
|
+
authorization = auth.get_application_default(current_scopes).dup
|
25
|
+
request_options.authorization = authorization
|
26
|
+
|
27
|
+
if impersonate_account
|
28
|
+
iam_credential.generate_service_account_access_token(
|
29
|
+
"projects/-/serviceAccounts/#{impersonate_account}",
|
30
|
+
token_request.new(scope: current_scopes, lifetime: '3600s'),
|
31
|
+
options: request_options
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
request_options.authorization
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module RailsCloudTasks
|
2
|
+
module Instrumentation
|
3
|
+
extend ActiveSupport::Autoload
|
4
|
+
|
5
|
+
autoload :Default
|
6
|
+
autoload :Factory
|
7
|
+
autoload :NewRelic
|
8
|
+
|
9
|
+
module_function
|
10
|
+
|
11
|
+
def agent
|
12
|
+
@agent ||= RailsCloudTasks::Instrumentation::Factory.agent_class.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def transaction_name!(*opts)
|
16
|
+
agent.transaction_name!(opts)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -8,11 +8,16 @@ module RailsCloudTasks
|
|
8
8
|
def call(env)
|
9
9
|
job_class = extract_job_class(env)
|
10
10
|
|
11
|
+
RailsCloudTasks::Instrumentation.transaction_name!(
|
12
|
+
"RailsCloudTasks/#{job_class}/perform_now"
|
13
|
+
)
|
14
|
+
|
11
15
|
request = ::Rack::Request.new(env)
|
12
16
|
job_args = extract_args(request)
|
13
|
-
job_class.perform_now(job_args)
|
14
17
|
|
15
|
-
|
18
|
+
job_class.perform_now(*job_args)
|
19
|
+
|
20
|
+
response(200, {})
|
16
21
|
rescue Rack::InvalidPayloadError => e
|
17
22
|
response(422, { error: e.message })
|
18
23
|
rescue StandardError => e
|
@@ -28,7 +33,7 @@ module RailsCloudTasks
|
|
28
33
|
|
29
34
|
def extract_args(request)
|
30
35
|
body = request.body.read
|
31
|
-
JSON.parse(body)
|
36
|
+
JSON.parse(body) || []
|
32
37
|
rescue JSON::ParserError, KeyError
|
33
38
|
raise Rack::InvalidPayloadError
|
34
39
|
end
|
@@ -9,9 +9,12 @@ module RailsCloudTasks
|
|
9
9
|
request = ::Rack::Request.new(env)
|
10
10
|
job = extract_job(request)
|
11
11
|
|
12
|
-
|
12
|
+
RailsCloudTasks::Instrumentation.transaction_name!(
|
13
|
+
"RailsCloudTasks/#{job['job_class']}/perform_now"
|
14
|
+
)
|
13
15
|
|
14
|
-
|
16
|
+
ActiveJob::Base.execute(job)
|
17
|
+
response(200, {})
|
15
18
|
rescue Rack::InvalidPayloadError => e
|
16
19
|
response(400, { error: e.cause.message })
|
17
20
|
rescue StandardError => e
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module RailsCloudTasks
|
2
|
+
class Scheduler
|
3
|
+
delegate :project_id, :location_id, :host, :auth, :tasks_path,
|
4
|
+
:scheduler_file_path, :scheduler_prefix_name,
|
5
|
+
:service_account_email, to: 'RailsCloudTasks.config'
|
6
|
+
|
7
|
+
attr_reader :client, :credentials, :logger
|
8
|
+
|
9
|
+
def initialize(
|
10
|
+
client: Google::Cloud::Scheduler.cloud_scheduler,
|
11
|
+
credentials: RailsCloudTasks::Credentials.new,
|
12
|
+
logger: RailsCloudTasks.logger
|
13
|
+
)
|
14
|
+
client.configure do |config|
|
15
|
+
config.credentials = credentials.generate(service_account_email)
|
16
|
+
end
|
17
|
+
@client = client
|
18
|
+
@logger = logger
|
19
|
+
end
|
20
|
+
|
21
|
+
# Create & Update scheduler job on Google Cloud
|
22
|
+
# TODO: Support to delete scheduled jobs
|
23
|
+
def upsert
|
24
|
+
result = { success: [], failure: [] }
|
25
|
+
scheduler_jobs.each do |job|
|
26
|
+
upsert_job(job) ? (result[:success] << job[:name]) : (result[:failure] << job[:name])
|
27
|
+
end
|
28
|
+
log_output(result)
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def location_path
|
34
|
+
@location_path ||= client.location_path project: project_id, location: location_id
|
35
|
+
end
|
36
|
+
|
37
|
+
def scheduler_jobs
|
38
|
+
parse_jobs_from_file.map(&method(:build_job))
|
39
|
+
end
|
40
|
+
|
41
|
+
def build_job(job)
|
42
|
+
{
|
43
|
+
name: "#{location_path}/jobs/#{scheduler_prefix_name}--#{job[:name]}",
|
44
|
+
schedule: job[:schedule],
|
45
|
+
description: job[:description],
|
46
|
+
time_zone: job[:time_zone],
|
47
|
+
http_target: {
|
48
|
+
uri: "#{host}#{tasks_path}/#{job[:class_name]}",
|
49
|
+
http_method: 'POST',
|
50
|
+
body: job[:args].to_json
|
51
|
+
}.merge(auth)
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def parse_jobs_from_file
|
56
|
+
settings = File.read(File.expand_path(scheduler_file_path))
|
57
|
+
YAML.safe_load(ERB.new(settings).result).map(&:deep_symbolize_keys)
|
58
|
+
rescue Errno::ENOENT
|
59
|
+
[]
|
60
|
+
end
|
61
|
+
|
62
|
+
def log_output(result)
|
63
|
+
parse_task_name = ->(task) { task.split("#{scheduler_prefix_name}--")[1] }
|
64
|
+
success = result[:success].map(&parse_task_name)
|
65
|
+
failure = result[:failure].map(&parse_task_name)
|
66
|
+
|
67
|
+
if success.count.positive?
|
68
|
+
log("Successfuly scheduled #{success.count} tasks", '- [✓] ',
|
69
|
+
success)
|
70
|
+
end
|
71
|
+
|
72
|
+
log("Failed to schedule #{failure.count} tasks", '- [𐄂] ', failure) if failure.count.positive?
|
73
|
+
end
|
74
|
+
|
75
|
+
def log(desc, prefix, tasks)
|
76
|
+
logger.info(desc)
|
77
|
+
logger.info(prefix + tasks.join("\n #{prefix}"))
|
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
|
94
|
+
end
|
95
|
+
end
|
data/lib/railtie.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails-cloud-tasks'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
module RailsCloudTasks
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
railtie_name :rails_cloud_tasks
|
7
|
+
|
8
|
+
rake_tasks do
|
9
|
+
namespace :rails_cloud_tasks do
|
10
|
+
path = File.expand_path(__dir__)
|
11
|
+
Dir.glob("#{path}/tasks/**/*.rake").each { |f| load f }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/rails-cloud-tasks.gemspec
CHANGED
@@ -23,8 +23,11 @@ Gem::Specification.new do |spec|
|
|
23
23
|
end
|
24
24
|
|
25
25
|
spec.add_dependency 'activesupport', '>= 4'
|
26
|
+
spec.add_dependency 'google-apis-cloudscheduler_v1'
|
27
|
+
spec.add_dependency 'google-apis-iamcredentials_v1'
|
28
|
+
spec.add_dependency 'google-cloud-scheduler', '>= 2'
|
26
29
|
spec.add_dependency 'google-cloud-tasks', '>= 2'
|
27
|
-
spec.
|
30
|
+
spec.add_dependency 'rails', '>= 4'
|
28
31
|
|
29
32
|
spec.add_development_dependency 'bundler'
|
30
33
|
spec.add_development_dependency 'pry'
|
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.4
|
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-
|
11
|
+
date: 2021-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,6 +24,48 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: google-apis-cloudscheduler_v1
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: google-apis-iamcredentials_v1
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: google-cloud-scheduler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2'
|
27
69
|
- !ruby/object:Gem::Dependency
|
28
70
|
name: google-cloud-tasks
|
29
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,7 +87,7 @@ dependencies:
|
|
45
87
|
- - ">="
|
46
88
|
- !ruby/object:Gem::Version
|
47
89
|
version: '4'
|
48
|
-
type: :
|
90
|
+
type: :runtime
|
49
91
|
prerelease: false
|
50
92
|
version_requirements: !ruby/object:Gem::Requirement
|
51
93
|
requirements:
|
@@ -236,15 +278,25 @@ files:
|
|
236
278
|
- Gemfile
|
237
279
|
- LICENSE
|
238
280
|
- README.md
|
281
|
+
- Rakefile
|
239
282
|
- lib/rails-cloud-tasks.rb
|
240
283
|
- lib/rails_cloud_tasks/adapter.rb
|
241
284
|
- lib/rails_cloud_tasks/app_engine.rb
|
242
285
|
- lib/rails_cloud_tasks/configuration.rb
|
286
|
+
- lib/rails_cloud_tasks/credentials.rb
|
287
|
+
- lib/rails_cloud_tasks/instrumentation.rb
|
288
|
+
- lib/rails_cloud_tasks/instrumentation/default.rb
|
289
|
+
- lib/rails_cloud_tasks/instrumentation/factory.rb
|
290
|
+
- lib/rails_cloud_tasks/instrumentation/new_relic.rb
|
243
291
|
- lib/rails_cloud_tasks/rack/errors.rb
|
244
292
|
- lib/rails_cloud_tasks/rack/jobs.rb
|
245
293
|
- lib/rails_cloud_tasks/rack/tasks.rb
|
294
|
+
- lib/rails_cloud_tasks/scheduler.rb
|
246
295
|
- lib/rails_cloud_tasks/version.rb
|
296
|
+
- lib/railtie.rb
|
297
|
+
- lib/tasks/scheduler.rake
|
247
298
|
- rails-cloud-tasks.gemspec
|
299
|
+
- renovate.json
|
248
300
|
homepage: http://github.com/flamingo-run/rails-cloud-tasks
|
249
301
|
licenses:
|
250
302
|
- Apache License 2.0
|