Rev 15178 | Blame | Compare with Previous | Last modification | View Log | RSS feed
from shop2020.utils.daemon import Daemonfrom dtr.utils.utils import to_java_datefrom dtr.utils.FetchLivePrices import get_mongo_connection, updatePriceForNotificationBundlesimport optparseimport sysfrom datetime import datetimefrom time import sleepparser = optparse.OptionParser()parser.add_option("-l", "--logfile", dest="logfile",type="string",help="Log all output to LOG_FILE")parser.add_option("-i", "--pidfile", dest="pidfile",type="string",help="Write the PID to pidfile")(options, args) = parser.parse_args()class NotificationDaemon(Daemon):def __init__(self, logfile='/var/log/services/NotificationDaemon.log', pidfile='/var/run/NotificationDaemon.pid'):Daemon.__init__(self, pidfile, stdout=logfile, stderr=logfile)def run(self):start()def start():while True:try:notificationBundles = list(get_mongo_connection().Catalog.Notifications.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}}))for notificationBundle in notificationBundles:print notificationBundle['skuBundleId']updatePriceForNotificationBundles(notificationBundle['skuBundleId'])print "==============SLEEPING============================"sleep(120)except Exception as e:print eif __name__ == "__main__":daemon = NotificationDaemon(options.logfile, options.pidfile)if len(args) == 0:daemon.run()elif len(args) == 1:if 'start' == args[0]:daemon.start()elif 'stop' == args[0]:daemon.stop()elif 'restart' == args[0]: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)