nixos/beanstalkd: new service for existing package (#55953)
parent
b6c82183be
commit
e5405f9ae8
@ -0,0 +1,52 @@ |
||||
{ config, lib, pkgs, ... }: |
||||
|
||||
with lib; |
||||
|
||||
let |
||||
cfg = config.services.beanstalkd; |
||||
pkg = pkgs.beanstalkd; |
||||
in |
||||
|
||||
{ |
||||
# interface |
||||
|
||||
options = { |
||||
services.beanstalkd = { |
||||
enable = mkEnableOption "Enable the Beanstalk work queue."; |
||||
|
||||
listen = { |
||||
port = mkOption { |
||||
type = types.int; |
||||
description = "TCP port that will be used to accept client connections."; |
||||
default = 11300; |
||||
}; |
||||
|
||||
address = mkOption { |
||||
type = types.str; |
||||
description = "IP address to listen on."; |
||||
default = "127.0.0.1"; |
||||
example = "0.0.0.0"; |
||||
}; |
||||
}; |
||||
}; |
||||
}; |
||||
|
||||
# implementation |
||||
|
||||
config = mkIf cfg.enable { |
||||
|
||||
environment.systemPackages = [ pkg ]; |
||||
|
||||
systemd.services.beanstalkd = { |
||||
description = "Beanstalk Work Queue"; |
||||
after = [ "network.target" ]; |
||||
wantedBy = [ "multi-user.target" ]; |
||||
serviceConfig = { |
||||
DynamicUser = true; |
||||
Restart = "always"; |
||||
ExecStart = "${pkg}/bin/beanstalkd -l ${cfg.listen.address} -p ${toString cfg.listen.port}"; |
||||
}; |
||||
}; |
||||
|
||||
}; |
||||
} |
@ -0,0 +1,43 @@ |
||||
import ./make-test.nix ({ pkgs, lib, ... }: |
||||
|
||||
let |
||||
produce = pkgs.writeScript "produce.py" '' |
||||
#!${pkgs.python2.withPackages (p: [p.beanstalkc])}/bin/python |
||||
import beanstalkc |
||||
|
||||
queue = beanstalkc.Connection(host='localhost', port=11300, parse_yaml=False); |
||||
queue.put('this is a job') |
||||
queue.put('this is another job') |
||||
''; |
||||
|
||||
consume = pkgs.writeScript "consume.py" '' |
||||
#!${pkgs.python2.withPackages (p: [p.beanstalkc])}/bin/python |
||||
import beanstalkc |
||||
|
||||
queue = beanstalkc.Connection(host='localhost', port=11300, parse_yaml=False); |
||||
|
||||
job = queue.reserve(timeout=0) |
||||
print job.body |
||||
job.delete() |
||||
''; |
||||
|
||||
in |
||||
{ |
||||
name = "beanstalkd"; |
||||
meta.maintainers = [ lib.maintainers.aanderse ]; |
||||
|
||||
machine = |
||||
{ ... }: |
||||
{ services.beanstalkd.enable = true; |
||||
}; |
||||
|
||||
testScript = '' |
||||
startAll; |
||||
|
||||
$machine->waitForUnit('beanstalkd.service'); |
||||
|
||||
$machine->succeed("${produce}"); |
||||
$machine->succeed("${consume}") eq "this is a job\n" or die; |
||||
$machine->succeed("${consume}") eq "this is another job\n" or die; |
||||
''; |
||||
}) |
Loading…
Reference in new issue