def test_create_and_get_event_with_process_after(): connection = data_access.connect(DSN) event = Event(topic="foo", process_after=timestamps.now() + timedelta(seconds=10)) with data_access.cursor(connection) as cursor: created = data_access.create_event(cursor, event) with data_access.cursor(connection) as cursor: retrieved = data_access.get_event_by_id(cursor, created.id) assert retrieved.process_after == event.process_after
def test_now(): assert timestamps.now().tzinfo == timezone.utc
def test_process_events(app): app.event_stream = Mock() app.process_events() app.event_stream.process.assert_called_once() assert app.last_processed == timestamps.now()
retrieved = data_access.get_event_by_id(cursor, created.id) assert retrieved.process_after == event.process_after @pytest.mark.parametrize( [ "first_process_after", "second_process_after", "expected_first_status", "expected_second_status", ], [ [None, None, constants.PROCESSED, constants.PROCESSED,], [ timestamps.now() + timedelta(seconds=10), None, constants.PENDING, constants.PROCESSED, ], ], ) def test_get_next_event( first_process_after, second_process_after, expected_first_status, expected_second_status, ): connection = data_access.connect(DSN) topic = "foo" with data_access.cursor(connection) as cursor:
def process_events(self): LOGGER.debug("Processing events") self.last_processed = timestamps.now() self.event_stream.process()
def calculate_seconds_since_last_processed(self): return (timestamps.now() - self.last_processed).total_seconds()