Git Product home page Git Product logo

core's Introduction

buzzn/core

buzzn/core is the central server-side application of buzzn. It contains the business logic, storage and API for our client/frontend applications.

Table of contents

Application Architecture

See docs/application_architecture.md.

Bin-Scripts

  • bin/console - starts application with pry session
  • bin/server - starts puma server
  • bin/rake - runs rake with application bundler context
  • bin/rspec - runs rspec with the current bundler context
  • bin/reset_test_db - runs some rake tasks to reset test DB
  • bin/example_data - runs some rake tasks to setup and seed DB for running local server

you can add ./bin to your PATH to simplely use console, server, rake or rspec.

Useful rake tasks

Discovergy Credentials

To wire up some datasource of some registers with the discovergy API you need add the credentials in .env.local

DISCOVERGY_LOGIN= DISCOVERGY_PASSWORD=

Overview

task name description source
rake db:empty Resets the database without dropping the DB.
Useful to reset DB when it has open connections.
Buzzn custom
rake db:seed:example_data Load an example localpool into the DB.
It does not prepare/empty the DB, run rake db:empty beforehands if required.
Buzzn custom
rake db:dump:transfer Transfer relevant data from buzzn_core_development to DATABASE_DUMP_NAME Buzzn custom
rake deploy:staging Deploy the application to staging. Buzzn custom
rake deploy:production Deploy the application to production and create a new release tag. Buzzn custom
rake heroku:update_db:staging Import the beekeeper dump locally and push it to staging. Buzzn custom
rake heroku:pull_db:staging Fetch a postgres dump from staging to DATABASE_DUMP_NAME, for use with db:dump:transfer
rake heroku:update_db:production Import the beekeeper dump locally and push it to production. Buzzn custom
rake heroku:pull_db:production Fetch a postgres dump from production to DATABASE_DUMP_NAME, for use with db:dump:transfer

Common testing workflow - after checking out a remote branch

  • checkout the branch
  • run reset_test_db once to ensure DB is prepared
  • run rspec

Common testing workflow - to run one test file

  • run reset_test_db once to ensure DB is prepared
  • run rspec path/to/spec_file

Loading setup and example data ("seeds")

Our application has two kinds of data that we can pre-load ("seed"), setup and example data.

Setup data is essential for any deployment of our application to work. Among others, it loads the buzzn organization into the database (which has hard-coded references in the code as Organization.buzzn). It can be loaded by running rake db:seed:setup_data on the shell.

Example data contains an exemplary localpool, as well as contracts and their users, meters etc.. This data is completely optional and should not be loaded into the production system. We use it for demos or testing where we don't have real user-generated data. Load it into the database by running rake db:seed:example_data on the shell.

Use the list of example users to log in. Login is the email, the password always is Example123.

Note that creating a user account with the buzzn operator role (super user) is not part of the example data. Use the separate rake tasks db:seed:buzzn_operators or db:seed:buzzn_operator to create one.

Important: both rake tasks do not empty the database before running, so when there already is data in the system, there may be conflicts, causing the task to abort. So if you know what you are doing, run rake db:empty first, to completely delete all data from the database.

Beekeeper import

How to run it

  • make sure your .env.local has the correct, safe DEFAULT_ACCOUNT_PASSWORD
  • load setup and example data into the local core DB (we need the user accounts)
    • rake db:empty db:seed:example_data
  • get the latest beekeeper MySQL dumps ("minipool_..." and "buzzndb_2017-11-17_TT.zip")
  • convert/load them into separate DBs in local postgres server
    • rake beekeeper:sql:mysql2postgres FILE=/absolute/path/to/minipooldb_2017-11-17_TT.zip
    • rake beekeeper:sql:mysql2postgres FILE=/absolute/path/to/buzzndb_2017-11-17_TT.zip
    • make sure no table has any errors, (check summary table at the end)
  • convert and import that data into the core DB:
    • rake beekeeper:import
  • optionally upload the local core DB into the Heroku DB
    • heroku pg:reset
    • heroku pg:push buzzn_development DATABASE_URL

