diff options
| author | VG <vg@devys.org> | 2016-02-25 23:54:43 +0100 | 
|---|---|---|
| committer | VG <vg@devys.org> | 2016-02-25 23:54:43 +0100 | 
| commit | d92048da7ec2d84a7b1cc8ad9f0dc62ee79e1426 (patch) | |
| tree | 65dd1f0b7da2edd15834552f2478fba646953111 | |
| download | wqueue-d92048da7ec2d84a7b1cc8ad9f0dc62ee79e1426.tar.gz wqueue-d92048da7ec2d84a7b1cc8ad9f0dc62ee79e1426.tar.bz2 wqueue-d92048da7ec2d84a7b1cc8ad9f0dc62ee79e1426.zip | |
first commit
| -rwxr-xr-x | tests/command.sh | 2 | ||||
| -rw-r--r-- | tests/queue.txt | 26 | ||||
| -rwxr-xr-x | tests/wqueue.py | 44 | 
3 files changed, 72 insertions, 0 deletions
| diff --git a/tests/command.sh b/tests/command.sh new file mode 100755 index 0000000..c942ef4 --- /dev/null +++ b/tests/command.sh @@ -0,0 +1,2 @@ +#!/bin/sh +exec sleep 10 diff --git a/tests/queue.txt b/tests/queue.txt new file mode 100644 index 0000000..0edb856 --- /dev/null +++ b/tests/queue.txt @@ -0,0 +1,26 @@ +a +b +c +d +e +f +g +h +i +j +k +l +m +n +o +p +q +r +s +t +u +v +w +x +y +z diff --git a/tests/wqueue.py b/tests/wqueue.py new file mode 100755 index 0000000..837fb26 --- /dev/null +++ b/tests/wqueue.py @@ -0,0 +1,44 @@ +#!/usr/bin/python3 + +import fcntl +import time +import subprocess +import os + +QUEUE_FILE = 'queue.txt' +COMMAND = './command.sh' + +def do_job(command=None, arg=None): +    assert(command) +    assert(arg) +    print('arg:', arg) +    print('doing operation with arg') +    ret = subprocess.check_call([command, arg]) +    print('ret:', ret) +    return ret == 0 + +def read_next_job_arg(): +    with open(QUEUE_FILE, 'r') as f: +        line = f.readline() +    return line.strip() + +def pop_job_arg(): +    queue = QUEUE_FILE +    queue_tmp = queue + '.tmp' +    linecount = 0 +    with open(queue, 'r') as fi, open(queue_tmp, 'w') as fo: +        for line in fi: +            linecount += 1 +            if linecount == 1: +                continue +            fo.write(line) +    os.rename(queue_tmp, queue) + +#with open('queue.txt', 'w') as f: +#    fcntl.lockf(f, fcntl.LOCK_EX) +#    time.sleep(9999) + +while True: +    job_arg = read_next_job_arg() +    if do_job(command=COMMAND, arg=job_arg): +        pop_job_arg() | 
