Betwork / betwork

GNU General Public License v2.0
1 stars 0 forks source link

AWS #67

Closed andybirla closed 1 year ago

andybirla commented 1 year ago

implemented a few cool things on a new branch named aws:

  1. Every time a bet is proposed, an email is sent using AWS SES to the receiving user’s email address.
  2. Every time a bet is confirmed by the receiving user, an email is sent using AWS SES to the proposing user’s email address. Additionally, the bet is now added to an AWS DynamoDB with all the relevant information and status = confirmed.
  3. Every time a bet is cancelled by either user, an email is sent to the other user’s email address. Additionally, the status of the bet is then changed to cancelled in the AWS DynamoDB.
  4. Every 2 hours, a lambda function automatically triggers in AWS that goes ahead and checks the AWS DynamoDB for bets with the status = confirmed . For each of these bets, it goes ahead and checks the same API that we check in the app to see if any of those games have finished. If they have, the lambda function send an email to both the winner and the loser intimating them about how much money they lost/won, etc. The lambda function then sets the status of that bet to finished in the DB so that we do not wind up sending repeat emails. Note that the lambda function only updates the AWS DynamoDB and sends emails to the users. It does not update the application DB to reflect the updated user amounts.
  5. When a user visits the home page now, all their bets are checked to see if any have terminated and their balances are updated. Previously a user had to log in and then visit the My Bets page and then go back to the Home Page to see their updated balance.

There are some caveats to the above:

  1. The AWS DynamoDB and Lambda function (which I wrote in Python coz its not within the application and Python > Ruby) reside within my AWS account. Happy to share the login details for the same with everyone.
  2. Currently there is only one AWS DynamoDB so once we all start working on and testing this feature, I will make DynamoDBs for everyone and a separate one for production so that bets that we make on our local set up while testing, do not affect other people or production.
  3. AWS SES requires emails that I am sending to to be verified so I made some extra users in populate.rake that correspond to multiple of my email addresses that I have verified so that those users can be used. If at any point the application or the lambda function is trying to send an email to an email address.
andybirla commented 1 year ago

@joadoumie Feel free to merge the PR. Doesn't look like there are any conflicts and I tested the AWS features myself plenty but I don't want to merge it without another set of eyes at least glancing through. Good from my side though!