Module: Notable
- Defined in:
- lib/notable.rb,
lib/notable/engine.rb,
lib/notable/version.rb,
app/models/notable/job.rb,
lib/notable/middleware.rb,
app/models/notable/request.rb,
lib/notable/debug_exceptions.rb,
lib/notable/validation_errors.rb,
lib/notable/unverified_request.rb,
lib/notable/job_backends/sidekiq.rb,
lib/notable/job_backends/delayed_job.rb,
lib/generators/notable/jobs_generator.rb,
lib/generators/notable/requests_generator.rb
Defined Under Namespace
Modules: DebugExceptions, Generators, JobBackends, UnverifiedRequest, ValidationErrors Classes: Engine, Job, Middleware, Request
Constant Summary collapse
- VERSION =
"0.1.0"
Class Attribute Summary collapse
-
.enabled ⇒ Object
Returns the value of attribute enabled.
-
.slow_job_threshold ⇒ Object
Returns the value of attribute slow_job_threshold.
-
.slow_request_threshold ⇒ Object
Returns the value of attribute slow_request_threshold.
-
.track_job_method ⇒ Object
jobs.
-
.track_request_method ⇒ Object
requests.
-
.user_method ⇒ Object
Returns the value of attribute user_method.
Class Method Summary collapse
- .clear_notes ⇒ Object
- .notes ⇒ Object
- .track(note_type, note = nil) ⇒ Object
- .track_error(e) ⇒ Object
- .track_job(job, job_id, queue, created_at, &block) ⇒ Object
Class Attribute Details
.enabled ⇒ Object
Returns the value of attribute enabled.
24 25 26 |
# File 'lib/notable.rb', line 24 def enabled @enabled end |
.slow_job_threshold ⇒ Object
Returns the value of attribute slow_job_threshold.
33 34 35 |
# File 'lib/notable.rb', line 33 def slow_job_threshold @slow_job_threshold end |
.slow_request_threshold ⇒ Object
Returns the value of attribute slow_request_threshold.
29 30 31 |
# File 'lib/notable.rb', line 29 def slow_request_threshold @slow_request_threshold end |
.track_job_method ⇒ Object
jobs
32 33 34 |
# File 'lib/notable.rb', line 32 def track_job_method @track_job_method end |
.track_request_method ⇒ Object
requests
27 28 29 |
# File 'lib/notable.rb', line 27 def track_request_method @track_request_method end |
.user_method ⇒ Object
Returns the value of attribute user_method.
28 29 30 |
# File 'lib/notable.rb', line 28 def user_method @user_method end |
Class Method Details
.clear_notes ⇒ Object
58 59 60 |
# File 'lib/notable.rb', line 58 def self.clear_notes RequestStore.store.delete(:notable_notes) end |
.notes ⇒ Object
54 55 56 |
# File 'lib/notable.rb', line 54 def self.notes RequestStore.store[:notable_notes].to_a end |
.track(note_type, note = nil) ⇒ Object
46 47 48 |
# File 'lib/notable.rb', line 46 def self.track(note_type, note = nil) (RequestStore.store[:notable_notes] ||= []) << {note_type: note_type, note: note} end |
.track_error(e) ⇒ Object
50 51 52 |
# File 'lib/notable.rb', line 50 def self.track_error(e) track "Error", "#{e.class.name}: #{e.message}" end |
.track_job(job, job_id, queue, created_at, &block) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/notable.rb', line 62 def self.track_job(job, job_id, queue, created_at, &block) if Notable.enabled exception = nil notes = nil start_time = Time.now queued_time = start_time - created_at begin yield rescue Exception => e exception = e track_error(e) ensure notes = Notable.notes Notable.clear_notes end runtime = Time.now - start_time safely do notes << {note_type: "Slow Job"} if runtime > Notable.slow_job_threshold notes.each do |note| data = { note_type: note[:note_type], note: note[:note], job: job, job_id: job_id, queue: queue, runtime: runtime, queued_time: queued_time } Notable.track_job_method.call(data) end end raise exception if exception else yield end end |