Created
May 19, 2009 18:48
-
-
Save jpemberthy/114314 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require File.expand_path(File.dirname(__FILE__)) + '/../../config/boot' | |
| rails_root = File.expand_path RAILS_ROOT | |
| ENV["RAILS_ENV"] ||= "production" | |
| Dir.chdir(rails_root) # Change current directory to RAILS_ROOT | |
| require "config/environment" # Start up rails | |
| require 'stock.rb' | |
| $running = true | |
| Signal.trap("TERM") do | |
| $running = false | |
| end | |
| while($running) do | |
| #makes work the production logger. | |
| RAILS_DEFAULT_LOGGER.auto_flushing = 1 | |
| s = Stock.new | |
| col_time = s.time | |
| if s.open? | |
| #Hopefully using this statment we dont have to use a monitor. | |
| ActiveRecord::Base.connection.reconnect! | |
| s.parsing | |
| ActiveRecord::Base.logger.info "Getting Stock info at #{col_time}.\n" | |
| #lets close the logger. | |
| RAILS_DEFAULT_LOGGER.auto_flushing = 1000 | |
| sleep 1200 #1200 secs = 20 mins. | |
| else | |
| if(col_time > s.close_time) | |
| Record.delete_last_history_day(s) | |
| ActiveRecord::Base.logger.info "Deleting last day records, last day => '#{s.last_day}'" | |
| end | |
| ActiveRecord::Base.logger.info "Sleeping at #{col_time}.\n" | |
| RAILS_DEFAULT_LOGGER.auto_flushing = 1000 | |
| sleep s.secs_til_open #sleeps til next open day. | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment