def notification(): if request.method == 'POST': notification = Notification() notification.message = request.form['message'] notification.subject = request.form['subject'] notification.status = 'Notifications submitted' notification.submitted_date = datetime.utcnow() logging.info("Record just created") try: db.session.add(notification) db.session.commit() ################################################## ## TODO: Refactor This logic into an Azure Function ## Code below will be replaced by a message queue ################################################# notification_id = notification.id msg = Message(str(notification_id)) queue_client.send(msg) ################################################# ## END of TODO ################################################# return redirect('/Notifications') except : logging.error('log unable to save notification') else: return render_template('notification.html')
def notification(): if request.method == 'POST': notification = Notification() notification.message = request.form['message'] notification.subject = request.form['subject'] notification.status = 'Notifications submitted' notification.submitted_date = datetime.utcnow() try: db.session.add(notification) db.session.commit() notification_id = notification.id msg = Message(str(notification_id)) # Call servicebus queue_client to enqueue notification ID queue_client.send(msg) # attendees = Attendee.query.all() # for attendee in attendees: # subject = '{}: {}'.format(attendee.first_name, notification.subject) # send_email(attendee.email, subject, notification.message) # notification.completed_date = datetime.utcnow() # notification.status = 'Notified {} attendees'.format(len(attendees)) # db.session.commit() return redirect('/Notifications') except Exception as e: logging.error(e) logging.error('log unable to save notification') else: return render_template('notification.html')
def notification(): if request.method == 'POST': notification = Notification() notification.message = request.form['message'] notification.subject = request.form['subject'] notification.status = 'Notifications submitted' notification.submitted_date = datetime.utcnow() try: db.session.add(notification) db.session.commit() ################################################## ## Refactor This logic into an Azure Function ## Code below will be replaced by a message queue ################################################# # Call servicebus queue_client to enqueue notification ID db.session.flush() msg = Message(notification.id) queue_client.send(msg) ################################################# ## END of TODO ################################################# return redirect('/Notifications') except: logging.error('log unable to save notification') else: return render_template('notification.html')
def notification(): if request.method == 'POST': notification = Notification() notification.message = request.form['message'] notification.subject = request.form['subject'] notification.status = 'Notifications submitted' notification.submitted_date = datetime.utcnow() try: db.session.add(notification) db.session.commit() print('Notification added with message: {} and text: {}'.format( request.form['message'], request.form['subject'])) # Call servicebus queue_client to enqueue notification ID # create queue client notification_id = str(notification.id) print('Adding notification_id: {} to queue: {}'.format( notification_id, app.config.get('SERVICE_BUS_QUEUE_NAME'))) print('Queue client is {}'.format(queue_client)) msg = Message(notification_id) queue_client.send(msg) return redirect('/Notifications') except: logging.error('log unable to save notification') else: return render_template('notification.html')
def notification(): if request.method == 'POST': notification = Notification() notification.message = request.form['message'] notification.subject = request.form['subject'] notification.status = 'Notifications submitted' notification.submitted_date = datetime.utcnow() try: db.session.add(notification) db.session.commit() print("notification") print(notification.id) print(notification.message) CONNECTION_STR = app.config.get('SERVICE_BUS_CONNECTION_STRING') print("CONNECTION STRING --> : " + CONNECTION_STR) QUEUE_NAME = app.config.get('SERVICE_BUS_QUEUE_NAME') print("SERVICE_BUS_QUEUE_NAME --> : " + QUEUE_NAME) sb_client = ServiceBusClient.from_connection_string(CONNECTION_STR) queue_client = sb_client.get_queue(QUEUE_NAME) message = Message(str(notification.id)) queue_client.send(message) return redirect('/Notifications') except: logging.error('log unable to save notification') else: return render_template('notification.html')
def notification(): if request.method == 'POST': notification = Notification() notification.message = request.form['message'] notification.subject = request.form['subject'] notification.status = 'Notifications submitted' notification.submitted_date = datetime.utcnow() try: db.session.add(notification) db.session.commit() db.session.refresh(notification) notid = '{}'.format(notification.id) try: msg = Message(notid) sentResult = queue_client.send(msg) # logging.info(msg) print(msg) except Exception as e: logging.error( 'Error occurred while sending message to queue {}', str(e)) return redirect('/Notifications') except: logging.error('Unable to save notification') else: return render_template('notification.html')
def notification(): if request.method == 'POST': notification = Notification() notification.message = request.form['message'] notification.subject = request.form['subject'] notification.status = 'Notifications submitted' notification.submitted_date = datetime.utcnow() try: notification.completed_date = datetime.utcnow() notification.status = 'Notification submitted' db.session.add(notification) db.session.commit() ################################################## ## TODO: Refactor This logic into an Azure Function ## Code below will be replaced by a message queue ################################################# # attendees = Attendee.query.all() # # for attendee in attendees: # subject = '{}: {}'.format(attendee.first_name, notification.subject) # send_email(attendee.email, subject, notification.message) # notification.completed_date = datetime.utcnow() # notification.status = 'Notification submitted' # db.session.commit() # TODO Call servicebus queue_client to enqueue notification ID notification_id = Notification.query.order_by( Notification.id.desc()).first() msg = Message(notification_id) queue_client.send(msg) ################################################# ## END of TODO ################################################# return redirect('/Notifications') except: logging.error('log unable to save notification') else: return render_template('notification.html')
def notification(): if request.method == 'POST': notification = Notification() notification.message = request.form['message'] notification.subject = request.form['subject'] notification.status = 'Notifications submitted' notification.submitted_date = datetime.utcnow() try: db.session.add(notification) db.session.commit() queue_client.send(Message('{}'.format(notification.id))) return redirect('/Notifications') except: logging.error('log unable to save notification') else: return render_template('notification.html')
def notification(): if request.method == 'POST': notification = Notification() notification.message = request.form['message'] notification.subject = request.form['subject'] notification.status = 'Notifications submitted' notification.submitted_date = datetime.utcnow() try: db.session.add(notification) db.session.commit() # Call servicebus queue_client to enqueue notification ID queue_client = QueueClient.from_connection_string(app.config.get('SERVICE_BUS_CONNECTION_STRING'), app.config.get('SERVICE_BUS_QUEUE_NAME')) message = Message(str(notification.id)) queue_client.send(message) return redirect('/Notifications') except : logging.error('log unable to save notification') else: return render_template('notification.html')
def notification(): if request.method == 'POST': notification = Notification() notification.message = request.form['message'] notification.subject = request.form['subject'] notification.status = 'Notifications submitted' notification.submitted_date = datetime.utcnow() try: db.session.add(notification) db.session.commit() ################################################## ## TODO: Refactor This logic into an Azure Function ## Code below will be replaced by a message queue ################################################# queue_client = QueueClient.from_connection_string( app.config.get("SERVICE_BUS_CONNECTION_STRING"), app.config.get("SERVICE_BUS_QUEUE_NAME")) msg = Message(f'{notification.id}'.encode()) logging.info(queue_client) logging.info(msg) # TODO Call servicebus queue_client to enqueue notification ID queue_client.send(msg) ################################################# ## END of TODO ################################################# return redirect('/Notifications') except: logging.error('log unable to save notification') else: return render_template('notification.html')