From b0ddbdb40bdae1bb7cc682bb234ff107e8b0b0ec Mon Sep 17 00:00:00 2001 From: Robbe Van Petegem Date: Sun, 10 Sep 2023 14:36:55 +0200 Subject: [PATCH] Update module to configure good job for background workers --- default.nix | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/default.nix b/default.nix index a45346b..7456b5d 100644 --- a/default.nix +++ b/default.nix @@ -56,7 +56,29 @@ in }; workers = mkOption { - description = "Amount of background workers that should be spawned."; + description = '' + A list of background workers with the queues they should use. Each element in the list will spawn a worker with the queues passed. + + The available options for queues are: + * `*` (All queues) + * default + * within_30_seconds + * within_5_minutes + * within_30_minutes + * whenever + Queues can be configured in different ways. Please check the good job docs for the possibilities: https://github.com/bensheldon/good_job#optimize-queues-threads-and-processes + ''; + default = [ "default,within_30_seconds" "+default,within_30_seconds,within_5_minutes,within_30_minutes,whenever" "+default,within_30_seconds,within_5_minutes,within_30_minutes,whenever" "+default,within_30_seconds,within_5_minutes,within_30_minutes,whenever" ]; + example = [ "default,within_30_seconds" "within_5_minutes:5;within_30_minutes:2;whenever:2" "+default,within_30_seconds,within_5_minutes,within_30_minutes,whenever" ]; + type = types.int; + }; + + delayedJobWorkers = mkOption { + description = '' + Amount of background workers using Delayed Job that should be spawned. + + This option is deprecated and should only be used to finish working existing jobs. + ''; default = 4; example = 8; type = types.int; @@ -160,8 +182,30 @@ in }; }; } // (builtins.foldl' (x: y: x // y) { } (builtins.genList + (index: { + "accentor-worker-${toString (index)}" = { + after = [ "network.target" "accentor-api.service" "postgresql.service" ]; + requires = [ "postgresql.service" ]; + wantedBy = [ "multi-user.target" ]; + environment = env // { + GOOD_JOB_QUEUES = (builtins.elemAt cfg.workers index); + }; + path = [ pkgs.ffmpeg gems gems.wrappedRuby ]; + serviceConfig = { + EnvironmentFile = cfg.environmentFile; + Type = "simple"; + User = "accentor"; + Group = "accentor"; + Restart = "on-failure"; + WorkingDirectory = api; + ExecStart = "${gems}/bin/bundle exec good_job start"; + }; + }; + }) + (builtins.length cfg.workers))) + // (builtins.foldl' (x: y: x // y) { } (builtins.genList (n: { - "accentor-worker${toString n}" = { + "accentor-worker-delayed${toString n}" = { after = [ "network.target" "accentor-api.service" "postgresql.service" ]; requires = [ "postgresql.service" ]; wantedBy = [ "multi-user.target" ]; @@ -179,7 +223,7 @@ in }; }) - cfg.workers)) // lib.optionalAttrs cfg.rescanTimer.enable { + cfg.delayedJobWorkers)) // lib.optionalAttrs cfg.rescanTimer.enable { accentor-rescan = { description = "Accentor rescan"; restartIfChanged = false; @@ -222,7 +266,7 @@ in services.nginx.upstreams = mkIf (cfg.nginx != null) { "accentor_api_server" = { servers = { - "unix:///run/accentor/server.socket" = {}; + "unix:///run/accentor/server.socket" = { }; }; }; };