Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions cloud_pipelines_backend/orchestrator_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ def process_each_queue_once(self):
break

def internal_process_queued_executions_queue(self, session: orm.Session):
_logger.debug("Selecting queued execution to process.)")

query_start_timestamp = time.monotonic_ns()
query = (
sql.select(bts.ExecutionNode).where(
bts.ExecutionNode.container_execution_status.in_(
Expand All @@ -133,12 +136,15 @@ def internal_process_queued_executions_queue(self, session: orm.Session):
.limit(1)
)
queued_execution = session.scalar(query)
query_duration_ms = (time.monotonic_ns() - query_start_timestamp) / 1_000_000
if queued_execution:
self._queued_executions_queue_idle = False
start_timestamp = time.monotonic_ns()

with contextual_logging.execution_logging_context(queued_execution):
_logger.info("Before processing queued execution")
_logger.info(
f"Before processing queued execution. (Query duration: {query_duration_ms}ms)"
)
try:
self.internal_process_one_queued_execution(
session=session, execution=queued_execution
Expand Down Expand Up @@ -169,13 +175,18 @@ def internal_process_queued_executions_queue(self, session: orm.Session):

return True
else:
if not self._queued_executions_queue_idle:
if not self._queued_executions_queue_idle or query_duration_ms > 1000:
self._queued_executions_queue_idle = True
_logger.debug("No queued executions found")
_logger.debug(
f"No queued executions found. (Query duration: {query_duration_ms}ms.)"
)
return False

def internal_process_running_executions_queue(self, session: orm.Session):
_logger.debug("Selecting running container execution to process.)")

# Select only the ID to avoid loading large JSON columns into the sort buffer.
query_start_timestamp = time.monotonic_ns()
id_query = (
sql.select(bts.ContainerExecution.id)
.where(
Expand All @@ -193,6 +204,7 @@ def internal_process_running_executions_queue(self, session: orm.Session):
running_container_execution = (
session.get(bts.ContainerExecution, execution_id) if execution_id else None
)
query_duration_ms = (time.monotonic_ns() - query_start_timestamp) / 1_000_000
if running_container_execution:
self._running_executions_queue_idle = False
start_timestamp = time.monotonic_ns()
Expand All @@ -210,7 +222,12 @@ def internal_process_running_executions_queue(self, session: orm.Session):
container_execution_id=running_container_execution.id,
execution_node_ids=execution_node_ids,
):
_logger.info("Before processing running container execution")
queries_duration_ms = (
time.monotonic_ns() - query_start_timestamp
) / 1_000_000
_logger.info(
f"Before processing running container execution. Queries duration {queries_duration_ms}ms."
)
try:
self.internal_process_one_running_execution(
session=session,
Expand Down Expand Up @@ -297,8 +314,10 @@ def internal_process_running_executions_queue(self, session: orm.Session):
)
return True
else:
if not self._running_executions_queue_idle:
_logger.debug("No running container executions found")
if not self._running_executions_queue_idle or query_duration_ms > 1000:
_logger.debug(
f"No running container executions found. (Query duration: {query_duration_ms}ms.)"
)
self._running_executions_queue_idle = True
return False

Expand Down
Loading