Skip to content

Instantly share code, notes, and snippets.

@rxbynerd
Created October 11, 2011 16:42
Show Gist options
  • Save rxbynerd/1278632 to your computer and use it in GitHub Desktop.
Save rxbynerd/1278632 to your computer and use it in GitHub Desktop.
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :title
t.text :body
end
end
end
require "active_record"
require "simple_worker"
Dir.glob("./models/*.rb").each{|r| require r}
Dir.glob("./migrations/*.rb").each{|r| require r}
Dir.glob("./workers/*.rb").each{|r| require r}
database = {
:adapter => "",
:host => "",
:port => 0,
:username => "",
:password => "",
:database => ""
}
SimpleWorker.configure do |config|
config.access_key = ENV['SW_ACCESS']
config.secret_key = ENV['SW_SECRET']
config.database = database
end
ActiveRecord::Base.establish_connection database
require "./environment"
@p = Post.all
puts "There are #{@p.count} posts"
@w = PostAdd.new
@w.queue
@w.wait_until_complete
@p = Post.all
puts "There are now #{@p.count} posts"
class Post < ActiveRecord::Base
end
class PostAdd < SimpleWorker::Base
merge_gem "active_record"
merge "./models/post"
def run
post = Post.new
post.title = "I love SimpleWorker"
post.body = "Just look how easy this is"
if post.save
log "save success!"
else
log "save fail!"
end
end
end
namespace :db do
desc "do active_record migrations"
task :migrate do
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Migration.verbose = true
ActiveRecord::Migrator.migrate("migrations")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment