Forum: Ruby Sugestion - Background process

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Marcelo J. (Guest)
on 2008-10-21 20:04
Before reply Backgroundrb, leaves to explain my situation. I need make a
feed reader, and obvious, she need refreshing the feeds registreds.
Everything is running smoothly, and for to make the updater, I used
Backgroundrb. But, I can not more than one process of Backgroundrb. I'm
doing the following.

WORKER

class RefreshWorker < BackgrounDRb::MetaWorker
  set_worker_name :refresh_worker
  def create(args = nil)
    logger.info "==========================================="
    logger.info "=           FEEDEEDO REFRESH              ="
    logger.info "==========================================="
    logger.info "por Marcelo I. Machado Junior"

    refresh
  end

  def refresh
      blogs = Blog.find(:all)
      blogs.each do |blog|
        logger.info "#{Time.now.strftime('%d/%m/%y %H:%M:%S')} -
#{blog.title}"
  blog.refresh
      end
      logger.info "#{blogs.size} blogs atualizados"
      refresh
  end


And the class Blog, I have the following:

  def refresh
    begin
        feed = FeedParser.new(self.link)
        self.title = feed.title
        self.description = feed.subtitle.html2text if feed.subtitle
       #b.publication = feed.publication || Time.now

        #É percorrido cada item do feed e cadastrado no banco

        feed.items.each do |item|
          bi = BlogItem.create() do |i|
            i.link = item.link
            i.title = item.title
            i.description = item.content.html2text
            i.indexed_content =
Blog.prepare_content(item.content.html2text)
            i.indexed_title = Blog.prepare_content(item.title || '')
            #i.publication = item.publication || Time.now
          end
          self.blog_items << bi
        end
    self.save
      true
    rescue
      retry
    end
  end

end

But I want more instances, who knows, for a blog.
Hemant K. (Guest)
on 2008-10-21 23:29
(Received via mailing list)
On Tue, Oct 21, 2008 at 9:33 PM, Marcelo J.
<removed_email_address@domain.invalid> wrote:
>  def create(args = nil)
>      blogs.each do |blog|
>
>          bi = BlogItem.create() do |i|
>    self.save
>      true
>    rescue
>      retry
>    end
>  end
>
> end
>
> But I want more instances, who knows, for a blog.

You have two options:

1. Use MiddleMan.new_worker() to create more than one instance of your
worker. Specifics I leave it to you.
2. Make feed fetching threaded in worker, using inbuilt thread pool.
This topic is locked and can not be replied to.