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 clean_old_entries(): """Deletes obsolete entries from the queues""" from indico_livesync.plugin import LiveSyncPlugin from indico_livesync.models.queue import LiveSyncQueueEntry queue_entry_ttl = LiveSyncPlugin.settings.get('queue_entry_ttl') if not queue_entry_ttl: return expire_threshold = now_utc() - timedelta(days=queue_entry_ttl) LiveSyncQueueEntry.find(LiveSyncQueueEntry.processed, LiveSyncQueueEntry.timestamp < expire_threshold).delete(synchronize_session='fetch')
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