How to deploy

We're running on Heroku, so you can deploy from Heroku's web interface if you want. To do it from the command line:

Maintenance Mode

to switch maintenance mode off/on execute the rake tasks on heroku for staging

`heroku run rake maintenance:on -a buzzn-core-staging`
`heroku run rake maintenance:on -a buzzn-core-staging`

or for production

`heroku run rake maintenance:on --remote production`
`heroku run rake maintenance:off --remote production`

this is important when the DB structure changes and the code and DB have mismatch for some time during deployment.

Deploy staging

Staging is deployed automatically for every green CI build on master. To do it manually: rake deploy:staging.

Deploy production

Run rake deploy:production. This pushes the current branch to Heroku and sets a release tag on the git repo.

Note on the previous, docker-based system and deployment: the Dockerfiles and related code have been removed, use this git tag to get them back. The same tag is set in the console app.

How to set up a development environment

Setup Ruby (using rbenv)

See https://github.com/sstephenson/rbenv#installation
The required version number is found in file .ruby-version

Install required software

imagemagick, postgresql, redis
for postgresql important on linux: 
  Edit the pg_hba.conf file /etc/postgresql/9.5/main/pg_hba.conf
  Change all authentication methods to "trust" and restart Server. 

use homebrew on a Mac

Set up the project

  • Grab the source git clone https://github.com/buzzn/core.git
  • Get dependencies
    cd core
    gem install bundler
    bundle install
  • Create a .env.development
    # Please keep the variables ordered alphabetically.
    # This file is for overrides of the .env file when running in development.
    ASSET_HOST=http://localhost:3000
    DEFAULT_ACCOUNT_PASSWORD=Example123
    DISPLAY_URL=http://localhost:2999
    SESSION_INACTIVITY_TIMEOUT=31536000 # 1 yearPOSTGRES_HOST=localhost
    POSTGRES_USER=postgres
    POSTGRES_PASSWORD=secret
    POSTGRES_BASE=postgres://$POSTGRES_USER@$POSTGRES_HOST
    DATABASE_URL=$POSTGRES_BASE/buzzn_developmentREDIS_HOST=localhost
    REDIS_CACHE_URL=redis://$REDIS_HOST:6379/0
    REDIS_SIDEKIQ_URL=redis://$REDIS_HOST:6379/1
    
    MAIL_BACKEND=stdout
    DISCOVERGY_LOGIN=YOUR_DISCOVERGY_LOGIN_NAME
    DISCOVERGY_PASSWORD=YOUR_DISCOVERGY_PASSWORD
  • Start postgres and and create a database and a user according to the entries of the previous .env.development
    createdb -U postgres -h localhost buzzn_development
    pg_restore -h localhost -d buzzn_development -U postgres ./some_data.dump # Import some data if you already have any
  • Start redis

Start server in development mode

bin/server

Reset and start test environment

RACK_ENV=test rake db:reset
guard

Set up rubocop

We run rubocop in CI to ensure consistent coding style and prevent error-prone syntax. Let your editor check the rules as well so you don't have to rely on CI.

Here's how to integrate it into editors:

To run rubocop from the CLI, simply type rubocop.

How to auto-corrrect rule offenses

Rubocop is smart enough to auto-corrrect most offenses by running rubocop -a

How to disable checking a rule locally

  • For a section of code:
# rubocop:disable RuleName
some = Exception(to, the, rule)
# rubocop:enable RuleName

How to run rubocop before every push automatically

Install the overcommit gem; it'll then use the .overcommit.yml file that's already checked in to run rubocop before pushing.

Misc admin info (may be outdated)

Start sidekiq message queue

redis-server
remark: probably necessary to reinit database (rake db:init) to let sidekiq run properly
bundle exec sidekiq -r ./config/sidekiq.rb

The (very useful) Sidekiq Admin interface currently isn't set up. See Sidekiq's documentation on standalone installation for how to enable it.

Stop sidekiq

rake sidekiq:kill

Find missing Indexes

lol_dba db:find_indexes

Run analysis of security vulnerabilities

brakeman

Further links & documentation

