Skip to content

Commit

Permalink
Adding Sidekiq monitoring, and also updating docker-compose.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
atbaker committed Mar 10, 2015
1 parent 0aa9945 commit 5f8996e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Set development environment variables here. Uses https://github.com/bkeepers/dotenv

SIDEKIQ_TESTING=inline
SIDEKIQ_DASHBOARD_PASSWORD=sidekiq

SUNLIGHT_KEY=YOURKEY

Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ If you want to use [Docker](https://www.docker.com/) for local development, this

If you already have Docker and Docker Compose installed, starting this app is as easy as `docker-compose up`.

After you've created the Docker containers, you can apply the migrations to the database with `docker-compose run web rake db:migrate`.

### RVM

*If you don't want to use Docker* for some reason, you can also just install ruby and all dependencies on your own:
Expand All @@ -38,6 +40,19 @@ If you already have Docker and Docker Compose installed, starting this app is as
1. Install Posgres and set up a user account.
1. Install gems w/ `bundle install`

You will also need to start a local PostgreSQL database and a Redis instance.

Finally, apply the database migrations with `rake db:migrate`.

### Sidekiq worker

This app uses [sidekiq](https://github.com/mperham/sidekiq) to do background processing for a few tasks.

By default, the app expects a sidekiq worker process to be available. You can start this process locally by running `bundle exec sidekiq -c 10`.

If you don't want to send jobs to sidekiq, you can set the `SIDEKIQ_TESTING` environment variable to `'inline'` or `'fake'`.


Deployment & Hosting Environments
---------------------------------

Expand Down
17 changes: 16 additions & 1 deletion config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,19 @@ use Rack::Cors do
:headers => :any,
:methods => [:get, :post, :put, :options]
end
end
end

# Code to enable the sidekiq monitoring dashboard
require 'sidekiq'
Sidekiq.configure_client do |config|
config.redis = { :size => 1 }
end

require 'sidekiq/web'
map '/sidekiq' do
use Rack::Auth::Basic, "Protected Area" do |username, password|
username == 'sidekiq' && password == ENV["SIDEKIQ_DASHBOARD_PASSWORD"]
end

run Sidekiq::Web
end
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
get '/calls/new_connection', to: 'calls#new_connection'
post '/calls/connection_gather_prompt', to: 'calls#connection_gather_prompt'
post '/calls/connection_gather', to: 'calls#connection_gather'

require 'sidekiq/api'
get "/queue-status" => proc { [200, {"Content-Type" => "text/plain"}, [Sidekiq::Queue.new.size < 100 ? "OK" : "UHOH" ]] }
get "/queue-latency" => proc { [200, {"Content-Type" => "text/plain"}, [Sidekiq::Queue.new.latency < 30 ? "OK" : "UHOH" ]] }
end
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ web:
- DATABASE_URL=postgres://postgres@db:5432/postgres
- REDIS_URL=redis://redis@redis:6379/

worker:
image: mayday20backend_web:latest
command: bundle exec sidekiq -c 10
volumes:
- .:/usr/src/app
links:
- redis
env_file:
- .env
environment:
- REDIS_PROVIDER=REDIS_URL
- REDIS_URL=redis://redis@redis:6379/

db:
image: postgres:9.4

Expand Down

0 comments on commit 5f8996e

Please sign in to comment.