#!/usr/bin/python

import sys, os, string, time
import beanstalkc, threading
import subprocess, time
import logging, daemon

commands = beanstalkc.Connection(host='localhost', port=11300)
refresher = beanstalkc.Connection(host='localhost', port=11300)
refresher.watch('nagios-reload')
commands.watch('nagios')
found = False
while True:
    job = commands.reserve(timeout=1)
    if job <> None:
        print job.body
        found = True
    else:
	break
if found == False:
    print "There is nothing in the command queue"
found = False
while True:
    job = refresher.reserve(timeout=1)
    if job <> None:
        print job.body
        found = True
    else:
	break
if found == False:
    print "There is nothing in the supplimental queue"
    
sys.exit(0)
