Skip to content

Commit

Permalink
Moved que example into rails
Browse files Browse the repository at this point in the history
  • Loading branch information
Cawllec committed Mar 1, 2018
1 parent c73bb96 commit 6c31c27
Show file tree
Hide file tree
Showing 22 changed files with 107 additions and 187 deletions.
7 changes: 0 additions & 7 deletions example/que/Gemfile

This file was deleted.

41 changes: 0 additions & 41 deletions example/que/Gemfile.lock

This file was deleted.

45 changes: 0 additions & 45 deletions example/que/README.md

This file was deleted.

37 changes: 0 additions & 37 deletions example/que/Rakefile

This file was deleted.

25 changes: 0 additions & 25 deletions example/que/app/jobs.rb

This file was deleted.

15 changes: 0 additions & 15 deletions example/que/app/migrations.rb

This file was deleted.

8 changes: 0 additions & 8 deletions example/que/app/model.rb

This file was deleted.

4 changes: 3 additions & 1 deletion example/rails-51/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ gem "resque"

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.4'
# Use sqlite3 as the database for Active Record
# Use sqlite3 and pg as the database for Active Record
gem 'sqlite3'
gem 'pg'

# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
Expand Down
4 changes: 3 additions & 1 deletion example/rails-51/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ GEM
nio4r (2.2.0)
nokogiri (1.8.2)
mini_portile2 (~> 2.3.0)
pg (1.0.0)
public_suffix (3.0.2)
puma (3.11.2)
que (0.14.2)
que (0.12.1)
rack (2.0.4)
rack-protection (2.0.1)
rack
Expand Down Expand Up @@ -215,6 +216,7 @@ DEPENDENCIES
coffee-rails (~> 4.2)
jbuilder (~> 2.5)
listen (>= 3.0.5, < 3.2)
pg
puma (~> 3.7)
que
rails (~> 5.1.4)
Expand Down
31 changes: 31 additions & 0 deletions example/rails-51/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,37 @@ The worker code can be found in `app/workers/sidekiq_workers.rb`.

## 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.

### Configuration

Ensure that the initial Que setup is complete by running:

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

and

```shell
bundle exec bin/rake db:migrate
```

Further configuration will be taken from the Rails environment.

### Running the examples

Start the Rails server as mentioned above.

Navigate to the `/que` page and queue jobs for any of the examples using links provided.

To process the jobs, run Que using the cli command:

```shell
bundle exec que ./config/environment.rb
```

## Resque in Rails

Expand Down
19 changes: 19 additions & 0 deletions example/rails-51/app/controllers/que_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require './app/jobs/que_crash'

class QueController < ActionController::Base
protect_from_forgery with: :exception

def index
@text = File.read(File.expand_path('app/views/que.md'))
end

def crash
QueCrash.enqueue
@text = "Que has queued the crash task"
end

def callbacks
QueCallback.enqueue
@text = "Que has queued the callbacks task"
end
end
14 changes: 14 additions & 0 deletions example/rails-51/app/jobs/que_callback.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class QueCallback < Que::Job
@run_at = proc { 5.seconds.from_now }

def run(options={})
Bugsnag.before_notify_callbacks << proc { |report|
new_tab = {
message: 'Que demo says: Everything is great',
code: 200
}
report.add_tab(:diagnostics, new_tab)
}
raise "Oh no"
end
end
7 changes: 7 additions & 0 deletions example/rails-51/app/jobs/que_crash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class QueCrash < Que::Job
@run_at = proc { 5.seconds.from_now }

def run(options={})
raise "Oh no"
end
end
15 changes: 15 additions & 0 deletions example/rails-51/app/views/que.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Bugsnag Que demo

This route demonstrates how to use Bugsnag with Que.

While testing the examples open [your dashboard](https://app.bugsnag.com) in order to see the example errors and exceptions being received.

Make sure you have a PostgreSQL instance running that your test application can connect to before running these examples.

1. [Crash](/que/crash)
<br/>
Raises an error within the framework, generating a report in the Bugsnag dashboard.

2. [Crash and use callbacks](/que/crash_with_callback)
<br/>
Raises an exception within the framework, but with additional data attached to the report. By registering a callback before the error occurs useful data can be attached as a tab in the Bugsnag dashboard.
1 change: 1 addition & 0 deletions example/rails-51/app/views/que/callbacks.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= markdown(@text)%>
1 change: 1 addition & 0 deletions example/rails-51/app/views/que/crash.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= markdown(@text)%>
1 change: 1 addition & 0 deletions example/rails-51/app/views/que/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= markdown(@text)%>
1 change: 1 addition & 0 deletions example/rails-51/app/views/que/metadata.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= markdown(@text)%>
2 changes: 1 addition & 1 deletion example/rails-51/app/views/resque.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ QUEUE=crash,callback,metadata bundle exec rake resque:work

3. [Notify with data](/resque/notify_data)
<br/>
Same as `notify` but allows you to attach additional data within a `block`, similar to the `before_notify_callbacks` example above. In this case we're adding information about the user to go into the `user` tab, and additional diagnostics as a `diagnostics` tab.
Same as `notify` but allows you to attach additional data within a `block`, similar to the `before_notify_callbacks` example above. In this case we're adding information about the queue to go into the `queue` tab, and additional diagnostics as a `diagnostics` tab.
2 changes: 1 addition & 1 deletion example/rails-51/app/views/sidekiq.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ Make sure you have a Redis instance running that your test application can conne

3. [Notify with data](/sidekiq/notify_data)
<br/>
Same as `notify` but allows you to attach additional data within a `block`, similar to the `before_notify_callbacks` example above. In this case we're adding information about the user to go into the `user` tab, and additional diagnostics as a `diagnostics` tab.
Same as `notify` but allows you to attach additional data within a `block`, similar to the `before_notify_callbacks` example above. In this case we're adding information about the function being called to go into the `function` tab, and additional diagnostics as a `diagnostics` tab.
9 changes: 5 additions & 4 deletions example/rails-51/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
adapter: postgresql
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: localhost
timeout: 5000

development:
<<: *default
database: db/development.sqlite3
database: default

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
database: default

production:
<<: *default
database: db/production.sqlite3
database: default
5 changes: 4 additions & 1 deletion example/rails-51/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
get '/sidekiq/crash_with_callback', to: 'sidekiq#callbacks'

# Que routing
get '/que', to: 'que#index'
get '/que/crash', to: 'que#crash'
get '/que/notify_data', to: 'que#metadata'
get '/que/crash_with_callback', to: 'que#callbacks'

# Resque routing
get '/resque', to: 'resque#index'
get '/resque/crash', to: 'resque#crash'
get '/resque/notify_data', to: 'resque#metadata'
get '/resque/crash_with_callback', to: 'resque#callbacks'
end

0 comments on commit 6c31c27

Please sign in to comment.