| 
									
										
										
										
											2014-10-22 15:01:55 +04:00
										 |  |  | #root = File.join(File.dirname(__FILE__), "..") | 
					
						
							|  |  |  | #$LOAD_PATH.push root unless $LOAD_PATH.include? root | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require File.join(File.dirname(__FILE__), "worker") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "commands/deploy" | 
					
						
							|  |  |  | require "db/mongo/models/server" | 
					
						
							| 
									
										
										
										
											2014-11-17 14:23:59 +03:00
										 |  |  | require "db/mongo/models/report" | 
					
						
							| 
									
										
										
										
											2014-10-22 15:01:55 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | class DeployWorker < Worker | 
					
						
							|  |  |  |   include DeployCommands | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-17 14:23:59 +03:00
										 |  |  |   def perform(dir, server, tags, owner, conf) | 
					
						
							| 
									
										
										
										
											2014-10-22 15:01:55 +04:00
										 |  |  |     set_status jid, "init" | 
					
						
							|  |  |  |     config = convert_config(conf) | 
					
						
							| 
									
										
										
										
											2014-11-17 14:23:59 +03:00
										 |  |  |     file = File.join(dir, jid) | 
					
						
							|  |  |  |     File.open(file, "w") do |out| | 
					
						
							| 
									
										
										
										
											2014-10-22 15:01:55 +04:00
										 |  |  |       begin | 
					
						
							|  |  |  |         set_status jid, "running" | 
					
						
							|  |  |  |         mongo = mongo_connector(config) | 
					
						
							| 
									
										
										
										
											2014-11-17 14:23:59 +03:00
										 |  |  |         s = Server.new(server) | 
					
						
							|  |  |  |         o = { | 
					
						
							|  |  |  |           "file" => file, | 
					
						
							|  |  |  |           "_id" => jid, | 
					
						
							|  |  |  |           "created_by" => owner, | 
					
						
							|  |  |  |           "project" => s.project, | 
					
						
							|  |  |  |           "deploy_env" => s.deploy_env, | 
					
						
							|  |  |  |           "type" => Report::DEPLOY_TYPE | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         mongo.save_report(Report.new(o)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         r = deploy_server_proc.call(out, s, mongo, tags) | 
					
						
							|  |  |  |         set_status jid, (r == 0 ? "completed" : "failed") | 
					
						
							| 
									
										
										
										
											2014-10-22 15:01:55 +04:00
										 |  |  |       rescue Exception => e | 
					
						
							|  |  |  |         out << "\n" | 
					
						
							|  |  |  |         out << e.message | 
					
						
							|  |  |  |         out << "\n" | 
					
						
							|  |  |  |         out << e.backtrace.join("\n") | 
					
						
							|  |  |  |         set_status jid, "failed" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |