diff --git a/queue_message/appointmentrequestsender.py b/queue_message/appointmentrequestsender.py index df45dfc..1f6b834 100644 --- a/queue_message/appointmentrequestsender.py +++ b/queue_message/appointmentrequestsender.py @@ -93,6 +93,7 @@ class AppointmentRequestSender(threading.Thread): self.channel.start_consuming() def on_message(self, ch, method, properties, body): + self.check_and_stop_if_necessary(hour_to_check=11, mins_to_check=40) _message_count = self.cookiesPublisher.message_count() self.logger.info("message count in queue is {}".format(_message_count)) _received_object = body.decode("UTF-8") @@ -261,3 +262,13 @@ class AppointmentRequestSender(threading.Thread): else: self.logger.info("already read emails, no contact to use -> stop") self.channel.stop_consuming() + + def check_and_stop_if_necessary(self, hour_to_check, mins_to_check): + hour = datetime.datetime.now().hour + mins = datetime.datetime.now().minute + if hour == hour_to_check and mins >= mins_to_check: + self.logger.info("will stop") + self.channel.stop_consuming() + elif hour > hour_to_check: + self.logger.info("will stop") + self.channel.stop_consuming()