Sha256: 697d23b332337db00736c5fe0c9717dfa0178bc46ff5ad241b1c5c52b9035828

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

require "daemons"

module Sad
	class Runner

		# === Example:
		#   options = {
		#     :app_name   => "my_app",
		#     :ARGV       => ['start', '-f', '--', 'param_for_myscript']
		#     :dir_mode   => :script,
		#     :dir        => 'pids',
		#     :multiple   => true,
		#     :ontop      => true,
		#     :mode       => :exec,
		#     :backtrace  => true,
		#     :monitor    => true
		#   }

		def self.exec(opts={})
			count = (ENV['COUNT'] && ENV['COUNT'].to_i)

			if count and count != 0
				count.times do |t|
					Daemons.run_proc("Sad-#{Sad::Config.queue(ENV['QUEUE'])}-#{t+1}", opts) do
						self.require_libs
						self.show_info
						::Sad.logger.reopen
						EM.run{
							Sad::Config.redis.send(:reconnect)
							Sad::Server.run(ENV['QUEUE'])
						}
					end
				end
			end
		end

		def self.show_info
			p "Interval:#{::Sad::Config.interval}"
		end

		def self.require_libs
			if ENV['LIBS']
				p "Require libs:"
				ENV['LIBS'].split(',').each do |f|
					file = File.join(ENV['SAD_OLD_ROOT'], f)
					p("===LIBS: #{file}")
					require file
				end
			end
		end
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sad-1.5.17 lib/sad/runner.rb
sad-1.5.16 lib/sad/runner.rb