diff --git a/Gemfile b/Gemfile index d1afdb8cc..d61290921 100644 --- a/Gemfile +++ b/Gemfile @@ -19,6 +19,9 @@ gem "mongo_session_store-rails3" gem 'nokogiri' gem 'radius' gem 'rake' +gem 'resque' # background jobs +gem 'resque-scheduler' # job scheduling +gem 'resque-restriction' gem 'ruby-debug19' gem 'rubyzip' gem 'sinatra' diff --git a/Gemfile.lock b/Gemfile.lock index 71742974a..16acce214 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -153,6 +153,20 @@ GEM rake (0.9.2.2) rdoc (3.12) json (~> 1.4) + redis (2.2.2) + redis-namespace (1.0.3) + redis (< 3.0.0) + resque (1.20.0) + multi_json (~> 1.0) + redis-namespace (~> 1.0.2) + sinatra (>= 0.9.2) + vegas (~> 0.1.2) + resque-restriction (0.3.0) + resque (>= 1.7.0) + resque-scheduler (1.9.9) + redis (>= 2.0.1) + resque (>= 1.8.0) + rufus-scheduler rspec (2.8.0) rspec-core (~> 2.8.0) rspec-expectations (~> 2.8.0) @@ -182,6 +196,8 @@ GEM ruby_parser (2.3.1) sexp_processor (~> 3.0) rubyzip (0.9.6.1) + rufus-scheduler (2.0.16) + tzinfo (>= 0.3.23) ruport (1.6.3) fastercsv pdf-writer (= 1.1.8) @@ -222,6 +238,8 @@ GEM uglifier (1.2.3) execjs (>= 0.3.0) multi_json (>= 1.0.2) + vegas (0.1.11) + rack (>= 1.0.0) warden (1.1.1) rack (>= 1.0) watchr (0.7) @@ -259,6 +277,9 @@ DEPENDENCIES radius rails (>= 3.1.0, < 3.2.0) rake + resque + resque-restriction + resque-scheduler rspec (~> 2.0) rspec-rails (~> 2.0) ruby-debug19 diff --git a/Rakefile b/Rakefile index 9a495de7b..e0dc9c5b8 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,9 @@ +# /usr/bin/ruby -Ku # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) +require 'resque/tasks' require 'rake/dsl_definition' require 'rake' diff --git a/app/jobs/fetch_time.rb b/app/jobs/fetch_time.rb new file mode 100644 index 000000000..5fce3036c --- /dev/null +++ b/app/jobs/fetch_time.rb @@ -0,0 +1,15 @@ +# require 'open-uri' +# require 'nokogiri' +class FetchTime < Resque::Plugins::RestrictionJob + restrict :per_300 => 10 + + @queue = :low + + def self.perform() +# sleep 10 + doc = Nokogiri::HTML(open('http://www.timeanddate.com/worldclock/city.html?n=241')) + CronMail.time_check(doc.at('#ct').children.first.text).deliver + puts "Mail Sent" + true + end +end diff --git a/app/jobs/nccu_calendar.rb b/app/jobs/nccu_calendar.rb new file mode 100644 index 000000000..1848c6918 --- /dev/null +++ b/app/jobs/nccu_calendar.rb @@ -0,0 +1,12 @@ +class NccuCalendar + require 'open-uri' + @queue = :high + + def self.perform() + File.open(File.join(Rails.root, 'public/static', 'nccu_calendar.rss'),'w') do |file| + file << open('http://events.nccu.edu.tw/Feed').read + CronMail.time_check("NCCU Calendar synced").deliver + end + puts "NccuCalendar Synced" + end +end diff --git a/app/jobs/sync_db.rb b/app/jobs/sync_db.rb new file mode 100644 index 000000000..d4bda7901 --- /dev/null +++ b/app/jobs/sync_db.rb @@ -0,0 +1,15 @@ +class SyncDb + + @queue = :high + + def self.perform() + self.start_sync + end + + def self.start_sync + task = 'mid_site:sync' + args = [] + %x[rake #{task} --trace >> #{Rails.root}/log/rake.log] + puts "SyncDb Synced" + end +end diff --git a/app/mailer/cron_mail.rb b/app/mailer/cron_mail.rb new file mode 100644 index 000000000..8a4c97009 --- /dev/null +++ b/app/mailer/cron_mail.rb @@ -0,0 +1,8 @@ +class CronMail < ActionMailer::Base + default :from => "orbit_test@rulingcom.com" + + def time_check(msg) + #attachments["rails.png"] = File.read("#{Rails.root}/public/images/rails.png") + mail(:to => "Matt ", :subject => msg) + end +end \ No newline at end of file diff --git a/app/views/admin/sites/_side_bar.html.erb b/app/views/admin/sites/_side_bar.html.erb new file mode 100644 index 000000000..4b25835ef --- /dev/null +++ b/app/views/admin/sites/_side_bar.html.erb @@ -0,0 +1,12 @@ +<%= content_tag :li, :class => active_for_controllers('sites') do -%> + <%= link_to content_tag(:i, nil, :class => 'icons-cog') + t('admin.site_settings'), admin_site_site_info_path(@site) %> + + <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('sites')) do -%> + <%= content_tag :li, link_to(t('admin.site_info'), admin_site_site_info_path(@site)), :class => active_for_action('sites', 'site_info') %> + <%= content_tag :li, link_to(t('admin.system_info'), admin_site_system_info_path(@site)), :class => active_for_action('sites', 'system_info') %> + <%= content_tag :li, link_to(t('admin.language'), admin_site_language_path(@site)), :class => active_for_action('sites', 'language') %> + <%= content_tag :li, link_to(t('admin.mail_setting'), admin_site_mail_setting_path(@site)), :class => active_for_action('sites', 'mail_setting') %> + <%= content_tag :li, link_to(t('admin.ui_theme'), admin_site_ui_theme_path(@site)), :class => active_for_action('sites', 'ui_theme') %> + <% end -%> + +<% end -%> diff --git a/app/views/admin/sites/language.html.erb b/app/views/admin/sites/language.html.erb index ceb9b0124..2b6265641 100644 --- a/app/views/admin/sites/language.html.erb +++ b/app/views/admin/sites/language.html.erb @@ -1 +1,5 @@ +<% content_for :side_bar do %> + <%= render 'side_bar' %> +<% end %> + language.html.erb \ No newline at end of file diff --git a/app/views/admin/sites/mail_setting.html.erb b/app/views/admin/sites/mail_setting.html.erb index 3a52ede2b..aaef18571 100644 --- a/app/views/admin/sites/mail_setting.html.erb +++ b/app/views/admin/sites/mail_setting.html.erb @@ -1 +1,5 @@ +<% content_for :side_bar do %> + <%= render 'side_bar' %> +<% end %> + mail_setting.html.erb \ No newline at end of file diff --git a/app/views/admin/sites/site_info.html.erb b/app/views/admin/sites/site_info.html.erb index 1b7c90f54..f0ad23ce3 100644 --- a/app/views/admin/sites/site_info.html.erb +++ b/app/views/admin/sites/site_info.html.erb @@ -1,3 +1,7 @@ +<% content_for :side_bar do %> + <%= render 'side_bar' %> +<% end %> +
<%= form_for @site, :url => admin_site_path(@site), :html => {:class => "clear"} do |f| %>
diff --git a/app/views/admin/sites/system_info.html.erb b/app/views/admin/sites/system_info.html.erb index 45535dacf..dc9d45c95 100644 --- a/app/views/admin/sites/system_info.html.erb +++ b/app/views/admin/sites/system_info.html.erb @@ -1 +1,5 @@ +<% content_for :side_bar do %> + <%= render 'side_bar' %> +<% end %> + system_info.html.erb \ No newline at end of file diff --git a/app/views/admin/sites/ui_theme.html.erb b/app/views/admin/sites/ui_theme.html.erb index 222f59695..540405da8 100644 --- a/app/views/admin/sites/ui_theme.html.erb +++ b/app/views/admin/sites/ui_theme.html.erb @@ -1 +1,5 @@ +<% content_for :side_bar do %> + <%= render 'side_bar' %> +<% end %> + ui_theme.html.erb \ No newline at end of file diff --git a/app/views/layouts/_orbit_bar.html.erb b/app/views/layouts/_orbit_bar.html.erb index 46f2b712f..4c14a8fe9 100644 --- a/app/views/layouts/_orbit_bar.html.erb +++ b/app/views/layouts/_orbit_bar.html.erb @@ -10,6 +10,7 @@
  • <%#= link_to content_tag(:i, nil, :class => 'icons-asset') + t('admin.asset'), admin_assets_path %>
  • <%= link_to content_tag(:i, nil, :class => 'icons-structure') + t('admin.structure'), admin_items_path %>
  • +
  • <%= link_to content_tag(:i, nil, :class => 'icons-cog') + t('admin.site_settings'), admin_site_site_info_path(@site) %>
  • <%#= link_to content_tag(:i, nil, :class => 'icons-plus-cube') + t('admin.add_item') %>
  • diff --git a/app/views/layouts/_side_bar.html.erb b/app/views/layouts/_side_bar.html.erb index c38388271..05562e0bf 100644 --- a/app/views/layouts/_side_bar.html.erb +++ b/app/views/layouts/_side_bar.html.erb @@ -67,14 +67,3 @@ <%= content_tag :li, link_to(t('announcement.tags'), panel_web_resource_back_end_tags_path), :class => active_for_action('/panel/web_resource/back_end/tags', 'index') %> <% end -%> <% end -%> - -<%= content_tag :li, :class => active_for_controllers('sites') do -%> - <%= link_to content_tag(:i, nil, :class => 'icons-cog') + t('admin.site_settings'), admin_site_site_info_path(@site) %> - <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('sites')) do -%> - <%= content_tag :li, link_to(t('admin.site_info'), admin_site_site_info_path(@site)), :class => active_for_action('sites', 'site_info') %> - <%= content_tag :li, link_to(t('admin.system_info'), admin_site_system_info_path(@site)), :class => active_for_action('sites', 'system_info') %> - <%= content_tag :li, link_to(t('admin.language'), admin_site_language_path(@site)), :class => active_for_action('sites', 'language') %> - <%= content_tag :li, link_to(t('admin.mail_setting'), admin_site_mail_setting_path(@site)), :class => active_for_action('sites', 'mail_setting') %> - <%= content_tag :li, link_to(t('admin.ui_theme'), admin_site_ui_theme_path(@site)), :class => active_for_action('sites', 'ui_theme') %> - <% end -%> -<% end -%> diff --git a/app/views/layouts/new_admin.html.erb b/app/views/layouts/new_admin.html.erb index 51a961904..3a493a9d6 100644 --- a/app/views/layouts/new_admin.html.erb +++ b/app/views/layouts/new_admin.html.erb @@ -26,7 +26,11 @@
    diff --git a/config/application.rb b/config/application.rb index cef8c446c..8460d1365 100644 --- a/config/application.rb +++ b/config/application.rb @@ -62,6 +62,8 @@ module Orbit # Enable the asset pipeline config.assets.enabled = true + #config.time_zone = 'Taipei' + ENV['TZ'] = 'Asia/Taipei' end end Orbit_Apps = [] diff --git a/config/environments/development.rb b/config/environments/development.rb index 1dbff0320..20f4519b4 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -29,16 +29,16 @@ Orbit::Application.configure do # :sender_address => %{"notifier" }, # :exception_recipients => %w{chris@rulingcom.com} - # config.action_mailer.delivery_method = :smtp - # config.action_mailer.smtp_settings = { - # :tls => true, - # :enable_starttls_auto => true, - # :address => "smtp.gmail.com", - # :port => '587', - # :domain => "smtp.gmail.com", - # :authentication => "plain", - # :user_name => "redmine@rulingcom.com", - # :password => "rulingredmine" } - + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { + :tls => true, + :enable_starttls_auto => true, + :address => "smtp.gmail.com", + :port => '587', + :domain => "smtp.gmail.com", + :authentication => "plain", + :user_name => "redmine@rulingcom.com", + :password => "rulingredmine" } + end diff --git a/config/initializers/resque.rb b/config/initializers/resque.rb new file mode 100644 index 000000000..62de3fa45 --- /dev/null +++ b/config/initializers/resque.rb @@ -0,0 +1,20 @@ +require 'resque_scheduler' +# require 'resque_scheduler/server' +# require 'yaml' + +Resque.redis = 'localhost:6379' +#Resque.redis.namespace = "resque:SchedulerExample" + +# If you want to be able to dynamically change the schedule, +# uncomment this line. A dynamic schedule can be updated via the +# Resque::Scheduler.set_schedule (and remove_schedule) methods. +# When dynamic is set to true, the scheduler process looks for +# schedule changes and applies them on the fly. +# Note: This feature is only available in >=2.0.0. +#Resque::Scheduler.dynamic = true + +Dir["#{Rails.root}/app/jobs/*.rb"].each { |file| require file } + +# The schedule doesn't need to be stored in a YAML, it just needs to +# be a hash. YAML is usually the easiest. +Resque.schedule = YAML.load_file(Rails.root.join('config', 'resque_schedule.yml')) diff --git a/config/resque.god b/config/resque.god new file mode 100644 index 000000000..6c4e4bded --- /dev/null +++ b/config/resque.god @@ -0,0 +1,55 @@ +rails_env = 'development' #ENV['RAILS_ENV'] || "production" +rails_root = ENV['RAILS_ROOT'] || "/Users/kaito/Documents/MyWorkspeace/orbit/orbit" +num_workers = rails_env == 'production' ? 5 : 2 + +num_workers.times do |num| + God.watch do |w| + w.dir = "#{rails_root}" + w.name = "resque-#{num}" + w.group = 'resque' + w.interval = 30.seconds + p "/usr/bin/rake -f #{rails_root}/Rakefile resque:work QUEUE=* RAILS_ENV=#{rails_env}" +# w.env = {"QUEUE"=>"critical,high,low", "RAILS_ENV"=>rails_env} + w.start = "rake -f #{rails_root}/Rakefile resque:work QUEUE=* RAILS_ENV=#{rails_env}" + + w.uid = 'kaito' + w.gid = 'staff' + + # restart if memory gets too high + w.transition(:up, :restart) do |on| + on.condition(:memory_usage) do |c| + c.above = 350.megabytes + c.times = 2 + end + end + + # determine the state on startup + w.transition(:init, { true => :up, false => :start }) do |on| + on.condition(:process_running) do |c| + c.running = true + end + end + + # determine when process has finished starting + w.transition([:start, :restart], :up) do |on| + on.condition(:process_running) do |c| + c.running = true + c.interval = 5.seconds + end + + # failsafe + on.condition(:tries) do |c| + c.times = 5 + c.transition = :start + c.interval = 5.seconds + end + end + + # start if process is not running + w.transition(:up, :start) do |on| + on.condition(:process_running) do |c| + c.running = false + end + end + end +end \ No newline at end of file diff --git a/config/resque_schedule.yml b/config/resque_schedule.yml new file mode 100644 index 000000000..6929152e6 --- /dev/null +++ b/config/resque_schedule.yml @@ -0,0 +1,17 @@ +# do_mail_matt: +# every: 10s +# class: FetchTime +# args: +# description: Runs the perform method in FetchTime + +nccu_daily_ldap_sync: + cron: * * [0,12] * * * + class: SyncDb + args: + description: Sync NCCU middle site with Orbit for LDAP data + +nccu_claender_sync: + cron: * * [0,12] * * * + class: NccuCalendar + args: + description: Sync NCCU calendar RSS Feeds \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1b98bcc25..50600063a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ Orbit::Application.routes.draw do - + mount Resque::Server, :at => "/admin/resque" devise_for :users # routes for sinatra app @@ -12,6 +12,7 @@ Orbit::Application.routes.draw do # routes for admin namespace :admin do + mount Resque::Server.new, :at => "/resque" resources :assets resources :app_auths resources :object_auths do diff --git a/dump.rdb b/dump.rdb new file mode 100644 index 000000000..a3c1b42c4 Binary files /dev/null and b/dump.rdb differ diff --git a/lib/parsers/parser_common.rb b/lib/parsers/parser_common.rb index b5945200f..1799ae370 100644 --- a/lib/parsers/parser_common.rb +++ b/lib/parsers/parser_common.rb @@ -1,7 +1,7 @@ module ParserCommon include ActionView::Helpers::TagHelper - def menu_level(page, current, menu, edit = false) + def menu_level(page, current_page_id, current, menu, edit = false) res = '' if page.ordered_and_visible_children.size > 0 res << "