2019-11-05 11:31:16 +00:00
|
|
|
import ./make-test-python.nix ({ pkgs, lib, ... }:
|
2019-02-22 13:10:02 +00:00
|
|
|
|
|
|
|
let
|
2019-02-22 19:17:30 +00:00
|
|
|
pythonEnv = pkgs.python3.withPackages (p: [p.beanstalkc]);
|
|
|
|
|
2019-02-22 13:10:02 +00:00
|
|
|
produce = pkgs.writeScript "produce.py" ''
|
2019-02-22 19:17:30 +00:00
|
|
|
#!${pythonEnv.interpreter}
|
2019-02-22 13:10:02 +00:00
|
|
|
import beanstalkc
|
|
|
|
|
|
|
|
queue = beanstalkc.Connection(host='localhost', port=11300, parse_yaml=False);
|
2019-02-22 19:17:30 +00:00
|
|
|
queue.put(b'this is a job')
|
|
|
|
queue.put(b'this is another job')
|
2019-02-22 13:10:02 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
consume = pkgs.writeScript "consume.py" ''
|
2019-02-22 19:17:30 +00:00
|
|
|
#!${pythonEnv.interpreter}
|
2019-02-22 13:10:02 +00:00
|
|
|
import beanstalkc
|
|
|
|
|
|
|
|
queue = beanstalkc.Connection(host='localhost', port=11300, parse_yaml=False);
|
|
|
|
|
|
|
|
job = queue.reserve(timeout=0)
|
2019-02-22 19:17:30 +00:00
|
|
|
print(job.body.decode('utf-8'))
|
2019-02-22 13:10:02 +00:00
|
|
|
job.delete()
|
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
name = "beanstalkd";
|
|
|
|
meta.maintainers = [ lib.maintainers.aanderse ];
|
|
|
|
|
2022-03-20 23:15:30 +00:00
|
|
|
nodes.machine =
|
2019-02-22 13:10:02 +00:00
|
|
|
{ ... }:
|
|
|
|
{ services.beanstalkd.enable = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
2019-11-05 11:31:16 +00:00
|
|
|
start_all()
|
2019-02-22 13:10:02 +00:00
|
|
|
|
2019-11-05 11:31:16 +00:00
|
|
|
machine.wait_for_unit("beanstalkd.service")
|
2019-02-22 13:10:02 +00:00
|
|
|
|
2019-11-05 11:31:16 +00:00
|
|
|
machine.succeed("${produce}")
|
|
|
|
assert "this is a job\n" == machine.succeed(
|
|
|
|
"${consume}"
|
|
|
|
)
|
|
|
|
assert "this is another job\n" == machine.succeed(
|
|
|
|
"${consume}"
|
|
|
|
)
|
2019-02-22 13:10:02 +00:00
|
|
|
'';
|
|
|
|
})
|