From 3f83898780a0d5e8d02c192b11ebdd100c49c78e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20W=C3=B6ginger?= Date: Fri, 6 Sep 2024 21:06:22 +0200 Subject: [PATCH] fixes --- lib/radiator/job.ex | 4 ++-- lib/radiator/job_supervisor.ex | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/radiator/job.ex b/lib/radiator/job.ex index 982f6a96..f566b03a 100644 --- a/lib/radiator/job.ex +++ b/lib/radiator/job.ex @@ -15,14 +15,14 @@ defmodule Radiator.Job do defstruct [:work, :id, :max_retries, retries: 0, status: "new"] def start_job(args) do - if Enum.count(running_imports()) >= 5 do + if Enum.count(running_jobs()) >= 5 do {:error, :import_quota_reached} else DynamicSupervisor.start_child(JobRunner, {JobSupervisor, args}) end end - def running_imports() do + def running_jobs do match_all = {:"$1", :"$2", :"$3"} guards = [{:==, :"$3", "import"}] map_result = [%{id: :"$1", pid: :"$2", type: :"$3"}] diff --git a/lib/radiator/job_supervisor.ex b/lib/radiator/job_supervisor.ex index 5e0c3320..31b1e8a8 100644 --- a/lib/radiator/job_supervisor.ex +++ b/lib/radiator/job_supervisor.ex @@ -1,5 +1,8 @@ - defmodule Radiator.JobSupervisor do + @moduledoc """ + A Supervisor for each job for greater flexibility. Starts as a child of + JobRunner and as a Supervisor for each job + """ use Supervisor, restart: :temporary def start_link(args) do