Created
October 11, 2011 16:42
-
-
Save rxbynerd/1278632 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreatePosts < ActiveRecord::Migration | |
def change | |
create_table :posts do |t| | |
t.string :title | |
t.text :body | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post < ActiveRecord::Base | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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