system preference
This commit is contained in:
1 parent
62fa589e8a
commit
b198b1a17b
19 files changed
+251
-83
No files matched your search
@@ -5,9 +5,13 @@ class BackupServer
|
||||
#CronMail.time_check("Going to backup Orbit").deliver
|
||||
dbhost = Mongoid.config.database.connection.primary.join ':'
|
||||
dbname = Mongoid.config.database.name
|
||||
archive_db_list_path = OrbitSystemPreference::ArchiveDbListPath
|
||||
dbdirectory = "#{Rails.root}/tmp/#{dbname}-"+Time.now.strftime("%Y-%m-%d-%H-%M")
|
||||
%x[mongodump -h #{dbhost} -d #{dbname} -o #{dbdirectory} ]
|
||||
|
||||
# %x[touch #{Rails.root}/tmp/restart]
|
||||
%x[rm #{archive_db_list_path}]
|
||||
%x[ls #{Rails.root}/tmp/#{dbname}* | du -h --max-depth=1 --block-size=1M |sort -h >> #{archive_db_list_path}]
|
||||
OrbitJobLogger.info "DB backup done Path:#{dbdirectory}"
|
||||
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,36 @@
|
||||
class DashboardCounter < Resque::Plugins::RestrictionJob
|
||||
@queue = :high
|
||||
|
||||
def self.perform(*args)
|
||||
site = Site.first
|
||||
obj = new(*args)
|
||||
site.dashboard_counter[:visitors_this_week] = obj.display_visitors_this_week
|
||||
site.dashboard_counter[:visitors_this_month] = obj.display_visitors_this_month
|
||||
site.dashboard_counter[:visitors_this_year] = obj.display_visitors_this_year
|
||||
site.save
|
||||
OrbitJobLogger.info "DashboardCounter done #{site.dashboard_counter.to_s}"
|
||||
end
|
||||
|
||||
|
||||
def display_visitors(options={})
|
||||
impressions = Impression.where(options).and(:referrer.ne => nil)
|
||||
impressions.map{|i| i[:session_hash]}.uniq.count
|
||||
end
|
||||
|
||||
def display_visitors_today
|
||||
display_visitors(created_at: {'$gte' => Date.today.beginning_of_day, '$lte' => Date.today.end_of_day})
|
||||
end
|
||||
|
||||
def display_visitors_this_week
|
||||
display_visitors(created_at: {'$gte' => Date.today.beginning_of_week, '$lte' => Date.today.end_of_week})
|
||||
end
|
||||
|
||||
def display_visitors_this_month
|
||||
display_visitors(created_at: {'$gte' => Date.today.beginning_of_month, '$lte' => Date.today.end_of_month})
|
||||
end
|
||||
|
||||
def display_visitors_this_year
|
||||
display_visitors(created_at: {'$gte' => Date.today.beginning_of_year, '$lte' => Date.today.end_of_year})
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,46 @@
|
||||
class GenerateSystemSummary
|
||||
@queue = :high
|
||||
|
||||
def self.perform()
|
||||
@site = Site.first
|
||||
get_disk_free
|
||||
get_git_log_list
|
||||
get_package_info
|
||||
@site.save
|
||||
end
|
||||
|
||||
def self.get_package_info
|
||||
@info = {}
|
||||
get_nginx_version
|
||||
get_MongoDB_version
|
||||
get_Linux_version
|
||||
@site.system_package_info = @info
|
||||
end
|
||||
|
||||
def self.get_git_log_list
|
||||
git_commit_list_path = OrbitSystemPreference::GitCommitListPath
|
||||
%x[rm #{git_commit_list_path}]
|
||||
%x[cd #{Rails.root};#{OrbitSystemPreference::GitLogCommend} >>#{git_commit_list_path} ]
|
||||
end
|
||||
|
||||
def self.get_disk_free
|
||||
@site.disk_space= %x[#{OrbitSystemPreference::DiskFree}]
|
||||
end
|
||||
|
||||
def self.get_nginx_version
|
||||
@info[:nginx] = %x[#{OrbitSystemPreference::SystemPackage::NginxVersion} ]
|
||||
end
|
||||
|
||||
def self.get_MongoDB_version
|
||||
@info[:mongodb] = %x[#{OrbitSystemPreference::SystemPackage::MongodbVersion} ]
|
||||
end
|
||||
|
||||
def self.get_Linux_version
|
||||
@info[:linux] = %x[#{OrbitSystemPreference::SystemPackage::SystemVersion} ]
|
||||
end
|
||||
|
||||
def self.check_system_has_enough_space( limit =OrbitSystemPreference::DefaultDiskSpaceLimit )
|
||||
binding.pry
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,21 +0,0 @@
|
||||
class NccuCalendar
|
||||
require 'open-uri'
|
||||
require 'tempfile'
|
||||
|
||||
@queue = :high
|
||||
|
||||
def self.perform()
|
||||
# temp_file = Tempfile.new('new_cal')
|
||||
# open('http://events.nccu.edu.tw/Month').read{|data|
|
||||
# temp_file << data
|
||||
# }
|
||||
|
||||
open(File.join(Rails.root, 'public/static', 'nccu_calendar.xml'), 'wb') do |fo|
|
||||
fo.print open('http://events.nccu.edu.tw/Month').read
|
||||
end
|
||||
|
||||
# FileUtils.mv(temp_file, File.join(Rails.root, 'public/static', 'nccu_calendar.xml'))
|
||||
|
||||
puts "[#{ DateTime.now.strftime("%Y %D %H:%M")}]NccuCalendar Synced #{File.join(Rails.root, 'public/static', 'nccu_calendar.xml')}"
|
||||
end
|
||||
end
|
||||
@@ -1,25 +0,0 @@
|
||||
class SyncDb
|
||||
|
||||
@queue = :high
|
||||
|
||||
def self.perform()
|
||||
puts "[ #{DateTime.now.strftime("%Y %D %H:%M") }]\t SyncDb Starting"
|
||||
self.start_sync
|
||||
self.set_admin
|
||||
end
|
||||
|
||||
def self.start_sync
|
||||
task = 'mid_site:sync'
|
||||
args = []
|
||||
%x[rake #{task} --trace >> #{Rails.root}/log/rake.log]
|
||||
User.all.each{|ur| ur.create_dept_cache}
|
||||
puts "[#{ DateTime.now.strftime("%Y %D %H:%M")}]\tSyncDb Synced"
|
||||
end
|
||||
|
||||
def self.set_admin
|
||||
task = 'mid_site:install_admin'
|
||||
args = []
|
||||
%x[rake #{task} --trace >> #{Rails.root}/log/rake.log]
|
||||
puts "[#{ DateTime.now.strftime("%Y %D %H:%M")}]\tAdmin done"
|
||||
end
|
||||
end
|
||||
@@ -5,5 +5,6 @@ class UpdateTagCloud
|
||||
Tag.all.each do |tag|
|
||||
tag.update_attribute(:cloud_view_count, tag.impressionist_count(:created_at.gte => 14.days.ago, :created_at.lte => Time.now))
|
||||
end
|
||||
OrbitJobLogger.info "UpdateTagCloud Done"
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user