Permalink
Browse files

More updates for ng gem.

  • Loading branch information...
1 parent 389938b commit 0e3cb60d26d0111b7703cb0f7301fef186a4802b @treeder treeder committed Aug 6, 2012
Showing with 16 additions and 18 deletions.
  1. +9 −9 config.ru
  2. +7 −9 hello.rb
View
@@ -12,18 +12,18 @@ rescue => ex
puts "Swallowed error: #{ex.message}"
end
@config = {} unless @config
-@config["iron"] ||= {}
-@config["iron"]["token"] ||= ENV['IRON_WORKER_TOKEN']
-@config["iron"]["project_id"] ||= ENV['IRON_WORKER_PROJECT_ID']
-
+@config["iron_worker"] ||= {}
+@config["iron_worker"]["token"] ||= ENV['IRON_WORKER_TOKEN']
+@config["iron_worker"]["project_id"] ||= ENV['IRON_WORKER_PROJECT_ID']
+@config["iron_mq"] ||= {}
+@config["iron_mq"]["token"] ||= ENV['IRON_MQ_TOKEN']
+@config["iron_mq"]["project_id"] ||= ENV['IRON_MQ_PROJECT_ID']
p @config
-IronWorker.configure do |iwc|
- iwc.token = @config["iron"]["token"]
- iwc.project_id = @config["iron"]["project_id"]
-end
+set :iron_worker, IronWorkerNG::Client.new(:token=>@config["iron_worker"]["token"], :project_id=>@config["iron_worker"]["project_id"])
-ironmq = IronMQ::Client.new('token' => @config["iron"]["token"], 'project_id' => @config["iron"]["project_id"])
+set :queue_name, "tweets"
+ironmq = IronMQ::Client.new(:token => @config["iron_mq"]["token"], :project_id => @config["iron_mq"]["project_id"])
#ironmq.logger.level = Logger::DEBUG
set :ironmq, ironmq
View
@@ -4,9 +4,6 @@
enable :sessions
set :public_folder, File.dirname(__FILE__) + '/static'
-#set :ironmq, IronMQ::Client.new('token'=>ENV['IRON_MQ_TOKEN'], 'project_id'=>ENV['IRON_MQ_PROJECT_ID'])
-set :iron_worker, IronWorkerNG::Client.new(:token=>ENV['IRON_WORKER_TOKEN'], :project_id=>ENV['IRON_WORKER_PROJECT_ID'])
-set :queue_name, "tweets"
post '/run_tweet_worker' do
@@ -31,15 +28,16 @@
get '/worker_status' do
puts 'worker_id in session? ' + session[:worker_id].inspect
if session[:worker_id]
- status = IronWorker.service.status(session[:worker_id])
- puts "status=" + status.inspect
+ task = settings.iron_worker.tasks.get(session[:worker_id])
+ #status = IronWorker.service.status(session[:worker_id])
+ puts "status=" + task.inspect
ret = {}
ret['msg'] = "Worker running"
ret['task_id'] = session[:worker_id]
- ret['status'] = status["status"]
- ret['percent'] = status['percent'] || 0
- ret['msg'] = status['msg'] || ""
- if status["status"] != "queued" && status["status"] != "running"
+ ret['status'] = task.status
+ ret['percent'] = task.percent || 0
+ ret['msg'] = task.msg || ""
+ if task.status != "queued" && task.status != "running"
session[:worker_id] = nil
end
return ret.to_json

0 comments on commit 0e3cb60

Please sign in to comment.