Skip to content

Commit

Permalink
Update module to configure good job for background workers
Browse files Browse the repository at this point in the history
  • Loading branch information
robbevp committed Sep 10, 2023
1 parent d9318bf commit b0ddbdb
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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" ];
Expand All @@ -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;
Expand Down Expand Up @@ -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" = { };
};
};
};
Expand Down

0 comments on commit b0ddbdb

Please sign in to comment.