Class: Workerholic::StatsStorage
- Inherits:
-
Object
- Object
- Workerholic::StatsStorage
- Defined in:
- lib/workerholic/statistics_storage.rb
Class Method Summary collapse
- .delete_expired_job_stats ⇒ Object
- .delete_memory_stats ⇒ Object
- .save_job(category, job) ⇒ Object
- .save_processes_memory_usage ⇒ Object
- .update_historical_stats(category, klass) ⇒ Object
Class Method Details
.delete_expired_job_stats ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/workerholic/statistics_storage.rb', line 32 def self.delete_expired_job_stats max_time = Time.now.to_i - 1001 StatsAPI.jobs_classes(false).each do |klass| storage.remove_range_from_set("workerholic:stats:completed_jobs:#{klass}", 0, max_time) storage.remove_range_from_set("workerholic:stats:failed_jobs:#{klass}", 0, max_time) end end |
.delete_memory_stats ⇒ Object
28 29 30 |
# File 'lib/workerholic/statistics_storage.rb', line 28 def self.delete_memory_stats storage.delete('workerholic:stats:memory:processes') end |
.save_job(category, job) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/workerholic/statistics_storage.rb', line 3 def self.save_job(category, job) job_hash = job.to_hash job_hash[:klass] = job.klass.to_s serialized_job_stats = JobSerializer.serialize(job_hash) namespace = "workerholic:stats:#{category}:#{job.klass}" storage.add_to_set(namespace, job.statistics.completed_at, serialized_job_stats) end |
.save_processes_memory_usage ⇒ Object
21 22 23 24 25 26 |
# File 'lib/workerholic/statistics_storage.rb', line 21 def self.save_processes_memory_usage PIDS.each do |pid| size = `ps -p #{Process.pid} -o pid=,rss=`.scan(/\d+/).last storage.hash_set('workerholic:stats:memory:processes', pid, size) end end |
.update_historical_stats(category, klass) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/workerholic/statistics_storage.rb', line 12 def self.update_historical_stats(category, klass) current_day_secs = Time.now.utc.to_i - (Time.now.utc.to_i % 86400) namespace = "workerholic:stats:historical:#{category}" namespace_with_class = "workerholic:stats:historical:#{category}:#{klass}" storage.hash_increment_field(namespace, current_day_secs, 1) storage.hash_increment_field(namespace_with_class, current_day_secs, 1) end |