yabeda-activejob 0.3.1 → 0.5.0

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: 3cd5ae2317f42f9d4e2a5b44bba2d44b792e07f9e55a7992af2e37dabbd6333f
4
- data.tar.gz: 4da6bb136cb5a1ab33a7f3927b79f4a9a50a1188e32340d459ebdcfbf9ca2ca6
3
+ metadata.gz: c3c22dd8f72f9eb6bfe6e70ab014b7e0dfe539df47f08127474fc7fc08f14b5b
4
+ data.tar.gz: 2b25afaacc5fbe787c23e2c8d8e69ea44e8b8ca569714c68043fef8de6683bf5
5
5
  SHA512:
6
- metadata.gz: 2f73db31ff848abc54d5e43fb664cb28c5de70b7a5697a349d952bdf1a7e2e605eb8ebdb98edb31c90f0c8832c59162e29d278ae6846c73d0829be4a20ea3a54
7
- data.tar.gz: 5c86775ae9e1811f2fd2e1e9558eeb9fb681635af322180e2d3828d3f7ab2be235b6ea579fb5f13c95324b32fe0e2a14fefa9d5240daffe018b4a3e910f5cea2
6
+ metadata.gz: e7ec04003b26361f39904f30c55421032897aba30e3a896318ae1ec6ecb91ea0095aed31220f3f6d0345150e61522129c4c132624869bf16b4f31570e393a94e
7
+ data.tar.gz: e45c270929a89d80add771fa8da32e45332ca4fb02ca2cc6906192daad1a5c33687efad3d4ef5e73a490323961bc2a9ccdd997cd999edabeae412de2d86cd3bc
data/README.md CHANGED
@@ -50,6 +50,21 @@ Prometheus::Client.config.data_store = Prometheus::Client::DataStores::DirectFil
50
50
 
51
51
  **Note** if using direct file datastore it must be called before registering any metrics.
52
52
 
53
+ If using `resque` with prometheus and scraping your resque process via the `/metrics` endpoint is unfeasible consider setting up a
54
+ push gateway. Once set up, you can use the `after_event_block` to push metrics to your push gateway after every event is
55
+ complete.
56
+
57
+ ````ruby
58
+ Yabeda.configure do
59
+ Yabeda::ActiveJob.after_event_block = Proc.new do |event|
60
+ # do your pushing or any custom code here
61
+ end
62
+ Yabeda::ActiveJob.install!
63
+ end
64
+ ````
65
+
66
+ **Note**: Since the notifications are registered on install make sure to setup your after_event_block before calling install!
67
+
53
68
  ## Metrics
54
69
 
55
70
  - Total enqueued jobs: `activejob.enqueued_total` segmented by: queue, activejob(job class name), executions(number of executions)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Yabeda
4
4
  module ActiveJob
5
- VERSION = "0.3.1"
5
+ VERSION = "0.5.0"
6
6
  end
7
7
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "yabeda"
4
4
  require "yabeda/activejob/version"
5
+ require "active_support"
5
6
 
6
7
  module Yabeda
7
8
  # Small set of metrics on activejob jobs
@@ -11,6 +12,8 @@ module Yabeda
11
12
  30, 60, 120, 300, 1800, 3600, 21_600, # In cases jobs are very long-running
12
13
  ].freeze
13
14
 
15
+ mattr_accessor :after_event_block, default: proc { |_event| }
16
+
14
17
  # rubocop: disable Metrics/MethodLength, Metrics/BlockLength, Metrics/AbcSize
15
18
  def self.install!
16
19
  Yabeda.configure do
@@ -53,6 +56,7 @@ module Yabeda
53
56
 
54
57
  activejob_executed_total.increment(labels)
55
58
  activejob_runtime.measure(labels, Yabeda::ActiveJob.ms2s(event.duration))
59
+ Yabeda::ActiveJob.after_event_block.call(event) if Yabeda::ActiveJob.after_event_block.respond_to?(:call)
56
60
  end
57
61
 
58
62
  # start job event
@@ -68,6 +72,7 @@ module Yabeda
68
72
  labels.merge!(event.payload.slice(*Yabeda.default_tags.keys - labels.keys))
69
73
  job_latency = Yabeda::ActiveJob.job_latency(event)
70
74
  activejob_latency.measure(labels, job_latency) if job_latency.present?
75
+ Yabeda::ActiveJob.after_event_block.call(event) if Yabeda::ActiveJob.after_event_block.respond_to?(:call)
71
76
  end
72
77
 
73
78
  ActiveSupport::Notifications.subscribe "enqueue.active_job" do |*args|
@@ -81,6 +86,7 @@ module Yabeda
81
86
 
82
87
  labels.merge!(event.payload.slice(*Yabeda.default_tags.keys - labels.keys))
83
88
  activejob_enqueued_total.increment(labels)
89
+ Yabeda::ActiveJob.after_event_block.call(event) if Yabeda::ActiveJob.after_event_block.respond_to?(:call)
84
90
  end
85
91
  end
86
92
  end
@@ -90,7 +96,7 @@ module Yabeda
90
96
  enqueue_time = event.payload[:job].enqueued_at
91
97
  return nil unless enqueue_time.present?
92
98
 
93
- enqueue_time = Time.parse(enqueue_time).utc
99
+ enqueue_time = Time.parse(enqueue_time).utc unless enqueue_time.is_a?(Time)
94
100
  perform_at_time = Time.parse(event.end.to_s).utc
95
101
  (perform_at_time - enqueue_time)
96
102
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yabeda-activejob
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fullscript
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-29 00:00:00.000000000 Z
11
+ date: 2023-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -128,7 +128,7 @@ metadata:
128
128
  homepage_uri: https://github.com/Fullscript/yabeda-activejob
129
129
  source_code_uri: https://github.com/Fullscript/yabeda-activejob
130
130
  changelog_uri: https://github.com/Fullscript/yabeda-activejob/CHANGELOG.md
131
- post_install_message:
131
+ post_install_message:
132
132
  rdoc_options: []
133
133
  require_paths:
134
134
  - lib
@@ -143,8 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  requirements: []
146
- rubygems_version: 3.1.6
147
- signing_key:
146
+ rubygems_version: 3.3.7
147
+ signing_key:
148
148
  specification_version: 4
149
149
  summary: Yabeda Prometheus exporter for monitoring your activejobs
150
150
  test_files: []