Project

General

Profile

« Previous | Next » 

Revision 960373b7

Added by Marc Dequènes over 15 years ago

  • ID 960373b717f2389e30dd63ecc2230b64bd96c926

[evol] check new mails at a selectable minimum interval, and handle stop requests gracefully

View differences:

postman
logger.log_to_file(@config.log.file) unless @config.log.file.nil?
end
@current_thread = Thread.current
@stop_asap = false
@waiting = false
logger.info "Bot '#{self.human_name}' loaded"
end
def run
imap = IMAP.new(@config.imap)
until @stop_asap
t = Time.now.to_i
logger.debug "Starting mail check"
check_mails(imap)
logger.debug "Mail check finished"
t2 = Time.now.to_i
sleep_time = @config.imap.min_check_interval - (t2 - t)
if sleep_time > 0
logger.debug "Having a break before new check..."
@waiting = true
begin
sleep(sleep_time)
rescue
end
@waiting = false
end
end
logger.info "Bot was asked to stop..." if @stop_asap
logger.info "Bot terminating"
end
def check_mails(imap)
imap.check_mail do |msg|
if @stop_asap
logger.info "Bot was asked to stop..."
......
next
end
logger.info "Message accepted, processing orders..."
logger.debug "Message accepted, processing orders..."
result_list = CommandParser.run(order)
# create transcript
......
def ask_to_stop
@stop_asap = true
Thread.critical = true
@current_thread.raise if @waiting
Thread.critical = false
end
end
end

Also available in: Unified diff