Skip to content
Browse files

Merge branch 'master' of git://github.com/sethm/backgroundrb

  • Loading branch information...
2 parents b995dff + 5438cc0 commit dc16a41358e3ff774ee61212718432bc1c0446ac @gnufied gnufied committed
View
12 generators/bdrb_migration/USAGE
@@ -0,0 +1,12 @@
+Description:
+ Creates a migration to add the job queue table used by BackgrounDRb.
+ Pass the migration name, either CamelCased or under_scored, as an argument.
+
+Example:
+ ./script/generate bdrb_migration CreateBackgroundrbQueue
+
+ Assuming this is run at 09:00:15h on 12 September, 2008, this will create the
+ CreateBackgroundrbQueue migration in:
+
+ db/migrate/20080912090015_create_backgroundrb_queue.rb
+
View
19 generators/bdrb_migration/bdrb_migration_generator.rb
@@ -0,0 +1,19 @@
+class BdrbMigrationGenerator < Rails::Generator::NamedBase
+ def initialize(runtime_args, runtime_options = {})
+ runtime_args << 'CreateBackgroundrbQueueTable' if runtime_args.empty?
+ super
+ end
+
+ def manifest
+ record do |m|
+ m.migration_template 'migration.rb', 'db/migrate',
+ :assigns => { :bdrb_table_name => default_bdrb_table_name }
+ end
+ end
+
+ protected
+
+ def default_bdrb_table_name
+ ActiveRecord::Base.pluralize_table_names ? 'bdrb_job_queue'.pluralize : 'bdrb_job_queue'
+ end
+end
View
26 generators/bdrb_migration/templates/migration.rb
@@ -0,0 +1,26 @@
+class <%= class_name %> < ActiveRecord::Migration
+ def self.up
+ create_table :<%= bdrb_table_name %> 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_table_name %>
+ end
+end
View
69 tasks/backgroundrb_tasks.rake
@@ -1,52 +1,4 @@
namespace :backgroundrb do
- def generate_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 :scheduled_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
- end
-
- def setup_queue_migration
- generate_queue_migration.up
- end
-
- def redo_queue_migration
- klass = generate_queue_migration
- klass.down
- klass.up
- end
-
require 'yaml'
desc 'Setup backgroundrb in your rails application'
task :setup do
@@ -88,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 "Drops and recreate backgroundrb queue table"
@@ -122,6 +66,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"

0 comments on commit dc16a41

Please sign in to comment.
Something went wrong with that request. Please try again.