def get_event_logs(session, limit, offset=None):
    """Get all log entries from event log"""
    total_entries = session.query(func.count(Log.id)).scalar()
    event_logs = session.query(Log).order_by(Log.id).offset(offset).limit(limit).all()
    return event_log_collection_schema.dump(
        EventLogCollection(event_logs=event_logs, total_entries=total_entries)
    )
Ejemplo n.º 2
0
def get_event_logs(
    *,
    limit: int,
    offset: Optional[int] = None,
    order_by: str = "event_log_id",
    session: Session = NEW_SESSION,
) -> APIResponse:
    """Get all log entries from event log"""
    to_replace = {"event_log_id": "id", "when": "dttm"}
    allowed_filter_attrs = [
        'event_log_id',
        "when",
        "dag_id",
        "task_id",
        "event",
        "execution_date",
        "owner",
        "extra",
    ]
    total_entries = session.query(func.count(Log.id)).scalar()
    query = session.query(Log)
    query = apply_sorting(query, order_by, to_replace, allowed_filter_attrs)
    event_logs = query.offset(offset).limit(limit).all()
    return event_log_collection_schema.dump(
        EventLogCollection(event_logs=event_logs, total_entries=total_entries))
Ejemplo n.º 3
0
 def test_serialize(self, session):
     event_log_model_1 = Log(event="TEST_EVENT_1", task_instance=self._create_task_instance())
     event_log_model_2 = Log(event="TEST_EVENT_2", task_instance=self._create_task_instance())
     event_logs = [event_log_model_1, event_log_model_2]
     session.add_all(event_logs)
     session.commit()
     event_log_model_1.dttm = timezone.parse(self.default_time)
     event_log_model_2.dttm = timezone.parse(self.default_time2)
     instance = EventLogCollection(event_logs=event_logs, total_entries=2)
     deserialized_event_logs = event_log_collection_schema.dump(instance)
     assert deserialized_event_logs == {
         "event_logs": [
             {
                 "event_log_id": event_log_model_1.id,
                 "event": "TEST_EVENT_1",
                 "dag_id": "TEST_DAG_ID",
                 "task_id": "TEST_TASK_ID",
                 "execution_date": self.default_time,
                 "owner": 'airflow',
                 "when": self.default_time,
                 "extra": None,
             },
             {
                 "event_log_id": event_log_model_2.id,
                 "event": "TEST_EVENT_2",
                 "dag_id": "TEST_DAG_ID",
                 "task_id": "TEST_TASK_ID",
                 "execution_date": self.default_time,
                 "owner": 'airflow',
                 "when": self.default_time2,
                 "extra": None,
             },
         ],
         "total_entries": 2,
     }