Module: ActiveJobTracker
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/active_job_tracker.rb,
lib/active_job_tracker/engine.rb,
lib/active_job_tracker/version.rb,
lib/active_job_tracker/configuration.rb,
app/helpers/active_job_tracker/records_helper.rb,
lib/generators/active_job_tracker/migrations_generator.rb,
lib/generators/active_job_tracker/initializer_generator.rb
Defined Under Namespace
Modules: Generators, RecordsHelper
Classes: Configuration, Engine, Error
Constant Summary
collapse
- VERSION =
"0.3.0"
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.configuration ⇒ Object
12
13
14
|
# File 'lib/active_job_tracker.rb', line 12
def self.configuration
@configuration ||= Configuration.new
end
|
16
17
18
|
# File 'lib/active_job_tracker.rb', line 16
def self.configure
yield(configuration)
end
|
Instance Method Details
#active_job_tracker ⇒ Object
43
44
45
|
# File 'lib/active_job_tracker.rb', line 43
def active_job_tracker
@active_job_tracker ||= ::ActiveJobTrackerRecord.find_or_create_by(job_id: job_id, active_job_trackable: trackable)
end
|
#active_job_tracker_cache_threshold(value) ⇒ Object
31
32
33
|
# File 'lib/active_job_tracker.rb', line 31
def active_job_tracker_cache_threshold(value)
active_job_tracker.cache_threshold = value
end
|
#active_job_tracker_log_error(exception) ⇒ Object
73
74
75
76
77
78
79
80
81
|
# File 'lib/active_job_tracker.rb', line 73
def active_job_tracker_log_error(exception)
active_job_tracker.flush_progress_cache
active_job_tracker.update(
status: "failed",
failed_at: Time.current,
error: exception.message,
backtrace: exception.backtrace&.join("\n").to_s.truncate(1000)
)
end
|
#active_job_tracker_progress(cache: false, increment_by: 1) ⇒ Object
39
40
41
|
# File 'lib/active_job_tracker.rb', line 39
def active_job_tracker_progress(cache: false, increment_by: 1)
active_job_tracker.progress(use_cache: cache, increment_by: increment_by)
end
|
#active_job_tracker_target(target) ⇒ Object
35
36
37
|
# File 'lib/active_job_tracker.rb', line 35
def active_job_tracker_target(target)
active_job_tracker.update(target: target)
end
|
#initialize_tracker ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/active_job_tracker.rb', line 52
def initialize_tracker
active_job_tracker.update(
status: "pending",
started_at: nil,
completed_at: nil,
target: ActiveJobTracker.configuration.default_target,
current: 0
)
end
|
#mark_as_completed ⇒ Object
66
67
68
69
70
71
|
# File 'lib/active_job_tracker.rb', line 66
def mark_as_completed
active_job_tracker.flush_progress_cache
if active_job_tracker.current == active_job_tracker.target
active_job_tracker.update(status: "completed", completed_at: Time.current)
end
end
|
#mark_as_running ⇒ Object
62
63
64
|
# File 'lib/active_job_tracker.rb', line 62
def mark_as_running
active_job_tracker.update(status: "running", started_at: Time.current)
end
|
#trackable ⇒ Object
47
48
49
50
|
# File 'lib/active_job_tracker.rb', line 47
def trackable
raise ArgumentError, "Trackable object is required as the first argument." if arguments.empty?
arguments.first
end
|