From 083963af65432a610762b8046c49d81ad7a6db44 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 8 May 2012 19:20:53 +0800 Subject: [PATCH] Test version for DB sync schedule job --- app/controllers/application_controller.rb | 70 ++---------------- app/jobs/sync_db.rb | 10 ++- config/initializers/middle_site_connection.rb | 2 +- config/resque_schedule.yml | 16 ++-- dump.rdb | Bin 816 -> 1530 bytes lib/tasks/mid_site_sync.rake | 1 + 6 files changed, 23 insertions(+), 76 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 494b497e..fb82774e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -39,65 +39,15 @@ class ApplicationController < ActionController::Base @parent_item = Item.first(:conditions => { :id => BSON::ObjectId(params[:parent_id]) }) rescue nil end - def auth_failed_in_backend - #redirect_to admin_dashboards_url - redirect_to root_path - end - # Check if the current_user is admin def is_admin? - current_user.admin? ? true : auth_failed_in_backend - end - - def is_manager? - @module_app.managing_users.include?(current_user) || is_admin? - end - - def for_admin_only - if is_admin? - true - else - flash[:error] = t("admin.access.denied.not_admin") - auth_failed_in_backend - end - end - - def for_app_manager - if is_manager? - true - else - flash[:error] = t("admin.access.denied.app.not_manager") - auth_failed_in_backend - end - end - - def for_app_sub_manager - if (@module_app.sub_managing_users.include?(current_user) || is_manager?) - true - else - flash[:error] = t("admin.access.denied.app.not_sub_manager") - auth_failed_in_backend - end - end - - def for_app_user - if (@module_app.app_auth.auth_users.include?(current_user) || for_app_sub_manager ) - true - else - flash[:error] = t("admin.access.denied.app.not_authed_user") - auth_failed_in_backend - end - end - - def check_object_premission(obj,title) - flash[:error] = t("admin.access.denied.object") - auth_failed_in_backend unless (obj.get_object_auth_by_title(title).auth_users.include?(current_user) || is_manager? || is_admin? ) + redirect_to root_url unless current_user.admin? end # Render the page - def render_page(param={}) + def render_page(id = nil) if @item - render :text => process_page(@item, param[:id], param), :layout => 'page_layout' + render :text => process_page(@item, id), :layout => 'page_layout' else render :text => '404 Not Found' end @@ -128,8 +78,8 @@ class ApplicationController < ActionController::Base # set site if exist or create site @site = Site.first || Site.create({:valid_locales => [], :in_use_locales => []}) session[:site] = @site.id - @site_in_use_locales = site_locales_default_head(@site.in_use_locales) - @site_valid_locales = site_locales_default_head(@site.valid_locales) + @site_in_use_locales = @site.in_use_locales + @site_valid_locales = @site.valid_locales end def set_current_item @@ -164,14 +114,4 @@ class ApplicationController < ActionController::Base end end - def site_locales_default_head(locales) - if locales[0].eql? I18n.locale.to_s - locales - else - a = Array.new(locales) - shift_out = a.delete(I18n.locale.to_s) - [shift_out] + a - end - end - end diff --git a/app/jobs/sync_db.rb b/app/jobs/sync_db.rb index f6458204..d4bda790 100644 --- a/app/jobs/sync_db.rb +++ b/app/jobs/sync_db.rb @@ -3,7 +3,13 @@ class SyncDb @queue = :high def self.perform() -# sleep 10 - puts "DB Sync" + 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/config/initializers/middle_site_connection.rb b/config/initializers/middle_site_connection.rb index 5dddcdcb..4f20995a 100644 --- a/config/initializers/middle_site_connection.rb +++ b/config/initializers/middle_site_connection.rb @@ -11,4 +11,4 @@ mid_host = { :database => "RSS23_NCCU_MIDDLE", :encoding => "UTF8" } -#MID_CLIENT = Mysql2::Client.new(mid_host) +MID_CLIENT = Mysql2::Client.new(mid_host) diff --git a/config/resque_schedule.yml b/config/resque_schedule.yml index 1f491898..6929152e 100644 --- a/config/resque_schedule.yml +++ b/config/resque_schedule.yml @@ -1,17 +1,17 @@ -do_mail_matt: - every: 10s - class: FetchTime - args: - description: Runs the perform method in FetchTime +# 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: Runs the perform method in SnycDB + description: Sync NCCU middle site with Orbit for LDAP data nccu_claender_sync: - every: 1m + cron: * * [0,12] * * * class: NccuCalendar args: - description: Runs the perform method in NccuCalendar \ No newline at end of file + description: Sync NCCU calendar RSS Feeds \ No newline at end of file diff --git a/dump.rdb b/dump.rdb index a4a56dc0cba0b3124f374e1d3dba72ac23f09bae..a3c1b42c46ad075453c0ee3cb39529b5802dd944 100644 GIT binary patch literal 1530 zcmbW1PjA~s5XC9_PmRQZn*xE0wunb-z)k{LT+$LP5iMdvc7q-o6mf#0DI94@jwRYl zF0)+9c8U~6i=6T$dhQ|T+^QhoB8NagZn^Z(dt1tqBclLy=#ev=d4u0oFxfy$k(X6&ix=nQX)*Yv(k@y zPxULK9cLqnKHUl0ovCb6`()He6jRPV3po0{qW0;i`eB(D)OVg(wz_p?1QJK=))#2INoX=bPapX(Xluy7^g zyF~EV!&n6(f~EN_*-k@@)Q*%w!it8ikCq&wWPm;>0iHyr5WdU60^uH@r{E}PbERb;0~(?@ zmzUv&1suD`lbb;9P5a2PU3}A@d!}y-&s)Bf7~h_JFXUkoBY8h#2;F6Axw|aHVZ3A%ZyF74^dSq7ap*D`Fqb1_2!uF@*N0a2%1PBs zU{7C#eONqg>rR7jb}yC4IBxl$xHHSnXd0WQA*_6GZEoaRVr)KI$XpvFYoEoMSqFUf c+`2C{+8D>fC~#&#Z$d=hpr6FTfG)_y7O^ delta 156 zcmeyxy@9Ph$koL&*ucQR@E-#cUr}mtVQH#Wd45rLYEdzxKyG45iEd(Mk(HUTsi~!v z7K0j!3M+JZtKyQxqLS1UNh1S8BV7YiT>}dRLsKhbBP(M=1#JTh0|Q1ys0qQz8L26y fITNLm7)2&NkeE2Fj){w9;seRe`iyfJ8UF(SGDa}@ diff --git a/lib/tasks/mid_site_sync.rake b/lib/tasks/mid_site_sync.rake index 76660bf8..89684985 100644 --- a/lib/tasks/mid_site_sync.rake +++ b/lib/tasks/mid_site_sync.rake @@ -2,6 +2,7 @@ # require 'ruby-debug' namespace :mid_site do + desc "mid_site Rake task" attr_from_mid = %w{nccu_id psn_nam ut_cod up_ut_cod eml_adr off_tel_ext sta_num} officer_posgrp_code = %w{02 06 10 05} #from RSS2 admin_role = nil