Skip to content

Commit 8c97ac1

Browse files
committed
Merge pull request #134 from senny/rails_integration
better Rails integration
2 parents f53eb56 + 5c4db3c commit 8c97ac1

File tree

5 files changed

+48
-20
lines changed

5 files changed

+48
-20
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require 'rails/generators'
2+
require 'rails/generators/migration'
3+
require 'active_record'
4+
5+
module QC
6+
class InstallGenerator < Rails::Generators::Base
7+
include Rails::Generators::Migration
8+
9+
namespace "queue_classic:install"
10+
self.source_paths << File.join(File.dirname(__FILE__), 'templates')
11+
desc 'Generates (but does not run) a migration to add a queue_classic table.'
12+
13+
def self.next_migration_number(dirname)
14+
next_migration_number = current_migration_number(dirname) + 1
15+
ActiveRecord::Migration.next_migration_number(next_migration_number)
16+
end
17+
18+
def create_migration_file
19+
migration_template 'add_queue_classic.rb', 'db/migrate/add_queue_classic.rb'
20+
end
21+
end
22+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class AddQueueClassic < ActiveRecord::Migration
2+
def self.up
3+
QC::Setup.create
4+
end
5+
6+
def self.down
7+
QC::Setup.drop
8+
end
9+
end

lib/queue_classic.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,4 @@ def self.log(data)
8383
require "queue_classic/queue"
8484
require "queue_classic/worker"
8585
require "queue_classic/setup"
86+
require "queue_classic/railtie" if defined?(Rails)

lib/queue_classic/railtie.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'rails/railtie'
2+
3+
module QC
4+
class Railtie < ::Rails::Railtie
5+
rake_tasks do
6+
load 'queue_classic/tasks.rb'
7+
end
8+
end
9+
end

readme.md

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -132,35 +132,22 @@ source "http://rubygems.org"
132132
gem "queue_classic", "2.2.0"
133133
```
134134

135-
Require these files in your Rakefile so that you can run `rake qc:work`.
136-
137-
```ruby
138-
require "queue_classic"
139-
require "queue_classic/tasks"
140-
```
141-
142135
By default, queue_classic will use the QC_DATABASE_URL falling back on DATABASE_URL. The URL must be in the following format: `postgres://username:password@localhost/database_name`. If you use Heroku's PostgreSQL service, this will already be set. If you don't want to set this variable, you can set the connection in an initializer. **QueueClassic will maintain its own connection to the database.** This may double the number of connections to your database. Set QC::Conn.connection to share the connection between Rails & QueueClassic
143136

144137
```ruby
145138
require 'queue_classic'
146139
QC::Conn.connection = ActiveRecord::Base.connection.raw_connection
147140
```
148141

149-
**Note on using ActiveRecord migrations:** If you use the migration, and you wish to use commands that reset the database from the stored schema (e.g. `rake db:reset`), your application must be configured with `config.active_record.schema_format = :sql` in `config/application.rb`. If you don't do this, the PL/pgSQL function that queue_classic creates will be lost when you reset the database.
142+
Next you need to run the queue classic generator to create the database
143+
migration. This will setup the necessary table to use queue classic.
150144

151-
```ruby
152-
require 'queue_classic'
153-
154-
class AddQueueClassic < ActiveRecord::Migration
155-
def self.up
156-
QC::Setup.create
157-
end
158-
159-
def self.down
160-
QC::Setup.drop
161-
end
162-
end
163145
```
146+
rails generate queue_classic:install
147+
rake db:migrate
148+
```
149+
150+
**Note on using ActiveRecord migrations:** If you use the migration, and you wish to use commands that reset the database from the stored schema (e.g. `rake db:reset`), your application must be configured with `config.active_record.schema_format = :sql` in `config/application.rb`. If you don't do this, the PL/pgSQL function that queue_classic creates will be lost when you reset the database.
164151

165152
### Rake Task Setup
166153

0 commit comments

Comments
 (0)