def start_asynchronous_jobs(self): """ Initialize the asynchronous operation, scheduled in the system """ if test_reactor: self._reactor = test_reactor # Scheduling the Delivery schedule to be executed every 2 seconds delivery_sched.DeliverySchedule().schedule(2, 1) # Scheduling the Anomalies Check schedule to be executed every 30 seconds statistics_sched.AnomaliesSchedule().schedule(30, 2) # Scheduling the Notification schedule to be executed every 60 seconds notification_sched.NotificationSchedule().schedule(60, 3) # Scheduling the Session Management schedule to be executed every minute session_management_sched.SessionManagementSchedule().schedule(60, 5) # Scheduling the Tip Cleaning scheduler to be executed every day at 00:00 current_time = datetime_now() delay = (3600 * (24 + 0)) - (current_time.hour * 3600) - ( current_time.minute * 60) - current_time.second clean = cleaning_sched.CleaningSchedule().schedule(3600 * 24, delay) # Scheduling the PGP Check scheduler to be executed every day at 02:00 delay = (3600 * (24 + 2)) - (current_time.hour * 3600) - ( current_time.minute * 60) - current_time.second pgp_check = pgp_check_sched.PGPCheckSchedule().schedule( 3600 * 24, delay) # Scheduling the Statistics schedule to be executed every hour on the hour delay = 3600 - (current_time.minute * 60) - current_time.second stats = statistics_sched.StatisticsSchedule().schedule(3600, delay)
def test_anomalies(self): yield helpers.TestGL.setUp(self) print "First round 10" self.increment_accesses(10) statistics_sched.AnomaliesSchedule().operation() print "Second round 30" self.increment_accesses(30) statistics_sched.AnomaliesSchedule().operation() print "Third round 30" self.increment_accesses(30) statistics_sched.AnomaliesSchedule().operation() print "Stats!" yield statistics_sched.StatisticsSchedule().operation()
def test_anomalies_schedule(self): self.n = 0 full_ammo = 1000000 original_get_disk_anomaly_conditions = anomaly.get_disk_anomaly_conditions conditions_count = len(original_get_disk_anomaly_conditions(full_ammo, full_ammo, full_ammo, full_ammo)) def mock_get_disk_anomaly_conditions(*args, **kwargs): conditions = original_get_disk_anomaly_conditions(*args, **kwargs) # activate one condition at once for i in range(len(conditions)): if i == self.n: conditions[i]['condition'] = True else: conditions[i]['condition'] = False return conditions anomaly.get_disk_anomaly_conditions = mock_get_disk_anomaly_conditions # testing the scheduler with all the conditions unmet self.n = -1 yield statistics_sched.AnomaliesSchedule().operation() # testing the scheduler enabling all conditions one at once for j in range(conditions_count): self.n = j yield statistics_sched.AnomaliesSchedule().operation() yield statistics_sched.AnomaliesSchedule().operation() # testing the scheduler with all the conditions unmet # a second time in order test the accept_submissions value self.n = -1 yield statistics_sched.AnomaliesSchedule().operation()
def start_asynchronous_jobs(self): """ Initialize the asynchronous operation, scheduled in the system """ if reactor_override: self._reactor = reactor_override session_management = session_management_sched.SessionManagementSchedule( ) self._reactor.callLater(0, session_management.start, GLSettings.session_management_delta) anomaly = statistics_sched.AnomaliesSchedule() self._reactor.callLater(0, anomaly.start, GLSettings.anomaly_delta) delivery = delivery_sched.DeliverySchedule() self._reactor.callLater(1, delivery.start, GLSettings.delivery_delta) notification = notification_sched.NotificationSchedule() self._reactor.callLater(1, notification.start, GLSettings.notification_delta) mailflush = mailflush_sched.MailflushSchedule() self._reactor.callLater(1, mailflush.start, GLSettings.mailflush_delta) secure_file_delete = secure_file_delete_sched.SecureFileDeleteSchedule( ) self._reactor.callLater(1, secure_file_delete.start, GLSettings.secure_file_delete_delta) # The Tip cleaning scheduler need to be executed every day at midnight current_time = datetime_now() delay = (3600 * 24) - (current_time.hour * 3600) - ( current_time.minute * 60) - current_time.second clean = cleaning_sched.CleaningSchedule() self._reactor.callLater(delay, clean.start, 3600 * 24) # The PGP check scheduler need to be executed every day at midnight current_time = datetime_now() delay = (3600 * 24) - (current_time.hour * 3600) - ( current_time.minute * 60) - current_time.second pgp_check = pgp_check_sched.PGPCheckSchedule() self._reactor.callLater(delay, pgp_check.start, 3600 * 24) # The Stats scheduler need to be executed every hour on the hour current_time = datetime_now() delay = (60 * 60) - (current_time.minute * 60) - current_time.second stats = statistics_sched.StatisticsSchedule() self._reactor.callLater(delay, stats.start, 60 * 60)
def start_asynchronous(): """ Initialize the asynchronous operation, scheduled in the system """ # Scheduled jobs will be started by reactor after reactor.run() # # Arguments to reactor.callLater do the following: # - first argument is the first run delay in seconds # - second argument is the function that starts the schedule # - third argument is the schedule period in seconds session_management = session_management_sched.SessionManagementSchedule() reactor.callLater(0, session_management.start, GLSettings.session_management_delta) anomaly = statistics_sched.AnomaliesSchedule() reactor.callLater(0, anomaly.start, GLSettings.anomaly_delta) resources_check = statistics_sched.ResourcesCheckSchedule() reactor.callLater(0, resources_check.start, GLSettings.anomaly_delta) delivery = delivery_sched.DeliverySchedule() reactor.callLater(10, delivery.start, GLSettings.delivery_delta) notification = notification_sched.NotificationSchedule() reactor.callLater(20, notification.start, GLSettings.notification_delta) mailflush = mailflush_sched.MailflushSchedule() reactor.callLater(40, mailflush.start, GLSettings.mailflush_delta) # The Tip cleaning scheduler need to be executed every day at midnight current_time = datetime_now() delay = (3600 * 24) - (current_time.hour * 3600) - ( current_time.minute * 60) - current_time.second clean = cleaning_sched.CleaningSchedule() reactor.callLater(delay, clean.start, 3600 * 24) # The PGP check scheduler need to be executed every day at midnight current_time = datetime_now() delay = (3600 * 24) - (current_time.hour * 3600) - ( current_time.minute * 60) - current_time.second pgp_check = pgp_check_sched.PGPCheckSchedule() reactor.callLater(delay, pgp_check.start, 3600 * 24) # The Stats scheduler need to be executed every hour on the hour current_time = datetime_now() delay = (60 * 60) - (current_time.minute * 60) - current_time.second stats = statistics_sched.StatisticsSchedule() reactor.callLater(delay, stats.start, 60 * 60)
def start_asynchronous_jobs(self): """ Initialize the asynchronous operation, scheduled in the system """ if test_reactor: self._reactor = test_reactor # Scheduling the Delivery schedule to be executed every 2 seconds delivery = delivery_sched.DeliverySchedule() self._reactor.callLater(1, delivery.start, 2) # Scheduling the Anomalies Check schedule to be executed every 30 seconds anomaly = statistics_sched.AnomaliesSchedule() self._reactor.callLater(0, anomaly.start, 30) # Scheduling the Notification schedule to be executed every 60 seconds notification = notification_sched.NotificationSchedule() self._reactor.callLater(1, notification.start, 60) # Scheduling the Session Management schedule to be executed every minute session_management = session_management_sched.SessionManagementSchedule( ) self._reactor.callLater(0, session_management.start, 60) # Scheduling the Tip Cleaning scheduler to be executed every day at 00:00 current_time = datetime_now() delay = (3600 * 24) - (current_time.hour * 3600) - ( current_time.minute * 60) - current_time.second clean = cleaning_sched.CleaningSchedule() self._reactor.callLater(delay, clean.start, 3600 * 24) # Scheduling the PGP Check scheduler to be executed every day at 01:00 current_time = datetime_now() delay = (3600 * 25) - (current_time.hour * 3600) - ( current_time.minute * 60) - current_time.second pgp_check = pgp_check_sched.PGPCheckSchedule() self._reactor.callLater(delay, pgp_check.start, 3600 * 24) # Scheduling the Statistics schedule to be executed every hour on the hour current_time = datetime_now() delay = (60 * 60) - (current_time.minute * 60) - current_time.second stats = statistics_sched.StatisticsSchedule() self._reactor.callLater(delay, stats.start, 60 * 60)
def start_asynchronous(): """ Initialize the asynchronous operation, scheduled in the system """ # Here we prepare the scheduled, # schedules will be started by reactor after reactor.run() session_management = session_management_sched.SessionManagementSchedule() delivery = delivery_sched.DeliverySchedule() notification = notification_sched.NotificationSchedule() clean = cleaning_sched.CleaningSchedule() pgp_check = pgp_check_sched.PGPCheckSchedule() mailflush = mailflush_sched.MailflushSchedule() resource_check = statistics_sched.ResourceChecker() anomaly = statistics_sched.AnomaliesSchedule() stats = statistics_sched.StatisticsSchedule() # here we prepare the schedule: # - first argument is the first run delay in seconds # - second argument is the function that starts the schedule # - third argument is the schedule period in seconds reactor.callLater(0, session_management.start, GLSetting.session_management_minutes_delta * 60) reactor.callLater(10, delivery.start, GLSetting.delivery_seconds_delta) reactor.callLater(20, notification.start, GLSetting.notification_minutes_delta * 60) reactor.callLater(30, clean.start, GLSetting.cleaning_hours_delta * 3600) reactor.callLater(40, mailflush.start, GLSetting.mailflush_minutes_delta * 60) reactor.callLater(50, resource_check.start, GLSetting.anomaly_seconds_delta) reactor.callLater(60, anomaly.start, GLSetting.anomaly_seconds_delta) # The Stats scheduler need to be executed every hour on the hour. current_time = datetime_now() delay = (60 * 60) - (current_time.minute * 60) - current_time.second reactor.callLater(delay, stats.start, 60 * 60) statistics_sched.StatisticsSchedule.collection_start_datetime = current_time # The PGP check scheduler need to be executed every day at midnight current_time = datetime_now() delay = (3600 * 24) - (current_time.hour * 3600) - (current_time.minute * 60) - current_time.second reactor.callLater(delay, pgp_check.start, 3600 * 24)
def start_asynchronous(): """ Initialize the asynchronous operation, scheduled in the system https://github.com/globaleaks/GLBackend/wiki/Asynchronous-and-synchronous-operation This method would be likely put in GLBaseRunner.postApplication, but is not executed by globaleaks.run_app, then is called by the OS-depenedent runner below """ from globaleaks.jobs import session_management_sched, statistics_sched, \ notification_sched, delivery_sched, cleaning_sched, \ pgp_check_sched # Here we prepare the scheduled, schedules will be started by reactor after reactor.run() session_management = session_management_sched.SessionManagementSchedule() delivery = delivery_sched.DeliverySchedule() notification = notification_sched.NotificationSchedule() clean = cleaning_sched.CleaningSchedule() anomaly = statistics_sched.AnomaliesSchedule() stats = statistics_sched.StatisticsSchedule() pgp_check = pgp_check_sched.PGPCheckSchedule() # here we prepare the schedule: # - first argument is the first run delay in seconds # - second argument is the function that starts the schedule # - third argument is the schedule period in seconds reactor.callLater(0, session_management.start, GLSetting.session_management_minutes_delta * 60) reactor.callLater(10, delivery.start, GLSetting.delivery_seconds_delta) reactor.callLater(20, notification.start, GLSetting.notification_minutes_delta * 60) reactor.callLater(30, clean.start, GLSetting.cleaning_hours_delta * 3600) reactor.callLater(40, anomaly.start, GLSetting.anomaly_seconds_delta) reactor.callLater(50, stats.start, GLSetting.stats_minutes_delta * 60) reactor.callLater(60, pgp_check.start, GLSetting.pgp_check_hours_delta * 3600)
def test_anomalies_schedule(self): yield statistics_sched.AnomaliesSchedule().operation()