-
Notifications
You must be signed in to change notification settings - Fork 70
/
sample_daemon.py
40 lines (33 loc) · 1.01 KB
/
sample_daemon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
a sample daemonization script for the sqs listener
"""
import sys
from sqs_listener.daemon import Daemon
from sqs_listener import SqsListener
class MyListener(SqsListener):
def handle_message(self, body, attributes, messages_attributes):
pass
# run your code here
class MyDaemon(Daemon):
def run(self):
print("Initializing listener")
listener = MyListener('main-queue', 'error-queue')
listener.listen()
if __name__ == "__main__":
daemon = MyDaemon('/var/run/sqs_daemon.pid')
if len(sys.argv) == 2:
if 'start' == sys.argv[1]:
print("Starting listener daemon")
daemon.start()
elif 'stop' == sys.argv[1]:
print("Attempting to stop the daemon")
daemon.stop()
elif 'restart' == sys.argv[1]:
daemon.restart()
else:
print("Unknown command")
sys.exit(2)
sys.exit(0)
else:
print("usage: %s start|stop|restart" % sys.argv[0])
sys.exit(2)