def get_logs( self, start_time: pendulum.DateTime = None, end_time: pendulum.DateTime = None, ) -> List["FlowRunLog"]: """ Get logs for this flow run from `start_time` to `end_time`. Args: - start_time (optional): A time to start the log query at, useful for limiting the scope. If not provided, all logs up to `updated_at` are retrieved. - end_time (optional): A time to end the log query at. By default, this is set to `self.updated_at` which is the last time that the flow run was updated in the backend before this object was created. Returns: A list of `FlowRunLog` objects sorted by timestamp """ client = prefect.Client() end_time = end_time or self.updated_at logs_query = { with_args( "logs", { "order_by": {EnumValue("timestamp"): EnumValue("asc")}, "where": { "_and": [ {"timestamp": {"_lte": end_time.isoformat()}}, ( {"timestamp": {"_gt": start_time.isoformat()}} if start_time else {} ), ] }, }, ): {"timestamp": True, "message": True, "level": True} } result = client.graphql( { "query": { with_args( "flow_run", { "where": {"id": {"_eq": self.flow_run_id}}, }, ): logs_query } } ) # Unpack the result logs = result.get("data", {}).get("flow_run", [{}])[0].get("logs", []) return [FlowRunLog.from_dict(log) for log in logs]
def pendulum_to_nlprp_datetime(p: Pendulum, to_utc: bool = True) -> str: """ Converts a :class:`pendulum.Pendulum` to the ISO string format (with timezone) used by the NLPRP. """ if to_utc: p = convert_datetime_to_utc(p) return p.isoformat()
def _create_log_path(self, time: pendulum.DateTime, directory: str, group: str) -> str: timestamp = time.isoformat(timespec='microseconds').replace(':', '_') return os.path.join(directory, f'{timestamp}.{group}.log')