Created
September 13, 2013 17:40
-
-
Save dvdasari/6553768 to your computer and use it in GitHub Desktop.
This file contains 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
lib/tasks/act_celluloid.rake | |
namespace :act_celluloid do | |
task :crawl => :environment do | |
app_ids = get_items | |
supervisor = Celluloid::SupervisionGroup.run! | |
supervisor.pool(AppActor, as: :app_actors, size: 10) | |
futures = [] | |
app_ids.each do |app_id| | |
futures << Celluloid::Actor[:app_actors].future.get_project(project_id, 'us') | |
end | |
futures.each do |future| | |
puts "future.value = #{future.value}" | |
end | |
end | |
end | |
lib/celloid_actors.rb | |
class AppActor | |
include Celluloid | |
def get_project(project_id, region) | |
project = Project.find(project_id) | |
project.get_data | |
end | |
end | |
app/models/project.rb | |
class Project < ActiveRecord::Base | |
def get_data | |
begin | |
data = ProjectParser.new(project_id) | |
rescue Exception => e | |
puts "In Exception => #{e}" | |
end | |
end | |
end | |
app/models/project_parser.rb | |
class ProjectParser | |
def initialize(project_id) | |
# some processing | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment