def consume(self, event: Dict[str, Any]) -> None: # Copy the event, so that we don't pass the `failed_tries' # data to send_email_from_dict (which neither takes that # argument nor needs that data). copied_event = copy.deepcopy(event) if 'failed_tries' in copied_event: del copied_event['failed_tries'] handle_send_email_format_changes(copied_event) send_email_from_dict(copied_event)
def send_email(self, event: Dict[str, Any]) -> None: # Copy the event, so that we don't pass the `failed_tries' # data to send_email (which neither takes that # argument nor needs that data). copied_event = copy.deepcopy(event) if "failed_tries" in copied_event: del copied_event["failed_tries"] handle_send_email_format_changes(copied_event) self.connection = initialize_connection(self.connection) send_email(**copied_event, connection=self.connection)
def handle(self, *args: Any, **options: Any) -> None: if settings.EMAIL_DELIVERER_DISABLED: sleep_forever() with lockfile("/tmp/zulip_email_deliver.lockfile"): while True: email_jobs_to_deliver = ScheduledEmail.objects.filter( scheduled_timestamp__lte=timezone_now()) if email_jobs_to_deliver: for job in email_jobs_to_deliver: handle_send_email_format_changes(job) try: send_email(**loads(job.data)) job.delete() except EmailNotDeliveredException: logger.warning("%r not delivered" % (job, )) time.sleep(10) else: # Less load on the db during times of activity, # and more responsiveness when the load is low time.sleep(2)
def handle(self, *args: Any, **options: Any) -> None: if settings.EMAIL_DELIVERER_DISABLED: sleep_forever() while True: email_jobs_to_deliver = ScheduledEmail.objects.filter( scheduled_timestamp__lte=timezone_now()) if email_jobs_to_deliver: for job in email_jobs_to_deliver: data = loads(job.data) handle_send_email_format_changes(data) try: send_email(**data) job.delete() except EmailNotDeliveredException: logger.warning("%r not delivered" % (job,)) time.sleep(10) else: # Less load on the db during times of activity, # and more responsiveness when the load is low time.sleep(2)