From 7fab64127d492646769e605d69fd54b284b61e24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kutryj?= Date: Thu, 21 Aug 2025 13:07:42 +0200 Subject: [PATCH 1/3] feat(front): add finite cache ttl for running pipelines --- .../front/workflow_page/pipeline_status/model.ex | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/front/lib/front/workflow_page/pipeline_status/model.ex b/front/lib/front/workflow_page/pipeline_status/model.ex index c7e25384d..0f30e23e3 100644 --- a/front/lib/front/workflow_page/pipeline_status/model.ex +++ b/front/lib/front/workflow_page/pipeline_status/model.ex @@ -11,7 +11,8 @@ defmodule Front.WorkflowPage.PipelineStatus.Model do def load(pipeline_id) do Cacheman.fetch(:front, cache_key(pipeline_id), fn -> pipeline_status = load_pipeline_status_from_api(pipeline_id) - Cacheman.put(:front, cache_key(pipeline_id), pipeline_status) + cache_opts = get_cache_opts_for_status(pipeline_status) + Cacheman.put(:front, cache_key(pipeline_id), pipeline_status, cache_opts) {:ok, pipeline_status} end) end @@ -36,4 +37,14 @@ defmodule Front.WorkflowPage.PipelineStatus.Model do defp pipeline_favicon_status(:DONE, :STOPPED), do: "stopped" defp pipeline_favicon_status(:DONE, :CANCELED), do: "canceled" defp pipeline_favicon_status(_, _), do: "pending" + + # Running pipelines should be cached for a limited time + defp get_cache_opts_for_status(status) when status in ["running", "stopping", "pending"] do + [ttl: :timer.minutes(15)] + end + + # Use default - infinite cache for completed pipelines + defp get_cache_opts_for_status(_status) do + [ttl: :infinity] + end end From 8821c14ac54f8b526dccb4840488b98ac4b0c84f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kutryj?= Date: Thu, 21 Aug 2025 14:24:31 +0200 Subject: [PATCH 2/3] toil(front): slight refactoring, formatting --- front/lib/front/models/workflow.ex | 23 +++++++++++++++++-- .../workflow_page/pipeline_status/model.ex | 13 ++++------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/front/lib/front/models/workflow.ex b/front/lib/front/models/workflow.ex index 851e7ce04..16bd064ba 100644 --- a/front/lib/front/models/workflow.ex +++ b/front/lib/front/models/workflow.ex @@ -115,7 +115,8 @@ defmodule Front.Models.Workflow do nil response -> - Cacheman.put(:front, cache_key, encode(response)) + ttl = get_ttl_for_workflow(response) + Cacheman.put(:front, cache_key, encode(response), ttl: ttl) response end end @@ -137,7 +138,8 @@ defmodule Front.Models.Workflow do non_cached_workflows = find_many(non_cached_ids, :from_api) Enum.each(non_cached_workflows, fn workflow -> - Cacheman.put(:front, workflow_cache_key(workflow.id), encode(workflow)) + ttl = get_ttl_for_workflow(workflow) + Cacheman.put(:front, workflow_cache_key(workflow.id), encode(workflow), ttl: ttl) end) cached_workflows ++ non_cached_workflows @@ -526,4 +528,21 @@ defmodule Front.Models.Workflow do workflow end + + defp has_active_pipelines?(workflow) do + workflow.pipelines + |> Enum.any?(fn pipeline -> + pipeline.state in [:RUNNING, :STOPPING, :PENDING, :QUEUING, :INITIALIZING] + end) + end + + defp get_ttl_for_workflow(workflow) do + if has_active_pipelines?(workflow) do + # Finite cache for workflows with active pipelines + :timer.hours(2) + else + # Never expire for completed workflows + :infinity + end + end end diff --git a/front/lib/front/workflow_page/pipeline_status/model.ex b/front/lib/front/workflow_page/pipeline_status/model.ex index 0f30e23e3..5ffcf86da 100644 --- a/front/lib/front/workflow_page/pipeline_status/model.ex +++ b/front/lib/front/workflow_page/pipeline_status/model.ex @@ -11,8 +11,8 @@ defmodule Front.WorkflowPage.PipelineStatus.Model do def load(pipeline_id) do Cacheman.fetch(:front, cache_key(pipeline_id), fn -> pipeline_status = load_pipeline_status_from_api(pipeline_id) - cache_opts = get_cache_opts_for_status(pipeline_status) - Cacheman.put(:front, cache_key(pipeline_id), pipeline_status, cache_opts) + ttl = get_ttl_for_status(pipeline_status) + Cacheman.put(:front, cache_key(pipeline_id), pipeline_status, ttl: ttl) {:ok, pipeline_status} end) end @@ -39,12 +39,9 @@ defmodule Front.WorkflowPage.PipelineStatus.Model do defp pipeline_favicon_status(_, _), do: "pending" # Running pipelines should be cached for a limited time - defp get_cache_opts_for_status(status) when status in ["running", "stopping", "pending"] do - [ttl: :timer.minutes(15)] - end + defp get_ttl_for_status(status) when status in ["running", "stopping", "pending"], + do: :timer.minutes(15) # Use default - infinite cache for completed pipelines - defp get_cache_opts_for_status(_status) do - [ttl: :infinity] - end + defp get_ttl_for_status(_status), do: :infinity end From b9c5b7a9ecb22be6c39ac7752de81cd1f689e142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Kutryj?= Date: Thu, 21 Aug 2025 14:32:32 +0200 Subject: [PATCH 3/3] fix(front): initialize wf with empty list of pipelines --- front/lib/front/models/workflow.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/front/lib/front/models/workflow.ex b/front/lib/front/models/workflow.ex index 16bd064ba..87f5ba7fe 100644 --- a/front/lib/front/models/workflow.ex +++ b/front/lib/front/models/workflow.ex @@ -352,7 +352,8 @@ defmodule Front.Models.Workflow do requester_id: workflow.requester_id, created_at: DateTime.from_unix!(workflow.created_at.seconds), triggered_by: TriggeredBy.key(workflow.triggered_by), - rerun_of: workflow.rerun_of + rerun_of: workflow.rerun_of, + pipelines: [] } |> then(fn workflow when preload? ->