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.2.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configurationObject



11
12
13
# File 'lib/active_job_tracker.rb', line 11

def self.configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



15
16
17
# File 'lib/active_job_tracker.rb', line 15

def self.configure
  yield(configuration)
end

Instance Method Details

#active_job_trackerObject



42
43
44
# File 'lib/active_job_tracker.rb', line 42

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



30
31
32
# File 'lib/active_job_tracker.rb', line 30

def active_job_tracker_cache_threshold(value)
  active_job_tracker.cache_threshold = value
end

#active_job_tracker_log_error(exception) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/active_job_tracker.rb', line 72

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) ⇒ Object



38
39
40
# File 'lib/active_job_tracker.rb', line 38

def active_job_tracker_progress(cache: false)
  active_job_tracker.progress(cache)
end

#active_job_tracker_target(target) ⇒ Object



34
35
36
# File 'lib/active_job_tracker.rb', line 34

def active_job_tracker_target(target)
  active_job_tracker.update(target: target)
end

#initialize_trackerObject



51
52
53
54
55
56
57
58
59
# File 'lib/active_job_tracker.rb', line 51

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_completedObject



65
66
67
68
69
70
# File 'lib/active_job_tracker.rb', line 65

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_runningObject



61
62
63
# File 'lib/active_job_tracker.rb', line 61

def mark_as_running
  active_job_tracker.update(status: "running", started_at: Time.current)
end

#trackableObject

Raises:

  • (ArgumentError)


46
47
48
49
# File 'lib/active_job_tracker.rb', line 46

def trackable
  raise ArgumentError, "Trackable object is required as the first argument." if arguments.empty?
  arguments.first
end