Skip to content

Commit

Permalink
[dy] Expire certain pipeline runs (mage-ai#4727)
Browse files Browse the repository at this point in the history
  • Loading branch information
dy46 authored and oonyoontong committed May 2, 2024
1 parent 1ef0296 commit f5da359
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 10 additions & 1 deletion mage_ai/api/resources/PipelineRunResource.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
ScheduleStatus,
ScheduleType,
)
from mage_ai.orchestration.db import safe_db_query
from mage_ai.orchestration.db import db_connection, safe_db_query
from mage_ai.orchestration.db.models.schedules import (
BlockRun,
PipelineRun,
Expand Down Expand Up @@ -241,6 +241,15 @@ async def process_collection(self, query_arg, meta, user, **kwargs):
has_next = results_size > limit
final_end_idx = results_size - 1 if has_next else results_size

# Expire pipeline runs that are in progress so that the latest status is returned
# the next time they are fetched.
for run in results:
if run.status in (
PipelineRun.PipelineRunStatus.RUNNING,
PipelineRun.PipelineRunStatus.INITIAL,
):
db_connection.session.expire(run)

result_set = self.build_result_set(
results[0:final_end_idx],
user,
Expand Down
10 changes: 6 additions & 4 deletions mage_ai/frontend/components/Triggers/Detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,12 @@ function TriggerDetail({
mutate: fetchPipelineRuns,
} = api.pipeline_runs.pipeline_schedules.list(
pipelineScheduleID,
pipelineRunsRequestQuery, {
refreshInterval: 3000,
revalidateOnFocus: true,
});
pipelineRunsRequestQuery,
{
refreshInterval: 3000,
revalidateOnFocus: true,
},
);
const pipelineRuns = useMemo(() => dataPipelineRuns?.pipeline_runs || [], [dataPipelineRuns]);
const totalRuns = useMemo(() => dataPipelineRuns?.metadata?.count || [], [dataPipelineRuns]);

Expand Down

0 comments on commit f5da359

Please sign in to comment.