Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update module to configure good job for background workers #10

Merged
merged 5 commits into from
Sep 30, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
robbevp marked this conversation as resolved.
Show resolved Hide resolved
};

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)))
robbevp marked this conversation as resolved.
Show resolved Hide resolved
// (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