Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions erpnext_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
import json
import os
import sys
import time
import signal
import logging
from logging.handlers import RotatingFileHandler
import pickledb
from zk import ZK, const

from threading import Event

exit = Event()

EMPLOYEE_NOT_FOUND_ERROR_MESSAGE = "No Employee found for the given employee field value"
EMPLOYEE_INACTIVE_ERROR_MESSAGE = "Transactions cannot be created for an Inactive Employee"
DUPLICATE_EMPLOYEE_CHECKIN_ERROR_MESSAGE = "This employee already has a log with the same timestamp"
Expand Down Expand Up @@ -321,12 +325,19 @@ def _safe_get_error_str(res):

def infinite_loop(sleep_time=15):
print("Service Running...")
while True:
while not exit.is_set():
try:
main()
time.sleep(sleep_time)
exit.wait(sleep_time)
except BaseException as e:
print(e)

def quit(signo, _frame):
print("Interrupted by %d, shutting down" % signo)
exit.set()

if __name__ == "__main__":
# https://stackoverflow.com/a/46346184
for sig in ('TERM', 'HUP', 'INT'):
signal.signal(getattr(signal, 'SIG'+sig), quit)
infinite_loop()