rails_band 0.3.0 → 0.4.0

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: 84c17289076af2e04e037b011c18c6ff3d0206401b67c1e68354979410e545a7
4
- data.tar.gz: 3133417c2eecf067f8e5f402a49b6143ee7e2944f92d95567289262c85af02ea
3
+ metadata.gz: 2068455c0eab607cbdc32392362c6a181b0789d8bd41e77201c7bb06e3eb8ba8
4
+ data.tar.gz: c27bcf5e8dcd06c7f87f164ca1a7f58e537b5910bba7b0a98a7ea3a003649fad
5
5
  SHA512:
6
- metadata.gz: 90f9b92421330c436f3968219be3a7ebf936d4b3b3a47f1906fdf3d1a9c65b4615fb2a3e6c8b76bdaa5f7dc2596c1e67d28f347bc5262420e66a72c69bdb087b
7
- data.tar.gz: 5d852e1baafe0632013fede3b0278deb886f9cf0347848e3cb960b9e153c79096384bc9d8449b974cfbb7c54d576f2d13e60583e5b0be5993ec2a815ae8449ff
6
+ metadata.gz: 936e787242f04a6d7d81bf29993d87bba1187cf27d3e706cb0de672dd27100e99ab029da802871bd044ad722801a4fa6f4f6f22b33e3f1c160935dce10c9b369
7
+ data.tar.gz: 549f64623c4374c3067d0e82a853eace86c14873a89c5e894118ca8e4c1122377d89d55c10c7816b86db391d0130df423c68db25d9d898e4de769947554c1e54
data/README.md CHANGED
@@ -116,13 +116,13 @@ These are Rails Instrumentation API hooks supported by this gem so far.
116
116
 
117
117
  | Event name | Supported |
118
118
  | ------------------------------------------------------------------------------------------------------------------------- | --------- |
