lib/gaspar.rb in gaspar-0.1.1 vs lib/gaspar.rb in gaspar-0.1.2

- old
+ new

@@ -52,10 +52,14 @@ def log(logger, message) logger.debug "[%s] %s" % ["Gaspar".yellow, message] if logger end end + def can_run_if(&block) + @can_run_if = block + end + def before_each(&block) self.class.set_callback :run, :before, &block end def after_each(&block) @@ -98,10 +102,17 @@ def lock @lock.synchronize { yield } end + def can_run? + return false if STDOUT.tty? or STDERR.tty? + return false if @can_run_if and @can_run_if.call == false + return false if Object.const_defined? :Rails and Rails.env.test? and !@options[:permit_test_mode] + return true + end + def schedule(method, timing, args = [], options = {}, &block) if block_given? options[:name] ||= args.first else klass, worker_args = *args @@ -157,13 +168,10 @@ @options[:worker] ||= :sidekiq if Object.const_defined? :Sidekiq @options[:worker] ||= :resque if Object.const_defined? :Resque end def start!(redis) - return log "Running under a controlling TTY. Refusing to start. Try starting from a daemonized process." if STDOUT.tty? or STDERR.tty? - if Object.const_defined? :Rails and Rails.env.test? - return unless @options[:permit_test_mode] - end + return log "Running under a controlling TTY. Refusing to start. Try starting from a daemonized process." unless can_run? @redis = redis return if @started \ No newline at end of file