Permalink
Browse files

finally got all emails working and added whenever scheduling to the p…

…roject
  • Loading branch information...
1 parent 94a823e commit 927cb86ede2783d548665423a7c3822cf9a24c72 @bentut committed Jan 11, 2012
View
@@ -13,6 +13,7 @@ gem 'httpclient'
gem 'devise', '1.1.2'
gem 'spork', '~> 0.9.0.rc'
gem 'rubyzip', '~> 0.9.4'
+gem 'whenever', :require => false
# Use unicorn as the web server
# gem 'unicorn'
View
@@ -41,6 +41,7 @@ GEM
childprocess (0.2.0)
ffi (~> 1.0.6)
choice (0.1.4)
+ chronic (0.6.6)
cucumber (1.0.2)
builder (>= 2.1.2)
diff-lcs (>= 1.1.2)
@@ -144,6 +145,9 @@ GEM
warden (0.10.7)
rack (>= 1.0.0)
watchr (0.7)
+ whenever (0.7.2)
+ activesupport (>= 2.3.4)
+ chronic (~> 0.6.3)
xpath (0.1.4)
nokogiri (~> 1.3)
@@ -164,3 +168,4 @@ DEPENDENCIES
spork (~> 0.9.0.rc)
test-unit (= 1.2.3)
watchr
+ whenever
@@ -1,10 +1,27 @@
class PackagerMailer < ActionMailer::Base
default :from => "udaman@hawaii.edu"
- def rake_notification(rake_task, download_string, error_string, summary_string)
- @download_string = download_string
- @error_string = error_string
- @summary_string = summary_string
- mail(:to => ["bentut@gmail.com","btrevino@hawaii.edu"], :subject => "UDAMAN New Download or Error (#{rake_task})")
+ # def rake_notification(rake_task, download_string, error_string, summary_string)
+ # @download_string = download_string
+ # @error_string = error_string
+ # @summary_string = summary_string
+ # mail(:to => ["bentut@gmail.com","btrevino@hawaii.edu"], :subject => "UDAMAN New Download or Error (#{rake_task})")
+ # end
+
+ def rake_notification(rake_task, download_results, errors, series, output_path, dates)
+ @download_results = download_results
+ @errors = errors
+ @series = series
+ @output_path = output_path
+ @dates = dates
+ mail(:to => ["btrevino@hawaii.edu", "jchfung@hawaii.edu", "james29@hawaii.edu", "icintina@gmail.com", "fuleky@hawaii.edu", "bonham@hawaii.edu"], :subject => "UDAMAN New Download or Error (#{rake_task})")
end
+
+ def rake_error(e, output_path)
+ @error = e
+ @output_path = output_path
+ mail(:to => ["btrevino@hawaii.edu"], :subject => "Rake failed in an unexpected way")
+ end
+
+
end
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
+ </head>
+ <body>
+ <h1>Error Message</h1>
+ <p><%= @error.message %></p>
+
+ <h1>Output Path</h1>
+ <p><%= @output_path %></p>
+
+ </body>
+</html>
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
+ </head>
+ <body>
+ <h1>Download Results</h1>
+ <table>
+ <% @download_results.each do |handle, hash| %>
+ <tr><td><%= handle %></td><td><%= hash[:changed] ? "c" : " " %></td><td><%= hash[:status] == 200 ? "Success" : "Error (#{hash[:status]})" %></td></tr>
+ <% end %>
+ </table>
+
+ <h1>File Written</h1>
+ <p><%= @output_path %></p>
+
+ <% if @errors != [] %>
+ <h1>Broken Series</h1>
+ <% @errors.each do |error| %>
+ <p>
+ <strong><%= error[:series] %></strong><br>
+ <em><%= error[:error] %></em><br>
+ <%= error[:definition] %><br>
+ </p>
+ <% end %>
+ <% end %>
+
+ <h1>Downloaded Series</h1>
+ <%
+ sorted= @dates.sort
+ date3 = sorted[-1]
+ date2 = sorted[-2]
+ date1 = sorted[-3]
+ %>
+
+ <table>
+ <tr><td></td><td><%= date1 %></td><td><%= date2 %></td><td><%= date3 %></td></tr>
+ <% @series.each do |series, data| %>
+ <tr><td><%= series %></td><td><%= data[date1] %></td><td><%= data[date2] %></td><td><%= data[date3] %></td></tr>
+ <% end %>
+ </table>
+ </body>
+</html>
View
@@ -0,0 +1,66 @@
+# Use this file to easily define all of your cron jobs.
+#
+# It's helpful, but not entirely necessary to understand cron before proceeding.
+# http://en.wikipedia.org/wiki/Cron
+
+# Example:
+#
+# set :output, "/path/to/my/cron_log.log"
+#
+# every 2.hours do
+# command "/usr/bin/some_great_command"
+# runner "MyModel.some_method"
+# rake "some:great:rake:task"
+# end
+#
+# every 4.days do
+# runner "AnotherModel.prune_old_records"
+# end
+
+# Learn more: http://github.com/javan/whenever
+
+hour = "1"
+set :output, "~/Documents/cronlog/udaman-download.log"
+set :environment, "development"
+job_type :rake, "cd :path && rake :task :output"
+#job_type :rake, "cd :path && RAILS_ENV=:environment bundle exec rake :task :output"
+
+every 1.day, :at => "#{hour}:37 am" do
+ rake "jp_upd_a"
+ rake "jp_upd_q"
+ rake "jp_upd_m"
+end
+
+every 1.day, :at => "#{hour}:38 am" do
+ rake "gsp_upd"
+ rake "inc_upd_q"
+ rake "inc_upd_a"
+end
+
+every 1.day, :at => "#{hour}:39 am" do
+ rake "bls_cpi_upd_m"
+ rake "bls_job_upd_m"
+ rake "bls_job_upd_s"
+end
+
+every 1.day, :at => "#{hour}:40 am" do
+ rake "uic_upd"
+ rake "const_upd_q"
+ rake "const_upd_m"
+end
+
+every 1.day, :at => "#{hour}:41 am" do
+ rake "tax_upd"
+end
+
+every 1.day, :at => "#{hour}:42 am" do
+ rake "tour_PC_upd"
+ rake "tour_seats_upd"
+ rake "tour_upd"
+end
+
+every 1.day, :at => "#{hour}:43 am" do
+ rake "us_upd_a"
+ rake "us_upd_q"
+ rake "us_upd_m"
+end
@@ -34,6 +34,7 @@ def set_xls_sheet
end
def download_results
+ @download_results ||= {}
@download_results
end
View
@@ -91,10 +91,15 @@ def add_definitions (definitions_hash)
end
def write_definitions_to(output_path = "udaman")
- return write_to_db if output_path == "udaman"
- @output_path = ENV["JON"] == "true" ? output_path.gsub("UHEROwork", "UHEROwork-1") : output_path
- @output_filename = @output_path.split("/")[-1]
- write_xls
+ begin
+ return write_to_db if output_path == "udaman"
+ @output_path = ENV["JON"] == "true" ? output_path.gsub("UHEROwork", "UHEROwork-1") : output_path
+ @output_filename = @output_path.split("/")[-1]
+ write_xls
+ rescue Exception => e
+ PackagerMailer.rake_error(e, output_path).deliver
+ raise e
+ end
end
def write_to_db
@@ -138,7 +143,8 @@ def write_xls
puts download_problem?
backup(old_file) unless old_file.nil?
puts "SENDING EMAIL"
- PackagerMailer.rake_notification("none entered", download_results_string, errors_string, series_summary_string).deliver
+ #PackagerMailer.rake_notification("none entered", download_results_string, errors_string, series_summary_string).deliver
+ PackagerMailer.rake_notification("none entered", download_results, errors, @series, @output_path, dates).deliver
end
end
@@ -159,9 +165,10 @@ def get_data_from_definitions
Series.open_cached_files
series = {}
@definitions.each do |series_name, definition|
- puts series_name#+": "+definition
+ #puts series_name#+": "+definition
begin
- series[series_name] = eval(definition).data
+ def_data = eval(definition).data
+ series[series_name] = def_data.nil? ? {} : def_data
rescue Exception => e
#puts "error for #{series_name}!!"
@errors.push({ :series => series_name, :definition => definition, :error => e.message })
@@ -185,6 +192,7 @@ def dates
dates_array = []
return [] if @series.nil?
@series.each do |series_name, data|
+ #puts series_name
dates_array |= data.keys
end
dates_array.sort
Oops, something went wrong.

0 comments on commit 927cb86

Please sign in to comment.