Skip to content

Commit

Permalink
Merge pull request #554 from bugsnag/example/better-rails-instructions
Browse files Browse the repository at this point in the history
Better Rails example instructions
  • Loading branch information
tomlongridge committed Aug 13, 2019
2 parents ab0fb88 + 24b4445 commit 66fe296
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 8 deletions.
6 changes: 3 additions & 3 deletions example/rails-51/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ../..
specs:
bugsnag (6.6.4)
bugsnag (6.11.1)
concurrent-ruby (~> 1.0)

GEM
Expand Down Expand Up @@ -101,7 +101,7 @@ GEM
pg (1.0.0)
public_suffix (3.0.2)
puma (3.11.2)
que (0.12.1)
que (0.14.3)
rack (2.0.4)
rack-protection (2.0.1)
rack
Expand Down Expand Up @@ -234,4 +234,4 @@ DEPENDENCIES
web-console (>= 3.3.0)

BUNDLED WITH
1.16.0
2.0.2
23 changes: 21 additions & 2 deletions example/rails-51/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,37 @@ Navigate to the `/sidekiq` page and run any of the examples using the links prov

The worker code can be found in `app/workers/sidekiq_workers.rb`.

To process the jobs, run Sidekiq using the following command:

```shell
bundle exec sidekiq
```

## Que in Rails

Que requires a database backend in order to queue jobs. By default this database will be PostgreSQL although this can be changed via options as detailed in [the que documentation](https://github.com/chanks/que).

Once PostgreSQL is set up as detailed using [the PostgreSQL documentation](https://www.postgresql.org/docs/), ensure Que can connect correctly before running and of the following examples. You may need to configure your connection in the `config/database.yml` file.
Once PostgreSQL is set up as detailed using [the PostgreSQL documentation](https://www.postgresql.org/docs/), ensure Que can connect correctly before running any of the following examples which reference a `quedb` that can be created with the following command:

```shell
createdb quedb
```

You can configure your connection in the `config/database.yml` file.

### Configuration

All tasks run with Que should set the rails environment to `que`. This ensures that the correct database and connection settings are used.
Do this by prepending `RAILS_ENV=que` before each command, or run:

```shell
export RAILS_ENV=que
```

Ensure that the initial Que setup is complete by running:

```shell
bundle exec bin/rake que:install
bundle exec bin/rails generate que:install
```

and
Expand Down
6 changes: 6 additions & 0 deletions example/rails-51/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000

que:
adapter: postgresql
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: localhost
timeout: 5000
database: quedb

development:
<<: *default
Expand Down
42 changes: 42 additions & 0 deletions example/rails-51/config/environments/que.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true

# Do not eager load code on boot. This avoids loading your whole application
# just for the purpose of running a single test. If you are using a tool that
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false

# Configure public file server for tests with Cache-Control for performance.
config.public_file_server.enabled = true
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}"
}

# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false

# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false

# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false
config.action_mailer.perform_caching = false

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test

# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr

# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end
3 changes: 3 additions & 0 deletions example/rails-51/config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ development:
test:
secret_key_base: 0b6d7f7e7eb96c729f3ebdd4b0868b8e3003ad8ebac8c4ce08f61d67b3184bca171364661988179c31e85e07b2d379bfb5f2d7570004805675432ae87811ad4a

que:
secret_key_base: 0b6d7f7e7eb96c729f3ebdd4b0868b8e3003ad8ebac8c4ce08f61d67b3184bca171364661988179c31e85e07b2d379bfb5f2d7570004805675432ae87811ad4a

# Do not keep production secrets in the unencrypted secrets file.
# Instead, either read values from the environment.
# Or, use `bin/rails secrets:setup` to configure encrypted secrets
Expand Down
4 changes: 1 addition & 3 deletions example/rails-51/config/sidekiq.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
---
:concurrency: 25
:pidfile: ./tmp/pids/sidekiq.pid
:logfile: ./log/sidekiq.log
:queues:
- default
:daemon: true
- default
2 changes: 2 additions & 0 deletions lib/bugsnag/integrations/que.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'que'

if defined?(::Que)
handler = proc do |error, job|
begin
Expand Down
9 changes: 9 additions & 0 deletions spec/integrations/que_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
@mocked_que = true
class ::Que
end
module Kernel
alias_method :old_require, :require
def require(path)
old_require(path) unless /^que/.match(path)
end
end
end
end

Expand Down Expand Up @@ -56,5 +62,8 @@ class ::Que

after do
Object.send(:remove_const, :Que) if @mocked_que
module Kernel
alias_method :require, :old_require
end
end
end

0 comments on commit 66fe296

Please sign in to comment.