summaryrefslogtreecommitdiff
path: root/Biz/PodcastItLater/Worker.nix
blob: 974a3bad5d4c6b9ac04066e173a9a67d6921249a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
{
  options,
  lib,
  config,
  pkgs,
  ...
}: let
  cfg = config.services.podcastitlater-worker;
in {
  options.services.podcastitlater-worker = {
    enable = lib.mkEnableOption "Enable the PodcastItLater worker service";
    dataDir = lib.mkOption {
      type = lib.types.path;
      default = "/var/podcastitlater";
      description = "Data directory for PodcastItLater (shared with web)";
    };
    package = lib.mkOption {
      type = lib.types.package;
      description = "PodcastItLater worker package to use";
    };
  };
  config = lib.mkIf cfg.enable {
    systemd.services.podcastitlater-worker = {
      path = [cfg.package pkgs.ffmpeg]; # ffmpeg needed for pydub
      wantedBy = ["multi-user.target"];
      after = ["network.target"];
      preStart = ''
        # Create data directory if it doesn't exist
        mkdir -p ${cfg.dataDir}

        # Manual step: create this file with secrets
        # OPENAI_API_KEY=your-openai-api-key
        # S3_ENDPOINT=https://your-s3-endpoint.digitaloceanspaces.com
        # S3_BUCKET=your-bucket-name
        # S3_ACCESS_KEY=your-s3-access-key
        # S3_SECRET_KEY=your-s3-secret-key
        test -f /run/podcastitlater/worker-env
      '';
      script = ''
        ${cfg.package}/bin/podcastitlater-worker
      '';
      description = ''
        PodcastItLater Worker Service - processes articles to podcasts
      '';
      serviceConfig = {
        Environment = [
          "AREA=Live"
          "DATA_DIR=${cfg.dataDir}"
        ];
        EnvironmentFile = "/run/podcastitlater/worker-env";
        KillSignal = "TERM";
        KillMode = "mixed";
        Type = "simple";
        Restart = "always";
        RestartSec = "10";
        # Give the worker time to finish current job
        TimeoutStopSec = "300"; # 5 minutes
        # Send SIGTERM first, then SIGKILL after timeout
        SendSIGKILL = "yes";
      };
    };
  };
}