rails-cloud-tasks 0.0.2 โ†’ 0.0.3

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: 924a936920255b90f05426a1a02d8fcb7c0b688f05ecf23f47d5574cfd830100
4
- data.tar.gz: dac09c6a8c32a41ce9b8849b57892cac630f54b9592faf88400d248ac32d4661
3
+ metadata.gz: 5059f50ae4598ee23d9abec5ddac5eb2e1c8d4a2023ff794b08461b8611d6d73
4
+ data.tar.gz: 15cb24ec98ffde490596bbdb0a1dff7145e98dcf15aadfb4a5c12093dd8dbfba
5
5
  SHA512:
6
- metadata.gz: b4bb22ec37af949357f944d2e5dc5f80c955fd65426aadc35f1ac4d7bc53cfdc8d5703813553f824e2024c137087a3d891f16d2a7859eb6a26fef771da7a894f
7
- data.tar.gz: 4ca848172ca6473f08348f0b5ff6d9f9ddad8ff2a9b95ab9b2f8e77d933c5d6a1ebd4c29b1eac6afa43ecd3e665913fb9864d22bc8b451a1ee946b1279be6cb4
6
+ metadata.gz: c9076b550dfbdbb3909633ee5f262613df39efc844d06d4a6c6e9153863b18480dc70405c728999465298a7b3950a29454db4f7c5bef926b5d2330cefc7e840d
7
+ data.tar.gz: cab15a28e2083170c65643b7ae58bd83ac2a359b767a3bfa138d6ffc32021767c526dafe4fbf1edc3f0a53b4714ffde19d4128b95081563a70c705e7ac6bd813
@@ -12,6 +12,7 @@ jobs:
12
12
  pre_release: ${{ steps.versioning.outputs.pre_release }}
13
13
  upgraded: ${{ steps.versioning.outputs.upgraded }}
14
14
  package_version: ${{ steps.versioning.outputs.package_version }}
15
+ release_message: ${{ steps.versioning.outputs.release_message }}
15
16
  steps:
16
17
  - uses: actions/checkout@v2
17
18
 
@@ -30,7 +31,9 @@ jobs:
30
31
  key: ${{ runner.os }}-gem-${{ hashFiles('**/rails-cloud-tasks.gemspec') }}-2.7
31
32
 
32
33
  - name: Install dependencies
33
- run: bundle install
34
+ run: |
35
+ bundle config set without 'development test'
36
+ bundle install
34
37
 
35
38
  - name: Fetching Tags
36
39
  run: git fetch -t
@@ -45,6 +48,8 @@ jobs:
45
48
  echo "::set-output name=upgraded::"$upgraded
