def RunTask(): """ Checks current jobs and run a one task if it is possible. Verifies if it is possible to start a new task, the maximum number of simultaneously running ``Jobs`` is limited. """ if len(tasks()) == 0: return False if len(jobs()) >= MAXIMUM_JOBS_STARTED: return False from customer import fire_hire if not fire_hire.IsAllHired(): if _Debug: lg.out( _DebugLevel, 'backup_control.RunTask some suppliers not hired yet, retry after 5 sec' ) reactor.callLater(5, RunTask) # @UndefinedVariable return False T = tasks().pop(0) message = T.run() if message: events.send('backup-task-failed', data=dict( path_id=T.pathID, message=message, )) T.result_defer.errback((T.pathID, message)) else: # events.send('backup-task-executed', data=dict(path_id=T.pathID, backup_id=T.backupID, )) T.result_defer.callback((T.backupID, None)) T.destroy(message) return True
def start(self): from twisted.internet.defer import Deferred from logs import lg from main.config import conf from main import events from raid import eccmap from services import driver from customer import fire_hire self.starting_deferred = Deferred() self.starting_deferred.addErrback( lambda err: lg.warn('service %r was not started: %r' % (self.service_name, err.getErrorMessage() if err else 'unknown reason'))) self.all_suppliers_hired_event_sent = False if driver.is_on('service_entangled_dht'): self._do_join_suppliers_dht_layer() eccmap.Update() fire_hire.A('init') fire_hire.A().addStateChangedCallback(self._on_fire_hire_ready, None, 'READY') conf().addConfigNotifier('services/customer/suppliers-number', self._on_suppliers_number_modified) conf().addConfigNotifier('services/customer/needed-space', self._on_needed_space_modified) events.add_subscriber(self._on_supplier_modified, 'supplier-modified') events.add_subscriber(self._on_dht_layer_connected, event_id='dht-layer-connected') if fire_hire.IsAllHired(): self.starting_deferred.callback(True) self.starting_deferred = None lg.info('all my suppliers are already hired') return True fire_hire.A('restart') return self.starting_deferred
def doOverallCheckUp(self, *args, **kwargs): """ Action method. """ from customer import fire_hire if not fire_hire.IsAllHired(): if _Debug: lg.out( _DebugLevel, 'backup_monitor.doOverallCheckUp some suppliers not hired yet, restart now' ) self.automat('restart') return if online_status.listOfflineSuppliers(): if time.time() - self.last_execution_time > 60: # re-sync every 1 min. if at least on supplier is dead if _Debug: lg.out( _DebugLevel, 'backup_monitor.doOverallCheckUp restart after 1 min, found offline suppliers' ) self.automat('restart') return if time.time() - self.last_execution_time > 60 * 10: # also re-sync every 10 min. if _Debug: lg.out( _DebugLevel, 'backup_monitor.doOverallCheckUp periodic 10 min. restart' ) self.automat('restart') return
def start(self): from logs import lg from customer import fire_hire if not fire_hire.IsAllHired(): lg.warn('service_list_files() can not start right now, not all suppliers hired yet') return False from customer import list_files_orator list_files_orator.A('init') return True
def _on_my_suppliers_all_hired(self, evt): from logs import lg from services import driver if driver.is_enabled('service_data_motion'): if not driver.is_started('service_data_motion'): from customer import fire_hire if fire_hire.IsAllHired(): lg.info( 'all my suppliers are hired, starting service_data_motion()' ) driver.start_single('service_data_motion')
def start(self): from logs import lg from customer import fire_hire if not fire_hire.IsAllHired(): lg.warn('service_data_motion() can not start right now, not all suppliers hired yet') return False from main import events from stream import io_throttle from stream import data_sender from stream import data_receiver io_throttle.init() data_sender.A('init') data_receiver.A('init') events.add_subscriber(self._on_identity_url_changed, 'identity-url-changed') return True
def _do_check_all_hired(self): from logs import lg from main import events from customer import fire_hire if fire_hire.IsAllHired(): self._do_cleanup_dht_suppliers() if not self.all_suppliers_hired_event_sent: lg.info('at the moment all my suppliers are hired and known') self.all_suppliers_hired_event_sent = True events.send('my-suppliers-all-hired', data=dict()) if self.starting_deferred and not self.starting_deferred.called: self.starting_deferred.callback(True) self.starting_deferred = None else: self.all_suppliers_hired_event_sent = False lg.info('some of my supplies are not hired yet') events.send('my-suppliers-yet-not-hired', data=dict()) if self.starting_deferred and not self.starting_deferred.called: self.starting_deferred.errback( Exception('not possible to hire enough suppliers')) self.starting_deferred = None