Skip to content

Commit

Permalink
* Added 'backgroundrb:queue_migration' rake task, to run the queue mi…
Browse files Browse the repository at this point in the history
…gration

  generator.

* Modified the 'backgroundrb:setup' task to run the migration generator
  instead of directly creating the queue table.
  • Loading branch information
Seth Morabito committed Sep 12, 2008
1 parent 3c04fbc commit 45029fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 48 deletions.
2 changes: 1 addition & 1 deletion generators/bdrb_migration/bdrb_migration_generator.rb
@@ -1,6 +1,6 @@
class BdrbMigrationGenerator < Rails::Generator::NamedBase
def initialize(runtime_args, runtime_options = {})
runtime_args << 'add_bdrb_job_queue_table' if runtime_args.empty?
runtime_args << 'CreateBackgroundrbQueueTable' if runtime_args.empty?
super
end

Expand Down
58 changes: 11 additions & 47 deletions tasks/backgroundrb_tasks.rake
@@ -1,41 +1,4 @@
namespace :backgroundrb do
def setup_queue_migration
config_file = "#{RAILS_ROOT}/config/database.yml"
require "erb"
require "active_record"
config = YAML.load(ERB.new(IO.read(config_file)).result)
env = ENV["RAILS_ENV"] || ENV["env"] || 'development'

ActiveRecord::Base.establish_connection(config[env])
migration_klass = Class.new(ActiveRecord::Migration) do
def self.up
create_table :bdrb_job_queues do |t|
t.column :args, :binary
t.column :worker_name, :string
t.column :worker_method, :string
t.column :job_key, :string
t.column :taken, :int
t.column :finished, :int
t.column :timeout, :int
t.column :priority, :int
t.column :submitted_at, :datetime
t.column :started_at, :datetime
t.column :finished_at, :datetime
t.column :archived_at, :datetime
t.column :tag, :string
t.column :submitter_info, :string
t.column :runner_info, :string
t.column :worker_key, :string
end
end

def self.down
drop_table :bdrb_job_queues
end
end
migration_klass.up
end

require 'yaml'
desc 'Setup backgroundrb in your rails application'
task :setup do
Expand Down Expand Up @@ -77,17 +40,9 @@ namespace :backgroundrb do
puts "Copying Worker envionment loader file #{worker_env_loader_dest}"
FileUtils.cp_r(worker_env_loader_src,worker_env_loader_dest)
end
begin
setup_queue_migration
rescue
error_msg = $!.message
puts error_msg.first(85)
end
end

desc "Create backgroundrb queue table"
task :create_queue do
setup_queue_migration
# Generate the migration
Rake::Task['backgroundrb:queue_migration'].invoke
end

desc 'update backgroundrb config files from your rails application'
Expand All @@ -106,6 +61,15 @@ namespace :backgroundrb do
end
end

desc 'Generate a migration for the backgroundrb queue table. The migration name can be ' +
'specified with the MIGRATION environment variable.'
task :queue_migration => :environment do
raise "Task unavailable to this database (no migration support)" unless ActiveRecord::Base.connection.supports_migrations?
require 'rails_generator'
require 'rails_generator/scripts/generate'
Rails::Generator::Scripts::Generate.new.run(['bdrb_migration', ENV['MIGRATION'] || 'CreateBackgroundrbQueueTable'])
end

desc 'Remove backgroundrb from your rails application'
task :remove do
script_src = "#{RAILS_ROOT}/script/backgroundrb"
Expand Down

0 comments on commit 45029fc

Please sign in to comment.