Skip to content

javs-perez/es_web_app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

* Ruby version 2.1.1

* Rails version 4.1.1

App to send notifications through RabbitMQ whenever a project's status changes to Funding. If previous status of project was funding, it does not send a notification again.

Models

Project

* status - valid values are "approved", "new", "pre-funding", and "funding"

* owner - which is a User

* name - added a name for the project so that they are easily visible on the UI, it does not need to be present to save a project

User

* name - name of the person that owns the project

* email - to be able to easily contact them

* phone_number - so that they are easily reached

Project_message

* message - this model was created to be able to keep the notifications that are not sent out due to server been down or unavailable. (a rake task :publish_messages needs to be run at different intervals before the app tries to send the messages again)

UI

* the UI is very simple, it has two main pages of users and projects. When looking at a user, it shows all projects connected with that user. The UI is nothing fancy, just a bit of bootstrap, but it sets up a way to view, create and update projects and users.

* there is no authentication

Notification

* When a project switches into the "funding" state, a notification is sent through the RabbitMQ server. This is done through a fanout exchange which broadcasts all the messages/notifications it receives to all the queues it knows.

* The app takes care of the transitioning from "funding" to "funding" and does not sent a notification for this.

Notification payload

header

* ref_id: a unique identifier for the message. It gest the time the message is sent and makes it into an integer. If the identifier needs to be more unique, that can be fixed.

* client_id: “es_web”, the name of the client generating this message

* timestamp: message’s created_at time

* priority: default is “normal”

* auth_token: an authorization token. Gave it the option to either take an environment variable or just a string if no variable is available.

* event_type: “project_status_update”, the type of event being sent

body

* user_id: project owner id

* channel: “email”, how to notify the account managers

* user_email: project owner email

* user_name: project owner name

* user_mobile: project owner’s phone number

<h3>Payload format: JSON</h3>

RabbitMQ Server

A local running RabbitMQ service was used in the dev environment and messages where sent to it. The receiver looked like this:

#!/usr/bin/env ruby
# encoding: utf-8
require "bunny"

conn = Bunny.new
conn.start

ch  = conn.create_channel
x   = ch.fanout("project.projects")
q   = ch.queue("receiver.projects", exclusive: true, durable: true)

q.bind(x)
puts " [*] Waiting for logs. To exit press CTRL+C"

begin
	q.subscribe(:ack => true, :block => true) do |delivery_info, properties, body|
		puts " [x] #{body}"

 		ch.ack(delivery_info.delivery_tag)
 	end
rescue Interrupt => _
	ch.close
	conn.close
end

This small code plus the RabbitMQ server was used to receive the messages and make sure they were in the right format.

RabbitMQ service down or unavailable

* When the message is been published if an exception is caught, the app saves the message into the ProjectMessage model. A rake task :publish_message needs to be run for the app to try to send the message again.

RSpec tests

* simply run rspec tests

* A integration test was done to test that the creation and update of a message redirects to the right pages

* Unit tests were done to make sure the project and user model where been validated correctly

* The bunny gem was used for RabbitMQ and bunny_mock gem was used to test the publishing.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages