forked from esquith/yabeda-activejob
-
Notifications
You must be signed in to change notification settings - Fork 6
Cleanup project and testing matrix #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
195016d
Update README.md
andrewmarkle 180026f
Fix github workflow
andrewmarkle c76e63e
UPdate test runners
andrewmarkle d689dd4
Update
andrewmarkle 7b7d96c
Update gemfile
andrewmarkle cc6cc3d
Add back testing for rails 7
andrewmarkle 5fa5dba
Try this
andrewmarkle c27f537
Merge remote-tracking branch 'origin/main' into andrewmarkle-patch-1
andrewmarkle 794c25b
Fix rubocop
andrewmarkle e7fea9d
Fix tests, update changelog, update testing matrix to include rails 8.1
andrewmarkle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| source "https://rubygems.org" | ||
| git_source(:github) { |repo| "https://github.com/#{repo}.git" } | ||
|
|
||
| gem "rails", "~> 8.1.0" | ||
|
|
||
| eval_gemfile "../Gemfile" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,105 +1,110 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class Yabeda::ActiveJob::EventHandler | ||
| def initialize(*event_args) | ||
| @event = ActiveSupport::Notifications::Event.new(*event_args) | ||
| end | ||
| module Yabeda | ||
| module ActiveJob | ||
| class EventHandler | ||
| def initialize(*event_args) | ||
| @event = ActiveSupport::Notifications::Event.new(*event_args) | ||
| end | ||
|
|
||
| def handle_perform | ||
| labels = { | ||
| activejob: event.payload[:job].class.to_s, | ||
| queue: event.payload[:job].queue_name.to_s, | ||
| executions: event.payload[:job].executions.to_s, | ||
| } | ||
| if event.payload[:exception].present? | ||
| Yabeda.activejob_failed_total.increment( | ||
| labels.merge(failure_reason: event.payload[:exception].first.to_s), | ||
| ) | ||
| else | ||
| Yabeda.activejob_success_total.increment(labels) | ||
| end | ||
| def handle_perform | ||
| labels = { | ||
| activejob: event.payload[:job].class.to_s, | ||
| queue: event.payload[:job].queue_name.to_s, | ||
| executions: event.payload[:job].executions.to_s, | ||
| } | ||
| if event.payload[:exception].present? | ||
| Yabeda.activejob_failed_total.increment( | ||
| labels.merge(failure_reason: event.payload[:exception].first.to_s), | ||
| ) | ||
| else | ||
| Yabeda.activejob_success_total.increment(labels) | ||
| end | ||
|
|
||
| Yabeda.activejob_executed_total.increment(labels) | ||
| Yabeda.activejob_runtime.measure(labels, ms2s(event.duration)) | ||
| call_after_event_block | ||
| end | ||
| Yabeda.activejob_executed_total.increment(labels) | ||
| Yabeda.activejob_runtime.measure(labels, ms2s(event.duration)) | ||
| call_after_event_block | ||
| end | ||
andrewmarkle marked this conversation as resolved.
Show resolved
Hide resolved
andrewmarkle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def handle_perform_start | ||
| labels = common_labels(event.payload[:job]) | ||
| def handle_perform_start | ||
| labels = common_labels(event.payload[:job]) | ||
|
|
||
| job_latency_value = job_latency | ||
| Yabeda.activejob_latency.measure(labels, job_latency_value) if job_latency_value.present? | ||
| call_after_event_block | ||
| end | ||
| job_latency_value = job_latency | ||
| Yabeda.activejob_latency.measure(labels, job_latency_value) if job_latency_value.present? | ||
| call_after_event_block | ||
| end | ||
|
|
||
| def handle_enqueue | ||
| labels = common_labels(event.payload[:job]) | ||
| def handle_enqueue | ||
| labels = common_labels(event.payload[:job]) | ||
|
|
||
| Yabeda.activejob_enqueued_total.increment(labels) | ||
| Yabeda.activejob_enqueued_total.increment(labels) | ||
|
|
||
| call_after_event_block | ||
| end | ||
| call_after_event_block | ||
| end | ||
|
|
||
| def handle_enqueue_at | ||
| labels = common_labels(event.payload[:job]) | ||
| def handle_enqueue_at | ||
| labels = common_labels(event.payload[:job]) | ||
|
|
||
| Yabeda.activejob_scheduled_total.increment(labels) | ||
| Yabeda.activejob_scheduled_total.increment(labels) | ||
|
|
||
| call_after_event_block | ||
| end | ||
| call_after_event_block | ||
| end | ||
|
|
||
| def handle_enqueue_all | ||
| event.payload[:jobs].each do |job| | ||
| labels = common_labels(job) | ||
| def handle_enqueue_all | ||
| event.payload[:jobs].each do |job| | ||
| labels = common_labels(job) | ||
|
|
||
| if job.scheduled_at | ||
| Yabeda.activejob_scheduled_total.increment(labels) | ||
| else | ||
| Yabeda.activejob_enqueued_total.increment(labels) | ||
| if job.scheduled_at | ||
| Yabeda.activejob_scheduled_total.increment(labels) | ||
| else | ||
| Yabeda.activejob_enqueued_total.increment(labels) | ||
| end | ||
| end | ||
|
|
||
| call_after_event_block | ||
| end | ||
| end | ||
|
|
||
| call_after_event_block | ||
| end | ||
| private | ||
|
|
||
| private | ||
| attr_reader :event | ||
| attr_reader :event | ||
|
|
||
| def job_latency | ||
| return unless (enqueue_time = event.payload[:job].enqueued_at) | ||
|
|
||
| def job_latency | ||
| if enqueue_time = event.payload[:job].enqueued_at | ||
| enqueue_time = parse_event_time(enqueue_time) | ||
| perform_at_time = parse_event_time(event.end) | ||
|
|
||
| perform_at_time - enqueue_time | ||
| end | ||
| end | ||
|
|
||
| def ms2s(milliseconds) | ||
| (milliseconds.to_f / 1000).round(3) | ||
| end | ||
| def ms2s(milliseconds) | ||
| (milliseconds.to_f / 1000).round(3) | ||
| end | ||
|
|
||
| def parse_event_time(time) | ||
| case time | ||
| when Time then time | ||
| when String then Time.parse(time).utc | ||
| else | ||
| if time > 1e12 | ||
| Time.at(ms2s(time)).utc | ||
| def parse_event_time(time) | ||
| case time | ||
| when Time then time | ||
| when String then Time.parse(time).utc | ||
| else | ||
| Time.at(time).utc | ||
| if time > 1e12 | ||
| Time.at(ms2s(time)).utc | ||
| else | ||
| Time.at(time).utc | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def common_labels(job) | ||
| Yabeda.default_tags.reverse_merge( | ||
| activejob: job.class.to_s, | ||
| queue: job.queue_name, | ||
| executions: job.executions.to_s, | ||
| ) | ||
| end | ||
| def common_labels(job) | ||
| Yabeda.default_tags.reverse_merge( | ||
| activejob: job.class.to_s, | ||
| queue: job.queue_name, | ||
| executions: job.executions.to_s, | ||
| ) | ||
| end | ||
|
|
||
| def call_after_event_block | ||
| Yabeda::ActiveJob.after_event_block.call(event) if Yabeda::ActiveJob.after_event_block.respond_to?(:call) | ||
| def call_after_event_block | ||
| Yabeda::ActiveJob.after_event_block.call(event) if Yabeda::ActiveJob.after_event_block.respond_to?(:call) | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.