def scheduled_update(): from indico_livesync.plugin import LiveSyncPlugin clean_old_entries() for agent in LiveSyncAgent.find_all(): if agent.backend is None: LiveSyncPlugin.logger.warning('Skipping agent %s; backend not found', agent.name) continue if not agent.initial_data_exported: LiveSyncPlugin.logger.warning('Skipping agent %s; initial export not performed yet', agent.name) continue LiveSyncPlugin.logger.info('Running agent %s', agent.name) agent.create_backend().run() db.session.commit()
def scheduled_update(): from indico_livesync.plugin import LiveSyncPlugin clean_old_entries() for agent in LiveSyncAgent.find_all(): if agent.backend is None: LiveSyncPlugin.logger.warning( 'Skipping agent %s; backend not found', agent.name) continue if not agent.initial_data_exported: LiveSyncPlugin.logger.warning( 'Skipping agent %s; initial export not performed yet', agent.name) continue LiveSyncPlugin.logger.info('Running agent %s', agent.name) agent.create_backend().run() db.session.commit()
def scheduled_update(): from indico_livesync.plugin import LiveSyncPlugin if LiveSyncPlugin.settings.get('disable_queue_runs'): LiveSyncPlugin.logger.warning('Queue runs are disabled') return clean_old_entries() for agent in LiveSyncAgent.query.all(): if agent.backend is None: LiveSyncPlugin.logger.warning( 'Skipping agent %s; backend not found', agent.name) continue backend = agent.create_backend() queue_allowed, reason = backend.check_queue_status() if not queue_allowed: LiveSyncPlugin.logger.warning( 'Skipping agent %s; queue runs disabled: %s', agent.name, reason) continue LiveSyncPlugin.logger.info('Running agent %s', agent.name) backend.run() db.session.commit()
def test_clean_old_entries(dummy_event, db, dummy_agent): now = now_utc() for processed in (True, False): for day in range(10): db.session.add( LiveSyncQueueEntry(agent=dummy_agent, change=ChangeType.created, type=EntryType.event, event=dummy_event, processed=processed, timestamp=now - timedelta(days=day, hours=12))) db.session.flush() # Nothing deleted with the setting's default value clean_old_entries() assert LiveSyncQueueEntry.find().count() == 20 # Nothing deleted when explicitly set to 0 (which is the default) LiveSyncPlugin.settings.set('queue_entry_ttl', 0) clean_old_entries() assert LiveSyncQueueEntry.find().count() == 20 # Only the correct entries deleted, and no unprocessed ones LiveSyncPlugin.settings.set('queue_entry_ttl', 3) clean_old_entries() assert LiveSyncQueueEntry.find(processed=False).count() == 10 assert LiveSyncQueueEntry.find(processed=True).count() == 3
def test_clean_old_entries(dummy_event, db, dummy_agent): now = now_utc() for processed in (True, False): for day in range(10): db.session.add(LiveSyncQueueEntry(agent=dummy_agent, change=ChangeType.created, type=EntryType.event, event=dummy_event, processed=processed, timestamp=now - timedelta(days=day, hours=12))) db.session.flush() # Nothing deleted with the setting's default value clean_old_entries() assert LiveSyncQueueEntry.find().count() == 20 # Nothing deleted when explicitly set to 0 (which is the default) LiveSyncPlugin.settings.set('queue_entry_ttl', 0) clean_old_entries() assert LiveSyncQueueEntry.find().count() == 20 # Only the correct entries deleted, and no unprocessed ones LiveSyncPlugin.settings.set('queue_entry_ttl', 3) clean_old_entries() assert LiveSyncQueueEntry.find(processed=False).count() == 10 assert LiveSyncQueueEntry.find(processed=True).count() == 3