Project

General

Profile

« Previous | Next » 

Revision a089227c

Added by Marc Dequènes about 13 years ago

  • ID a089227ca94121115f46e5998b497fa102787398

[fix/evol] work on better Interface/Task/Conversation/… sync and bot stop action in order to avoid races and locks

View differences:

lib/cyborghood/cyborg.rb
require 'cyborghood'
require 'eventmachine'
require 'thread'
require 'cyborghood/cyborg/dsl'
......
# use "aspects" Modules to define behaviors
end
def ask_to_stop
def stop(condition)
logger.info "Bot was asked to stop..."
yield if block_given?
try_stop
case condition
when :when_finished
wait_until_ready_to_stop
when :quickly
# try to stop gracefully
DSL::Task.stop_all
wait_until_ready_to_stop
when :at_once
# it won't wait for anything to finish…
exit
end
end
def ready_to_stop?
DSL::Task.idle?
# core capabilities
def capabilities
[]
end
protected
def stop_gracefully
end
def stop
def try_stop
logger.info "Bot stopping"
EventMachine.next_tick { EventMachine.stop_event_loop }
end
def try_stop
def ready_to_stop?
DSL::Task.idle?
end
def wait_until_ready_to_stop
if ready_to_stop?
@system_notification.unsubscribe(@system_notification_processing)
@system_notification_processing = nil
drop_channel(@system_notification_name)
stop
try_stop
else
EventMachine.next_tick { try_stop }
EventMachine.next_tick { wait_until_ready_to_stop }
end
end
# core capabilities
def capabilities
[]
end
protected
def process_system_notification(msg)
end
end

Also available in: Unified diff