README
Example app that runs all kinds of shit in threads.
What's preconfigured
- Rails 4
- pg
- Sidekiq background jobs
- Redis
- Clockwork crons
- Rails App Templates
- Other
- Rails Assets include bower assets in rails apps
- Other rubygems from the ruby toolbox
- Models
- Views
- Controllers
- Debugging
- better_errors
- binding_of_caller
- bullet
- hirb-unicode for hirb
- quiet_assets
- recipient_interceptor
- respec
- letter_opener
- pry
- pry-rescue
- pry-stackknife pry-stack_explorer replacment, since pry-stack is unusable
- jazz_fingers
- pry-byebug
- spring
- web-console
- Documentation
- Testing
- Code Coverage
require
d)
Also helpfully installed (but not - foreman_god
- brakeman - rails security scanner
- bundler-audit - bundler gem dependencies scanner
- rubocop - Ruby/Rails syntax style checker
- taps-taps database import/exporter
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 likefriendly_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 developmentPORT
# defaults to 3000 without foreman/foreman_god, 5000 withDATABASE_URL
RAILS_SERVE_STATIC_FILES
# defaults: heroku: true, not heroku: falseSECRET_KEY_BASE
# must always be set to 30+ characters in production
Provided by this template
- General configuration
RAILS_ASSET_HOST
RAILS_FORCE_SSL
# onlyRAILS_ASSETS_VERSION
# default: 1.0RAILS_DEFAULT_LOCALE
# default: en (English)RAILS_LOG_LEVEL
# default: infoRAILS_TIMEZONE
# in rails format, default: UTCRAILS_STATIC_CACHE_CONTROL
RAILS_X_SENDFILE_HEADER
REDIS_URL
# if redis is usedSIDEKIQ_JOB_QUEUE_REDIS_NAMESPACE
# namespace used by Sidekiq for this app (default: sidekiq_myapp)
- Puma
PUMA_MIN_THREADS
# default: 0PUMA_MAX_THREADS
# default: 16PUMA_WORKERS
# default: no. of processorsPUMA_CONTROL_ENDPOINT
PUMA_CONTROL_ENDPOINT_AUTH_TOKEN
# auth_tokenPUMA_CONTROL_ENDPOINT_NO_AUTH_TOKEN
PUMA_LOADED
# set by config/puma.rb
- ActiveRecord
AR_DB_DEAD_CONN_TIMEOUT
# dead_connection_timeoutAR_DB_REAP_FREQ
# reaping_frequencyAR_DB_POOL
# pool
- Testing
SIMPLECOV
# set to enable simplecov during rspecSTART_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
Coins can be purchased through CoinMama