Skip to content

Instantly share code, notes, and snippets.

View bleonard's full-sized avatar

Brian Leonard bleonard

View GitHub Profile
subscribe "task_changed" do |attributes|
if attributes["state"] == 'opened'
TaskIndex.write(attributes["id"])
end
end
# initializer
ResqueBus.dispatch("app_b") do
subscribe "user_created" do |attributes|
# business logic
NameCount.find_or_create_by_name(attributes["last_name"]).increment!
end
end
# business logic
ResqueBus.publish("user_created", "id" => 42, "first_name" => "John", "last_name" => "Smith")
# or do it later
ResqueBus.publish_at(1.hour.from_now, "user_created", "id" => 42, "first_name" => "John", "last_name" => "Smith")
class Profile::ContentSubscriber
include ResqueBus::Subscriber
subscribe :post_rated
def post_rated(attributes)
total = Profile::Rate.where(author_id: attributes['author_id']).count
sum = Profile::Rate.where(author_id: attributes['author_id']).sum(:rating)
profile = Profile::Document.find_by(user_id: attributes['post_author_id'])
class Profile::ContentSubscriber
include ResqueBus::Subscriber
subscribe :post_created
def post_created(attributes)
profile = Profile::Document.find_by(user_id: attributes['post_author_id'])
profile.post_ratings_total = attributes['total_ratings']
profile.post_rating_average = attributes['new_average']
profile.save!
ResqueBus.dispatch('profile') do
subscribe 'post_rated' do |attributes|
profile = Profile::Document.find_by(user_id: attributes['author_id'])
profile.post_ratings_total = attributes['total_ratings']
profile.post_rating_average = attributes['new_average']
profile.save!
end
end
$ ENGINE_BOOT=am bundle exec rails c
=> will boot the account and marketing engines - but not content, admin, etc.
$ ENGINE_BOOT=-m bundle exec rails c
=> will boot all engines except marketing
# Gemfile
gemspec path: "apps/shared"
BootInquirer.each_active_app do |app|
gemspec path: "apps/#{app.gem_name}"
end
APPS = {
'a' => 'account',
'c' => 'content',
'm' => 'marketing',
'z' => 'admin'
}
describe Content::Post do
fixtures :users
it "should be associated with a user" do
user = fixture(:users, :willy, Content)
post = Content::Post.new(content: "words")
post.user = user
post.save.should == true
user.posts.count.should == 1
end