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
31 32 33 34 35 36 37 |
# File 'lib/workerholic/statistics_storage.rb', line 31 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
27 28 29 |
# File 'lib/workerholic/statistics_storage.rb', line 27 def self.delete_memory_stats storage.delete('workerholic:stats:memory:processes') end |
.save_job(category, job) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/workerholic/statistics_storage.rb', line 3 def self.save_job(category, job) job_hash = job.to_hash 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
20 21 22 23 24 25 |
# File 'lib/workerholic/statistics_storage.rb', line 20 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
11 12 13 14 15 16 17 18 |
# File 'lib/workerholic/statistics_storage.rb', line 11 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 |