Skip to content

Instantly share code, notes, and snippets.

@jineshpaloor
Last active August 29, 2015 14:04
Show Gist options
  • Save jineshpaloor/35f9fc4058485db7bd6d to your computer and use it in GitHub Desktop.
Save jineshpaloor/35f9fc4058485db7bd6d to your computer and use it in GitHub Desktop.
Daemon to checks whether 'status' of one model, if it is '0' then update another model, else if it is '1' then don't do anything.
#standard python libs
import logging
import time
#third party libs
from daemon import runner
from utils process_shipment_queue
class App():
def __init__(self):
self.stdin_path = '/dev/null'
self.stdout_path = '/dev/tty'
self.stderr_path = '/dev/tty'
self.pidfile_path = '/var/run/testdaemon/testdaemon.pid'
self.pidfile_timeout = 5
def run(self):
while True:
# The following function checks whether 'status' of
# one model, if it is '0' then update another model,
# else if it is '1' then don't do anything.
process_shipment_queue()
time.sleep(10)
app = App()
logger = logging.getLogger("DaemonLog")
logger.setLevel(logging.INFO)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler = logging.FileHandler("/var/log/testdaemon/testdaemon.log")
handler.setFormatter(formatter)
logger.addHandler(handler)
daemon_runner = runner.DaemonRunner(app)
#This ensures that the logger file handle does not get closed during daemonization
daemon_runner.daemon_context.files_preserve=[handler.stream]
daemon_runner.do_action()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment