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_session_management_sched(self): authentication.GLSession('admin', 'admin', 'enabled') # 1! authentication.GLSession('admin', 'admin', 'enabled') # 2! authentication.GLSession('admin', 'admin', 'enabled') # 3! self.assertEqual(len(GLSettings.sessions), 3) authentication.reactor_override.advance(GLSettings.defaults.authentication_lifetime) self.assertEqual(len(GLSettings.sessions), 0) yield session_management_sched.SessionManagementSchedule().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 test_session_management_sched(self): new_session = OD( refreshdate=datetime_null(), # new but expired session! id="admin", role="admin", user_id="admin") GLSetting.sessions['111'] = new_session GLSetting.sessions['222'] = new_session GLSetting.sessions['333'] = new_session yield session_management_sched.SessionManagementSchedule().operation() self.assertEqual(len(GLSetting.sessions), 0)
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 test_session_management_sched(self): new_session('admin', 'admin', 'enabled') # 1! new_session('admin', 'admin', 'enabled') # 2! new_session('admin', 'admin', 'enabled') # 3! self.assertEqual(len(GLSessions), 3) self.test_reactor.pump([1] * (GLSettings.authentication_lifetime - 1)) self.assertEqual(len(GLSessions), 3) self.test_reactor.advance(1) self.assertEqual(len(GLSessions), 0) yield session_management_sched.SessionManagementSchedule().run()
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)