All Projects → steakknife → rails_plus_hacks_and_threads

steakknife / rails_plus_hacks_and_threads

Licence: MIT license
(DONT USE) Rails 4.x with support for lib/hacks and lib/threads

Programming Languages

ruby
36898 projects - #4 most used programming language
HTML
75241 projects
javascript
184084 projects - #8 most used programming language

README

Example app that runs all kinds of shit in threads.

What's preconfigured

Also helpfully installed (but not required)

How it works

Everything in lib/threads/*.rb gets spawned in a Thread.new (and supervised!)

Sidekiq, since it's popular, is also included. Sidekiq workers live at lib/workers/*.rb (Updated to work with Rails 4.2+ ActiveJob)

Clockwork, for timed jobs, is included as well lib/clocks/*.rb. Further only one instance of clockwork is spun up, no matter how many rails app instances are launched (using SingletonProcess is a really bad ZooKeeper).

lib/hacks/early/**/*.rb are loaded early by config/boot.rb unless env HACKS=n

lib/hacks/late/**/.rb are loaded later by config/environment.rb unless env HACKS=n

What's different

UUID id's (primary keys)

Postgres UUID-typed model primary key id's are enabled, but not default

Notes

  • UUID ids breaks default scope
  • Custom default scope based on created_at timestamp doesn't always work
  • UUID's allows for opaque/information hiding
  • Use the create_table, :..., id: uuid do way to specify UUID pk's
  • Foreign keys declared in migrations probably wont work
  • May want to define a custom to_param in the model or use something like friendly_id

Per view stylesheets and javascripts are not included in every view. Instead, per-view assets are loaded after corresponding application.js and application.css. This is more efficient to first page load as only the minimal assets are loaded. This could cause configuration issues and noobie confusion, so it's dropped.

Easy setup

git clone https://github.com/steakknife/rails_plus_hacks_and_threads yournewproject
cd yournewproject
bin/setup && ./Procfile.god

Requirements

  • ruby 2.2.0
  • postgres
  • redis
  • rake
  • bundler

Configuration

Can be set externally (such as heroku) or locally in config/application.yml

Standard

  • RAILS_ENV # defaults to development
  • PORT # defaults to 3000 without foreman/foreman_god, 5000 with
  • DATABASE_URL
  • RAILS_SERVE_STATIC_FILES # defaults: heroku: true, not heroku: false
  • SECRET_KEY_BASE # must always be set to 30+ characters in production

Provided by this template

  • General configuration
    • RAILS_ASSET_HOST
    • RAILS_FORCE_SSL # only
    • RAILS_ASSETS_VERSION # default: 1.0
    • RAILS_DEFAULT_LOCALE # default: en (English)
    • RAILS_LOG_LEVEL # default: info
    • RAILS_TIMEZONE # in rails format, default: UTC
    • RAILS_STATIC_CACHE_CONTROL
    • RAILS_X_SENDFILE_HEADER
    • REDIS_URL # if redis is used
    • SIDEKIQ_JOB_QUEUE_REDIS_NAMESPACE # namespace used by Sidekiq for this app (default: sidekiq_myapp)
  • Puma
    • PUMA_MIN_THREADS # default: 0
    • PUMA_MAX_THREADS # default: 16
    • PUMA_WORKERS # default: no. of processors
    • PUMA_CONTROL_ENDPOINT
    • PUMA_CONTROL_ENDPOINT_AUTH_TOKEN # auth_token
    • PUMA_CONTROL_ENDPOINT_NO_AUTH_TOKEN
    • PUMA_LOADED # set by config/puma.rb
  • ActiveRecord
    • AR_DB_DEAD_CONN_TIMEOUT # dead_connection_timeout
    • AR_DB_REAP_FREQ # reaping_frequency
    • AR_DB_POOL # pool
  • Testing
    • SIMPLECOV # set to enable simplecov during rspec
    • START_THREADS # set to n to disable, or y to force enable (default: foreman/foreman god: y, rails s: n)
    • HACKS # set to n to disable (will probably break the app)
    • EMAIL_INTERCEPTOR_RECIPIENT # email to redrect all outbound emails to

Author

  • Barry Allard

Contribs

  • Your name here

License

MIT

Security

Verify integrity of signed commits

git clone https://github.com/steakknife/rails_plus_hacks_and_threads
cd rails_plus_hacks_and_threads
gpg --recv-keys 0x14CAC196A122026C
git verify-commit HEAD

How this was created

rails new MyApp --database=postgresql --skip-test-unit

Please feel free to use a different markup language if you do not plan to run rake doc:app.

100% legitimately homeless tip-begging cup™

Please support open source

BTC: 19rFYN6yNpDaNBpAWKHzmeKAt7tiDPgdiP 19rFYN6yNpDaNBpAWKHzmeKAt7tiDPgdiP

Coins can be purchased through CoinMama

rattle-rattle

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].