- CHANGELOG
- Api Endpoint Documentation
- App-Specification (google docs), old app spec (Hackpad)
- Entity Relationship Diagram [2] [3]
- How-To Setup Development Environment
- Social Activity
- Activity Feed API
- Follower Model API
Delete and Destroy are globally disabled in lib/ts_prevent_deletion.rb,
instead we use a db-column called deleted_at or set a specific state on the model. There is one exception, Device(s) can be removed from the db.
Authorization is done via a token in the http header which is compared to a locally saved token for every user. The token is invalidated on logout and regenerated on login. On first signup the token is also created so a signed up user is already logged in.
We use Pundit for Authentication. In the app/policies/ folder are all files which contain authentication logic.
We develop on OSX and Ubuntu.
Setting environment variables can be done e.g. via .env or with another approach which we use atm, but we'll might switch to Rails secrets.yaml.
If deploying to AWS with ElasticBeanstalk the secret environment variables like database credentials are fetched from an S3 Bucket ( "https://s3.eu-central-1.amazonaws.com/timeslot.casino.beanstalk.configs/") and are expected to be defined in a file called '{ELASTICBEANSTALK_ENVIRONMENT_NAME}_config_variables.rb'. In this file the variables are defined in the same way as below.
On a local machine the configs are expected at ```secret-configs`` folder, which is not checked into version control.
ENV['MAX_THREADS'] # number of concurrent Puma Webserver threads, defaults to 5 if not set
ENV['NOTIFICATION_WORKERS'] # number of concurrent SuckerPunch Notification Workers, defaults to 5 if not set
ENV['INLINE_WORKERS'] = 'false' # controls if sucker punch jobs run async
ENV['DB_POOL'] # number of available database connections, defaults to MAX_THREADS or 10 if both are not set, BUT should be at least MAX_THREADS + NOTIFICATION_WORKERS
# maximum on heroku free plan is 20
ENV['PG_EXPLAIN'] = 'true' # show output of pg EXPLAIN ANALYZE for all SELECT queries, use carefully
# pagination
ENV['PAGINATION_DEFAULT_FILTER'] = none' # if not provided by client
ENV['PAGINATION_DEFAULT_MODE'] = 'all' # if not provided by client
ENV['PAGINATION_DEFAULT_LIMIT'] = '40' # if not provided by client
ENV['PAGINATION_MAX_LIMIT'] = '100' # depends on the environment...
ENV['TS_SLOT_WEBSHARING_URL'] = 'http://timesl.ot/' # domain name for the slot websharing service app, given we have one
ENV['WEB_IMPORTER_PASSWORD'] = 'Q8NUwaR4' # password used by web-import service
ENV['WEB_CONCURRENCY] = 2 # number of puma workers
# maintenance
ENV['ENABLE_IOS_DB_CLEAN'] = 'true' # to enable the endpoint for db cleaning
# let the frontend know if it needs to update itself
ENV['IOS_CURRENT_CLIENT_VERSION'] = '1.000'
ENV['IOS_MINIMUM_CLIENT_VERSION'] = '1.000'
ENV['ANDROID_CURRENT_CLIENT_VERSION'] = '1.000'
ENV['ANDROID_MINIMUM_CLIENT_VERSION'] = '1.000'The Data Team provides an elasticSearch - Slot Search Interface for it's crawler data.
ENV['TS_GLOBALSLOTS_SEARCH_SERVICE_URL']) # elastic search url
ENV['TS_GLOBALSLOTS_SEARCH_SERVICE_NAME'] # username
ENV['TS_GLOBALSLOTS_SEARCH_SERVICE_PASSWORD'] # password
Allows to get a Global Slot by its muid (slot_uuid).
ENV['TS_DATA_MALL_URL']) # data mall url
ENV['TS_DATA_MALL_NAME'] # username
ENV['TS_DATA_MALL_PASSWORD'] # passwordThe following env variables are available/expected:
ENV['AWS_ACCESS_KEY_ID']
ENV['AWS_SECRET_ACCESS_KEY']
ENV['AWS_REGION']- AWS ElasticBeanstalk
- Backend Rails App Deployment
- Heroku-like Service that uses EC2, VPC and other things
- AWS RDS
- Postgres Database
- AWS ElastiCache
- Redis
- AWS Simple Notification Service
- Apple Push Notifications
- AWS Simple Email Service
- Password Reset Email
- AWS Route53
- DNS Management
- AWS S3
- Stores Configuration Files for ElasticBeanstalk
- AWS Workmail
- Email Address Management for Email Addresses used to register at other external services
- AWS IAM - AWS Account and Access Management
- AWS Certificate Manager - Create Certificates for HTTPS
ENV['AWS_PLATFORM_APPLICATION_IOS'] # aws arn endpoint (iOS)
# enable push endpoints, if not set explicitly endpoint is enabled by default
# ENV['PUSH_DEFAULT'] = 'true'
ENV['PUSH_APNS'] = 'false'
ENV['PUSH_APNS_SANDBOX'] = 'true'Cloud Service for our Media Data, via Heroku Addon, Docs.
For local testing a free account can be opened and the following vars need to be set:
ENV['TS_RAILS_BACKEND_CLOUDINARY_CLOUD_NAME']
ENV['TS_RAILS_BACKEND_CLOUDINARY_API_KEY']
ENV['TS_RAILS_BACKEND_CLOUDINARY_API_SECRET']Redis is to store our Activity Streams via a service like Heroku Redis Addon. The following var need to be set:
ENV['REDIS_URL']For local testing you need a locally running redis server listening on localhost:6379
for exception monitoring, via Heroku Addon, Docs | Github
Log management service, collects logs from AWS Instances via remote_syslog2 deamon, which gets installed on all EC2 instances via ebextensions config.
Papertrail Account for Dev environments is registered with email casino-dev@timeslot.rocks, Password is in LastPass Company Account.
For ease of use check out Papertrail CLI.
- sometimes the rsyslog deamon stops working on the ec2 instance
- to restart ssh into ec2 &
sudo /sbin/service remote_syslog restart
- Start default rails dev server (s=server)
rails s| Flag | Effect |
|---|---|
:focus |
let only marked specs run |
:db |
print the database interactions to the console, does also :focus the marked spec |
:explain |
print postgres EXPLAIN ANALYZE for SELECT queries to console, does also :focus the marked spec |
:commit |
persist data in database, see below |
:seed |
load database seeds |
:keep_data |
doesn't clean metaslot, baseslot, stdslot, reslot, friendship & user table for marked group, cleans after group has run, for read-only specs |
:vcr |
use vcr to mock external requests, see below |
:aws |
use aws to mock external requests to AWS service, see below |
:redis |
use redis to indicates that data is stored into redis which has to be cleaned after each test |
:async |
use async to mock asynchronously requests through sucker punch workers, see below |
:activity |
used to turn on triggering activities (is off by default) |
Manages database transactions for specs/tests.
Default strategy is transaction.
If a spec needs truncation, a :commit flag can be set on the test.
describe "auditing", :commit do
# spec goes here
end
The specs uses the vcr gem (and webmock gem), which records external requests on the first run and on previous runs always returns this response. This makes that specs faster and allows them to be run offline, but also hides if there had been changes in the external API which breaks the comunication.
To enable outgoing http requests in specs (Rails test env) edit the first line
in the spec/support/vcr_setup.rb file.
To enable outgoing http requests in the Rails Dev Env there is a setting in
the development.rb file:
WebMock.allow_net_connect!
The specs uses the AWS webmock, which simulate external requests to AWS services. This allows to test in an special environment where the changes would not store live.
[Sucker Punch] (https://github.com/brandonhilkert/sucker_punch)
The specs uses a webmock to handle asynchronously tasks, which is internally handled by the sucker punch gem. This allows to test worker threads inside rails specs.
Detects n+1 database queries.
To run specs automatically if a file was edited. At the end of this document is my somewhat messy Guardfile with some customizations.
The documentation is based on the spec/acceptance tests. The DSL is outlined here.
- This is done via gem rspec_api_documentation. Call:
rake docs:generate
Per default the documentation is generated as markdown. The generated Markdown files will be in doc/api folder.
Can be automatically created in two flavours, both with their up- and downsides:
- install graphviz with pango/cairo support.
brew install Caskroom/cask/xquartz
brew install graphviz --with-pangocairo- gen simple ERD
bin/rake generate_lean_erd- gen detailed ERD
bin/rake generate_adv_erdAt the moment we use a mix of the GitFlow Workflow and the Forking Workflow.
- GitFlow Explained
- GitFlow Tutorial (german)
brew install git git-flow-avh
- When commiting use the following commit message format:
ACTION KEY #resolved <comment>
-
e.g.
git commit -m "ADD BKD-2 including module to stretch lifetime" -
KEY is the Jira Issue Number
-
ACTION should be one of ADDition, DELetion, MODification, IMProvement, FIX for small bugfixes, WIP if you need to commit while work in progress, WTF in special cases...
-
More detailed information on JIRA smart commit messages here.
However, this is likely to change sooner or later... The JIRA-Github integration is not yet done.
- If patching third party libraries we use a ts_ prefix.
- The API Responses are in lowerCamelCase, the transformation from snake_case is automatically handled by jbuilder gem
- rubocop
- rails best practices
- Cocoa Rest Client
- Postman - google chrome app
- RESTClient - addon for firefox
- PGCommander
- Navicat Essentials for POSTGRESQL
- PGAdmin - not so fancy but free
- Redis Desktop Manager