119
- | [`enqueue_at.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#enqueue-at-active-job) | |
120
- | [`enqueue.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#enqueue-active-job) | |
121
- | [`enqueue_retry.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#enqueue-retry-active-job) | |
122
- | [`perform_start.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#perform-start-active-job) | |
123
- | [`perform.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#perform-active-job) | |
124
- | [`retry_stopped.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#retry-stopped-active-job) | |
125
- | [`discard.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#discard-active-job) | |
119
+ | [`enqueue_at.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#enqueue-at-active-job) ||
120
+ | [`enqueue.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#enqueue-active-job) ||
121
+ | [`enqueue_retry.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#enqueue-retry-active-job) ||
122
+ | [`perform_start.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#perform-start-active-job) ||
123
+ | [`perform.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#perform-active-job) ||
124
+ | [`retry_stopped.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#retry-stopped-active-job) ||
125
+ | [`discard.active_job`](https://guides.rubyonrails.org/active_support_instrumentation.html#discard-active-job) ||
126
126
 
127
127
  ### Action Cable
128
128
 
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveJob
5
+ module Event
6
+ # A wrapper for the event that is passed to `discard.active_job`.
7
+ class Discard < BaseEvent
8
+ def adapter
9
+ @adapter ||= @event.payload.fetch(:adapter)
10
+ end
11
+
12
+ def job
13
+ @job ||= @event.payload.fetch(:job)
14
+ end
15
+
16
+ def error
17
+ @error ||= @event.payload.fetch(:error)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveJob
5
+ module Event
6
+ # A wrapper for the event that is passed to `enqueue.active_job`.
7
+ class Enqueue < BaseEvent
8
+ def adapter
9
+ @adapter ||= @event.payload.fetch(:adapter)
10
+ end
11
+
12
+ def job
13
+ @job ||= @event.payload.fetch(:job)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveJob
5
+ module Event
6
+ # A wrapper for the event that is passed to `enqueue_at.active_job`.
7
+ class EnqueueAt < BaseEvent
8
+ def adapter
9
+ @adapter ||= @event.payload.fetch(:adapter)
10
+ end
11
+
12
+ def job
13
+ @job ||= @event.payload.fetch(:job)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveJob
5
+ module Event
6
+ # A wrapper for the event that is passed to `enqueue_retry.active_job`.
7
+ class EnqueueRetry < BaseEvent
8
+ def adapter
9
+ @adapter ||= @event.payload.fetch(:adapter)
10
+ end
11
+
12
+ def job
13
+ @job ||= @event.payload.fetch(:job)
14
+ end
15
+
16
+ def wait
17
+ @wait ||= @event.payload.fetch(:wait)
18
+ end
19
+
20
+ def error
21
+ @error ||= @event.payload.fetch(:error)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveJob
5
+ module Event
6
+ # A wrapper for the event that is passed to `perform.active_job`.
7
+ class Perform < BaseEvent
8
+ def adapter
9
+ @adapter ||= @event.payload.fetch(:adapter)
10
+ end
11
+
12
+ def job
13
+ @job ||= @event.payload.fetch(:job)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveJob
5
+ module Event
6
+ # A wrapper for the event that is passed to `perform_start.active_job`.
7
+ class PerformStart < BaseEvent
8
+ def adapter
9
+ @adapter ||= @event.payload.fetch(:adapter)
10
+ end
11
+
12
+ def job
13
+ @job ||= @event.payload.fetch(:job)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsBand
4
+ module ActiveJob
5
+ module Event
6
+ # A wrapper for the event that is passed to `retry_stopped.active_job`.
7
+ class RetryStopped < BaseEvent
8
+ def adapter
9
+ @adapter ||= @event.payload.fetch(:adapter)
10
+ end
11
+
12
+ def job
13
+ @job ||= @event.payload.fetch(:job)
14
+ end
15
+
16
+ def error
17
+ @error ||= @event.payload.fetch(:error)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_band/active_job/event/enqueue_at'
4
+ require 'rails_band/active_job/event/enqueue'
5
+ require 'rails_band/active_job/event/enqueue_retry'
6
+ require 'rails_band/active_job/event/perform_start'
7
+ require 'rails_band/active_job/event/perform'
8
+ require 'rails_band/active_job/event/retry_stopped'
9
+ require 'rails_band/active_job/event/discard'
10
+
11
+ module RailsBand
12
+ module ActiveJob
13
+ # The custom LogSubscriber for ActiveJob.
14
+ class LogSubscriber < ::ActiveSupport::LogSubscriber
15
+ mattr_accessor :consumers
16
+
17
+ def enqueue_at(event)
18
+ consumer_of(__method__)&.call(Event::EnqueueAt.new(event))
19
+ end
20
+
21
+ def enqueue(event)
22
+ consumer_of(__method__)&.call(Event::Enqueue.new(event))
23
+ end
24
+
25
+ def enqueue_retry(event)
26
+ consumer_of(__method__)&.call(Event::EnqueueRetry.new(event))
27
+ end
28
+
29
+ def perform_start(event)
30
+ consumer_of(__method__)&.call(Event::PerformStart.new(event))
31
+ end
32
+
33
+ def perform(event)
34
+ consumer_of(__method__)&.call(Event::Perform.new(event))
35
+ end
36
+
37
+ def retry_stopped(event)
38
+ consumer_of(__method__)&.call(Event::RetryStopped.new(event))
39
+ end
40
+
41
+ def discard(event)
42
+ consumer_of(__method__)&.call(Event::Discard.new(event))
43
+ end
44
+
45
+ private
46
+
47
+ def consumer_of(sub_event)
48
+ consumers[:"#{sub_event}.active_job"] || consumers[:active_job] || consumers[:default]
49
+ end
50
+ end
51
+ end
52
+ end
@@ -31,6 +31,17 @@ module RailsBand
31
31
  end
32
32
 
33
33
  RailsBand::ActiveSupport::LogSubscriber.attach_to :active_support
34
+
35
+ if defined?(::ActiveJob)
36
+ require 'active_job/logging'
37
+
38
+ if defined?(::ActiveJob::Logging::LogSubscriber)
39
+ swap.call(::ActiveJob::Logging::LogSubscriber, RailsBand::ActiveJob::LogSubscriber, :active_job)
40
+ else
41
+ require 'active_job/log_subscriber'
42
+ swap.call(::ActiveJob::LogSubscriber, RailsBand::ActiveJob::LogSubscriber, :active_job)
43
+ end
44
+ end
34
45
  end
35
46
  end
36
47
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsBand
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
data/lib/rails_band.rb CHANGED
@@ -27,4 +27,8 @@ module RailsBand
27
27
  module ActiveSupport
28
28
  autoload :LogSubscriber, 'rails_band/active_support/log_subscriber'
29
29
  end
30
+
31
+ module ActiveJob
32
+ autoload :LogSubscriber, 'rails_band/active_job/log_subscriber'
33
+ end
30
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_band
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yutaka Kamei
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-08 00:00:00.000000000 Z
11
+ date: 2021-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -55,6 +55,14 @@ files:
55
55
  - lib/rails_band/action_view/event/render_template.rb
56
56
  - lib/rails_band/action_view/from_views.rb
57
57
  - lib/rails_band/action_view/log_subscriber.rb
58
+ - lib/rails_band/active_job/event/discard.rb
59
+ - lib/rails_band/active_job/event/enqueue.rb
60
+ - lib/rails_band/active_job/event/enqueue_at.rb
61
+ - lib/rails_band/active_job/event/enqueue_retry.rb
62
+ - lib/rails_band/active_job/event/perform.rb
63
+ - lib/rails_band/active_job/event/perform_start.rb
64
+ - lib/rails_band/active_job/event/retry_stopped.rb
65
+ - lib/rails_band/active_job/log_subscriber.rb
58
66
  - lib/rails_band/active_record/event/instantiation.rb
59
67
  - lib/rails_band/active_record/event/sql.rb
60
68
  - lib/rails_band/active_record/event/strict_loading_violation.rb