core's People

Contributors

bluepolarfox avatar clemensmanert avatar dependabot[bot] avatar drthth avatar eharit avatar katharinagrett avatar mguentner avatar mkristian avatar phillipoertel avatar sambagod avatar scsirdx avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

core's Issues

Fabricator metering_point remove meter

currently metering_point Fabricator has a meter attribute. like this:

Fabricator :mp_z2, from: :metering_point do
name 'PV'
readable 'world'
mode 'out'
meter { Fabricate(:easymeter_60051599) }
contracts { [Fabricate(:mpoc_buzzn_metering)] }
end

but this is wrong.
change it to:

Fabricator :mp_z2, from: :metering_point do
name 'PV'
readable 'world'
mode 'out'
contracts { [Fabricate(:mpoc_buzzn_metering)] }
end

and add the metering_point in meter:

Fabricator :easymeter_60051599, from: :easy_meter_q3d do
manufacturer_product_serialnumber '60051599'
after_create { |meter|
meter.metering_points << Fabricate(:mp_z2)
meter.save
}
end

bring api access_token to rails_view

the api is growing and more api endpoints are available to use.
the rails view (javascript) requires the access token to use the api.
there are many ways to make that happen.

  • create user access_token without expiration date at sign_in and use gon.gem to bring that token to rails javascript. delete token at sign_out.
  • use ouath in rails view to get fresh access_token. like normal SPA do it.

i like the first version.

Searching for resources

All listings of resources should have a search field to look for specific resources.
e.g. when viewing the members of a group I want to look for 'Christian' to see Christian's profile.

Role API

  • add member to metering_point
  • remove member from metering_point

Design start page

When entering app.buzzn.net the logged-off user should see a well designed and self-explained start page with informations about the buzzn platform.

Improve image viewing

At the moment users view images in their original size when clicking on it. Then, the page is redirecting to the URL of the image (e.g. /uploads/comment/image/2ccd862d-1926-4ec6-9521-23db11f4cc58/0ccf7aabd4b7fef940c1af10915b742c.jpg ).

The desired behaviour should look like this:
The User clicks on the thumbnail of the image and a new modal window should open with the image in it. To close this modal there should be a closing button "X".

Redirect User to right URL then clicking on notifications

When the User is getting a growl or badge notification he should be redirected to the right resource, e.g. when the notification tells the user that he has a new comment in one of his groups, he should be redirected to this group and the comments should scroll to the specific comment.
Maybe creating a view for each comment could help.

PaperTrail DEPRECATION WARNING

DEPRECATION WARNING: PaperTrail.track_associations has not been set. As of PaperTrail 5, it defaults to false. Tracking associations is an experimental feature so we recommend setting PaperTrail.config.track_associations = false in your config/initializers/paper_trail.rb . (called from block (2 levels) in <top (required)> at /home/rof/src/github.com/buzzn/buzzn/spec/requests/api/v1/contracts_spec.rb:161)

Improve flow of requests

At the moment, when receiving a request (e.g. friendship_request) the user always has to return to his profile to answer the request. Also metering_point_user_requests are only rendered when viewing the profile or the specific metering_point.

Maybe we can render them on every page or we build a show page for these requests and the user can redirect to this page when clicking on a badge notification.

friendship and friendship-request apis

i think this api endpoints make sense

/api/v1/friendship-requests

  • create friendship request
  • accept friendship request
  • deny friendship request

/api/v1/users/xxx/friendships

  • list friendships from a user

/api/v1/friendships

  • show single friendship
  • delete single friendship

discovergy live to last_reading

if you call discovergy live like this
https://my.discovergy.com/json/Api.getLive?meterId=EASYMETER_XXXXXXX&numOfSeconds=6&......
you get back a the last 6 secends from a meter. if the meter is offline more than 6 seconds you get back
{
status: "ok",
result: [ ]
}

this breaks the aggegation. a better solution would be to ask for the last reading.
so that everytime a reading is pressend and you display in the frontend that it is old.
this is currenty already implemented for buzzn_api.

What do you think @ChriWiChris

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.