每天,我的Rails 2.3.16网络应用程序会检查许多外部网站上的数据,以确定这些网站上的链接是否仍然有效或是否为404.我每天收到很多电子邮件,我想要更改此流程运行的频率,以便我不会经常收到尽可能多的电子邮件。
有一个文件domain_checker.rb,它位于\ web \ current \ lib \ daemons中。但是,我无法在文件中看到任何关于守护程序何时运行的内容。它似乎每天早上06:55:00 +0000运行。有没有办法改变频率?我应该从哪里开始看?对不起,我在Rails非常业余,并且正在摸索着。
以下是domain_checker.rb文件中的已清理代码,以供参考。编辑:我添加了代码,我认为ActiveMailer正在发送这些电子邮件。
#!/usr/bin/env ruby
#You might want to change this
ENV["RAILS_ENV"] ||= "production"
require File.dirname(__FILE__) + "/../../config/environment"
require 'net/http'
require 'uri'
# require "system_timer"
class Net::HTTP
alias_method :old_initialize, :initialize
def initialize(*args)
old_initialize(*args)
@ssl_context = OpenSSL::SSL::SSLContext.new
@ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
end
def get_url(uri_str,keywords, limit=10)
raise ArgumentError, 'HTTP redirect too deep' if limit == 0
url = URI.parse(uri_str)
http.read_timeout = 10
http.open_timeout = 10
response = nil
begin
SANITIZED
end
SANITIZED
if keywords == nil or keywords == ""
case response.code
when /^2|3\d{2}/ then true
#when Net::HTTPSuccess then true
#when Net::HTTPRedirection then true
#when Net::HTTPFound then true
#when Net::HTTPRedirection then get_url(response['location'], limit - 1)
else
response.error!
end
else
if response.code =~ /^2|3\d{2}/ and response.body.include? keywords
true
#when Net::HTTPSuccess then true
#when Net::HTTPRedirection then true
#when Net::HTTPFound then true
elsif response.code == Net::HTTPRedirection then get_url(response['location'], limit - 1)
else
@response_pass = nil
response.error!
end
end
rescue Timeout::Error
return false, "Timeout"
rescue TimeoutError
return false, "Timeout"
rescue Exception
if response != nil
if not @response_pass =~ /^2|3\d{2}/ #check for errant 200/300s and get rid of them...
return false, @response_pass, response['location'], response.body #return response error code if it isn't 2xx-3xx
else
return false, nil
end
else
return false, nil
end
end
@lists = List.find(:all)
for list in @lists
SANTIZED
if (@result == false) then
# ActiveRecord::Base.logger.info("#{task.list.id}, #{task.list.name}, #{code}, #{url}.\n")
UserMailer.deliver_emaildown(task, "Business Website", code, url)
end
end
ActiveRecord::Base.logger.info("The site checker is still running at #{Time.now}.\n")
end
ActiveRecord::Base.logger.info("The site checker is done at #{Time.now}.\n")
答案 0 :(得分:0)
此代码不处理调度。调度通常委托给gem或cron
之类的东西。