46
49
  pre_release=$([[ $package_version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && echo "false" || echo "true")
47
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
48
53
 
49
54
  release:
50
55
  runs-on: ubuntu-latest
@@ -68,7 +73,9 @@ jobs:
68
73
  key: ${{ runner.os }}-gem-${{ hashFiles('**/rails-cloud-tasks.gemspec') }}-2.7
69
74
 
70
75
  - name: Install dependencies
71
- run: bundle install
76
+ run: |
77
+ bundle config set without 'development test'
78
+ bundle install
72
79
 
73
80
  - name: Create Release
74
81
  uses: actions/create-release@v1
@@ -78,8 +85,7 @@ jobs:
78
85
  tag_name: ${{ needs.checks.outputs.package_version }}
79
86
  release_name: Release ${{ needs.checks.outputs.package_version }}
80
87
  body: |
81
- Auto-released by bot.
82
- See commit changes.
88
+ ${{ needs.checks.outputs.release_message }}
83
89
  draft: false
84
90
  prerelease: ${{ needs.checks.outputs.pre_release }}
85
91
 
data/README.md CHANGED
@@ -64,6 +64,14 @@ Check out the available configs and its usage description:
64
64
  | tasks_path | The path to run tasks | ๐„‚ | | '/tasks' |
65
65
 
66
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
+
67
75
  - Add a Job class:
68
76
  ```ruby
69
77
  # ./app/jobs/application_job.rb
@@ -12,6 +12,7 @@ module RailsCloudTasks
12
12
  autoload :AppEngine
13
13
  autoload :Configuration
14
14
  autoload :Version
15
+ autoload :Instrumentation
15
16
 
16
17
  module Rack
17
18
  extend ActiveSupport::Autoload
@@ -39,4 +40,21 @@ module RailsCloudTasks
39
40
  end
40
41
  end
41
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 StandardError => 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
42
60
  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
@@ -0,0 +1,7 @@
1
+ module RailsCloudTasks
2
+ module Instrumentation
3
+ class Default
4
+ def transaction_name!(*opts); end
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module RailsCloudTasks
2
+ module Instrumentation
3
+ class Factory
4
+ def self.agent_class
5
+ return NewRelic if defined?(::NewRelic)
6
+
7
+ Default
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module RailsCloudTasks
2
+ module Instrumentation
3
+ class NewRelic
4
+ def transaction_name!(opts)
5
+ agent.set_transaction_name(*opts)
6
+ end
7
+
8
+ def agent
9
+ @agent ||= ::NewRelic::Agent
10
+ end
11
+ end
12
+ end
13
+ end
@@ -8,6 +8,10 @@ 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
17
  job_class.perform_now(job_args)
@@ -9,8 +9,11 @@ module RailsCloudTasks
9
9
  request = ::Rack::Request.new(env)
10
10
  job = extract_job(request)
11
11
 
12
- ActiveJob::Base.execute(job)
12
+ RailsCloudTasks::Instrumentation.transaction_name!(
13
+ "RailsCloudTasks/#{job['job_class']}/perform_now"
14
+ )
13
15
 
16
+ ActiveJob::Base.execute(job)
14
17
  response(200, {})
15
18
  rescue Rack::InvalidPayloadError => e
16
19
  response(400, { error: e.cause.message })
@@ -4,28 +4,36 @@ 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
7
+ attr_reader :client, :credentials, :logger
8
8
 
9
9
  def initialize(
10
10
  client: Google::Cloud::Scheduler.cloud_scheduler,
11
- credentials: RailsCloudTasks::Credentials.new
11
+ credentials: RailsCloudTasks::Credentials.new,
12
+ logger: RailsCloudTasks.logger
12
13
  )
13
14
  client.configure do |config|
14
15
  config.credentials = credentials.generate(service_account_email)
15
16
  end
16
17
  @client = client
18
+ @logger = logger
17
19
  end
18
20
 
19
21
  # Create & Update scheduler job on Google Cloud
20
22
  # TODO: Support to delete scheduled jobs
21
23
  def upsert
24
+ result = { success: [], failure: [] }
22
25
  scheduler_jobs.each do |job|
26
+ success = true
23
27
  begin
24
28
  client.create_job parent: location_path, job: job
25
29
  rescue Google::Cloud::AlreadyExistsError
26
30
  client.update_job job: job
31
+ rescue StandardError
32
+ success = false
27
33
  end
34
+ success ? (result[:success] << job[:name]) : (result[:failure] << job[:name])
28
35
  end
36
+ log_output(result)
29
37
  end
30
38
 
31
39
  protected
@@ -58,5 +66,23 @@ module RailsCloudTasks
58
66
  rescue Errno::ENOENT
59
67
  []
60
68
  end
69
+
70
+ def log_output(result)
71
+ parse_task_name = ->(task) { task.split("#{scheduler_prefix_name}--")[1] }
72
+ success = result[:success].map(&parse_task_name)
73
+ failure = result[:failure].map(&parse_task_name)
74
+
75
+ if success.count.positive?
76
+ log("Successfuly scheduled #{success.count} tasks", '- [โœ“] ',
77
+ success)
78
+ end
79
+
80
+ log("Failed to schedule #{failure.count} tasks", '- [๐„‚] ', failure) if failure.count.positive?
81
+ end
82
+
83
+ def log(desc, prefix, tasks)
84
+ logger.info(desc)
85
+ logger.info(prefix + tasks.join("\n #{prefix}"))
86
+ end
61
87
  end
62
88
  end
@@ -1,3 +1,3 @@
1
1
  module RailsCloudTasks
2
- VERSION = '0.0.2'.freeze
2
+ VERSION = '0.0.3'.freeze
3
3
  end
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.add_dependency 'google-apis-iamcredentials_v1'
28
28
  spec.add_dependency 'google-cloud-scheduler', '>= 2'
29
29
  spec.add_dependency 'google-cloud-tasks', '>= 2'
30
- spec.add_development_dependency 'rails', '>= 4'
30
+ spec.add_dependency 'rails', '>= 4'
31
31
 
32
32
  spec.add_development_dependency 'bundler'
33
33
  spec.add_development_dependency 'pry'
data/renovate.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": [
3
+ "config:base"
4
+ ]
5
+ }
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.2
4
+ version: 0.0.3
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-02-11 00:00:00.000000000 Z
11
+ date: 2021-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -87,7 +87,7 @@ dependencies:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '4'
90
- type: :development
90
+ type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
@@ -284,6 +284,10 @@ files:
284
284
  - lib/rails_cloud_tasks/app_engine.rb
285
285
  - lib/rails_cloud_tasks/configuration.rb
286
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
287
291
  - lib/rails_cloud_tasks/rack/errors.rb
288
292
  - lib/rails_cloud_tasks/rack/jobs.rb
289
293
  - lib/rails_cloud_tasks/rack/tasks.rb
@@ -292,6 +296,7 @@ files:
292
296
  - lib/railtie.rb
293
297
  - lib/tasks/scheduler.rake
294
298
  - rails-cloud-tasks.gemspec
299
+ - renovate.json
295
300
  homepage: http://github.com/flamingo-run/rails-cloud-tasks
296
301
  licenses:
297
302
  - Apache License 2.0