Sha256: 0dad0df65e20eeddb51f5d654299a867d1fba33a4c78022833ff6caad689aad6

Contents?: true

Size: 987 Bytes

Versions: 1

Compression:

Stored size: 987 Bytes

Contents

module ChronoTrigger
  
  class Process

    def run(options={})
      @thread = Thread.new do
        setup(options)
        
        shell = ChronoTrigger::Shell.new
        options[:trigger_files] ? shell.load_triggers(options[:trigger_files].split(":")) : shell.load_triggers 
        loop do
          shell.execute_triggers
          sleep 1.minute.to_i
        end
      end
      
      @thread.join
    end
    
    def stop
      @thread.exit
    end
    
    private
    def setup(options={})
      if application_context = options[:application_context]
        ENV['RAILS_ENV'] = options[:env] || "development"
        
        application_path = File.join(application_context, 'config', 'environment')
        STDOUT.puts "Loading application environment at #{File.join(application_context, 'config', 'environment')} for '#{ENV['RAILS_ENV']}' environment."
        require(application_path)              
      end
      
      require "chrono_trigger"
    end
  end    
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
chrono_trigger-0.2.1 lib/chrono_trigger/process.rb