lib/right_chimp/daemon/ChimpDaemon.rb in right_chimp-2.1.0 vs lib/right_chimp/daemon/ChimpDaemon.rb in right_chimp-2.1.2
- old
+ new
@@ -5,11 +5,12 @@
#
module Chimp
class ChimpDaemon
- attr_accessor :verbose, :debug, :port, :concurrency, :delay, :retry_count, :dry_run, :logfile, :chimp_queue
+ attr_accessor :verbose, :debug, :port, :concurrency, :delay, :retry_count,
+ :dry_run, :logfile, :chimp_queue, :proc_counter, :semaphore
attr_reader :queue, :running
include Singleton
def initialize
@@ -21,11 +22,14 @@
@retry_count = 0
@threads = []
@running = false
@queue = ChimpQueue.instance
@chimp_queue = Queue.new
+ @semaphore = Mutex.new
+ @proc_counter= 0
+
#Connect to the API
Connection.instance
end
#
@@ -400,10 +404,14 @@
# tasks.each do |task|
# q.push(group, task)
# end
if verb == 'process' or verb == 'add'
ChimpDaemon.instance.chimp_queue.push payload
+ ChimpDaemon.instance.semaphore.synchronize do
+ ChimpDaemon.instance.proc_counter +=1
+ end
+ Log.debug "Tasks in the processing queue: #{ChimpDaemon.instance.proc_counter.to_s}"
id = 0
elsif verb == 'update'
puts "UPDATE"
q.get_job(job_id).status = payload.status
end
@@ -520,10 +528,27 @@
else
template_path = 'lib/right_chimp/templates'
end
#
+ # Check if we are asked for stats
+ #
+ if req.request_uri.path =~ /stats/
+ queue = ChimpQueue.instance
+ stats = ""
+ stats << "running: #{queue.get_jobs_by_status(:running).size} / "
+ stats << "failed: #{queue.get_jobs_by_status(:error).size} / "
+ stats << "done: #{queue.get_jobs_by_status(:done).size} / "
+ stats << "processing: #{ChimpDaemon.instance.proc_counter.to_s} / "
+ stats << "\n"
+
+ resp.body = stats
+
+ raise WEBrick::HTTPStatus::OK
+ end
+
+ #
# Check for static CSS files and serve them
#
if req.request_uri.path =~ /\.(css|js)$/
filename = req.request_uri.path.split('/').last
resp.body = File.read(File.join(template_path, filename))
@@ -552,9 +577,10 @@
count_jobs_running = queue.get_jobs_by_status(:running).size
count_jobs_queued = queue.get_jobs_by_status(:none).size
count_jobs_holding = queue.get_jobs_by_status(:holding).size
count_jobs_failed = queue.get_jobs_by_status(:error).size
count_jobs_done = queue.get_jobs_by_status(:done).size
+ count_jobs_processing = queue.get_jobs_by_status(:processing).size
resp.body = @template.result(binding)
raise WEBrick::HTTPStatus::OK
end
end