From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: * X-Spam-ASN: AS33070 50.56.128.0/17 X-Spam-Status: No, score=1.0 required=3.0 tests=AWL,HK_RANDOM_FROM, MSGID_FROM_MTA_HEADER,TVD_RCVD_IP shortcircuit=no autolearn=no version=3.3.2 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.lang.ruby.rainbows.general Subject: Re: background threads Date: Mon, 18 Jun 2012 14:55:50 -0700 Message-ID: <20120618215550.GA31162@dcvr.yhbt.net> References: <4FDF7420.7030300@objectdata.com.br> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1340056558 30152 80.91.229.3 (18 Jun 2012 21:55:58 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 18 Jun 2012 21:55:58 +0000 (UTC) Cc: Alexandre Riveira To: Rainbows! list Original-X-From: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Mon Jun 18 23:55:57 2012 Return-path: Envelope-to: gclrrg-rainbows-talk@m.gmane.org X-Original-To: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Delivered-To: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Content-Disposition: inline In-Reply-To: <4FDF7420.7030300-VwDbj2YsoUp0ZRtCdD4y8VAUjnlXr6A1@public.gmane.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Errors-To: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Xref: news.gmane.org gmane.comp.lang.ruby.rainbows.general:360 Archived-At: Received: from 50-56-192-79.static.cloud-ips.com ([50.56.192.79] helo=rubyforge.org) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SgjvQ-0003bj-J7 for gclrrg-rainbows-talk@m.gmane.org; Mon, 18 Jun 2012 23:55:56 +0200 Received: from localhost.localdomain (localhost [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id DBE112E06B; Mon, 18 Jun 2012 21:55:55 +0000 (UTC) Received: from dcvr.yhbt.net (dcvr.yhbt.net [64.71.152.64]) by rubyforge.org (Postfix) with ESMTP id DF2232E06B for ; Mon, 18 Jun 2012 21:55:51 +0000 (UTC) Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id EAE913EFEF; Mon, 18 Jun 2012 21:55:50 +0000 (UTC) Alexandre Riveira wrote: > Hello ! > > I'm trying to put in background threads in Rainbows. I created a > config/initializers/background_thread.rb, where I > > Thread.new do > # my background job > end > > With that, I have problems to "reload" in rainbows What kind of problems? Is preload_app true or false? (default is false) preload_app being true will cause that background thread to get started in the master process and not the workers. You can workaround it by starting th background thread in an after_fork hook in the Rainbows!/unicorn config file: http://unicorn.bogomips.org/Unicorn/Configurator.html#method-i-after_fork > Thank you all for your help. I'm often lazy when it comes to setting up hooks myself :x So for background threads, I prefer to start it in the app stack on the first request (use a mutex to protect against double-starts). For rails, you can probably do it in a before_filter. Raindrops::Watcher is a Rack app (no other framework, just rack) which starts a background thread in the #call method: git clone git://bogomips.org/raindrops raindrops cat raindrops/lib/watcher.rb _______________________________________________ Rainbows! mailing list - rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org http://rubyforge.org/mailman/listinfo/rainbows-talk Do not quote signatures (like this one) or top post when replying