<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>delayed_job resque on random thoughts</title><link>https://awesomeprogrammer.com/categories/delayed_job-resque/</link><description>Recent content in delayed_job resque on random thoughts</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sun, 30 Jun 2013 00:00:00 +0000</lastBuildDate><atom:link href="https://awesomeprogrammer.com/categories/delayed_job-resque/index.xml" rel="self" type="application/rss+xml"/><item><title>Delayed::Job to Resque migration</title><link>https://awesomeprogrammer.com/blog/2013/06/30/delayed-job-to-resque-migration/</link><pubDate>Sun, 30 Jun 2013 00:00:00 +0000</pubDate><guid>https://awesomeprogrammer.com/blog/2013/06/30/delayed-job-to-resque-migration/</guid><description><![CDATA[<p>When it comes to doing some asynchronous work, Ruby on Rails community have some great ready to use solutions to choose from. I think most popular is <a href="https://github.com/collectiveidea/delayed_job">delayed_job</a> and <a href="https://github.com/resque/resque">resque</a> (and probably sidekiq, but a story for another blog post).</p>
<p>Delayed Job is great for small apps, it&rsquo;s work out-of-the-box with ActiveRecord, you can also plug it into mongoid and it&rsquo;s probably your first choice if you don&rsquo;t want to setup redis. But when your traffic gets higher and higher, and you have to do more background jobs it&rsquo;s becoming clear it&rsquo;s not the perfect solution - the database-lock mechanism just don&rsquo;t play very well with high amount of tasks.</p>
<p>Migrating to resque shouldn&rsquo;t be a big problem (well, I guess it&rsquo;s vary greatly, depending of you app specifics), I will provide here some quick tips, as usual:</p>
<!-- raw HTML omitted -->
<ul>
<li>
<p>configuring <a href="http://redis.io/">redis</a> isn&rsquo;t so complicated as it seems, <a href="https://raw.github.com/antirez/redis/2.6/redis.conf">provided example</a> (I recommend sticking to current branch 2.6) is very well documented and should be self-explanatory</p>
</li>
<li>
<p>keep in mind that job arguments are JSON encoded, so all hashes will became strings</p>
</li>
<li>
<p>converting jobs structure and enqueue calls should also be straight-forward, if you have some heavily customized jobs take a look at <a href="https://github.com/resque/resque/blob/master/docs/HOOKS.md">hooks that resque has to offer</a> - they are quite similar to the ones from delayed_job, so you shouldn&rsquo;t have much of a problem converting those</p>
</li>
<li>
<p>you can replace <a href="https://github.com/ejschmitt/delayed_job_web">delayed_job_web</a> with built-in resque back-end. Just add to your routes:</p>
</li>
</ul>
<p>{% codeblock config/routes.rb %}
mount Resque::Server, :at =&gt; &ldquo;/resque&rdquo;
{% endcodeblock %}</p>
<p>You will probably want to protect it with some kind of password using initializer:</p>
<p>{% codeblock config/initializers/resque.rb %}
unless Rails.env.development?
Resque::Server.use Rack::Auth::Basic do |user, password|
user == &rsquo;login&rsquo; &amp;&amp; password == &lsquo;password&rsquo;
end
end
{% endcodeblock %}</p>
<ul>
<li>
<p>if you need some simple capistrano integration - take a look at <a href="https://github.com/sshingler/capistrano-resque">capistrano-resque</a></p>
</li>
<li>
<p>I also recommend checking out <a href="https://github.com/bvandenbos/resque-scheduler">resque-scheduler</a>, especially if you have a lot of tasks scheduled in you crontab - moving them to your app repository should make it a little bit more clear what&rsquo;s really going on</p>
</li>
</ul>
<p>And one final note - resque 2.0 is currently heavy development, you you might want to stick to <a href="https://github.com/resque/resque/tree/1-x-stable">1-x-stable</a> branch.</p>]]></description><content:encoded><![CDATA[<p>When it comes to doing some asynchronous work, Ruby on Rails community have some great ready to use solutions to choose from. I think most popular is <a href="https://github.com/collectiveidea/delayed_job">delayed_job</a> and <a href="https://github.com/resque/resque">resque</a> (and probably sidekiq, but a story for another blog post).</p>
<p>Delayed Job is great for small apps, it&rsquo;s work out-of-the-box with ActiveRecord, you can also plug it into mongoid and it&rsquo;s probably your first choice if you don&rsquo;t want to setup redis. But when your traffic gets higher and higher, and you have to do more background jobs it&rsquo;s becoming clear it&rsquo;s not the perfect solution - the database-lock mechanism just don&rsquo;t play very well with high amount of tasks.</p>
<p>Migrating to resque shouldn&rsquo;t be a big problem (well, I guess it&rsquo;s vary greatly, depending of you app specifics), I will provide here some quick tips, as usual:</p>
<!-- raw HTML omitted -->
<ul>
<li>
<p>configuring <a href="http://redis.io/">redis</a> isn&rsquo;t so complicated as it seems, <a href="https://raw.github.com/antirez/redis/2.6/redis.conf">provided example</a> (I recommend sticking to current branch 2.6) is very well documented and should be self-explanatory</p>
</li>
<li>
<p>keep in mind that job arguments are JSON encoded, so all hashes will became strings</p>
</li>
<li>
<p>converting jobs structure and enqueue calls should also be straight-forward, if you have some heavily customized jobs take a look at <a href="https://github.com/resque/resque/blob/master/docs/HOOKS.md">hooks that resque has to offer</a> - they are quite similar to the ones from delayed_job, so you shouldn&rsquo;t have much of a problem converting those</p>
</li>
<li>
<p>you can replace <a href="https://github.com/ejschmitt/delayed_job_web">delayed_job_web</a> with built-in resque back-end. Just add to your routes:</p>
</li>
</ul>
<p>{% codeblock config/routes.rb %}
mount Resque::Server, :at =&gt; &ldquo;/resque&rdquo;
{% endcodeblock %}</p>
<p>You will probably want to protect it with some kind of password using initializer:</p>
<p>{% codeblock config/initializers/resque.rb %}
unless Rails.env.development?
Resque::Server.use Rack::Auth::Basic do |user, password|
user == &rsquo;login&rsquo; &amp;&amp; password == &lsquo;password&rsquo;
end
end
{% endcodeblock %}</p>
<ul>
<li>
<p>if you need some simple capistrano integration - take a look at <a href="https://github.com/sshingler/capistrano-resque">capistrano-resque</a></p>
</li>
<li>
<p>I also recommend checking out <a href="https://github.com/bvandenbos/resque-scheduler">resque-scheduler</a>, especially if you have a lot of tasks scheduled in you crontab - moving them to your app repository should make it a little bit more clear what&rsquo;s really going on</p>
</li>
</ul>
<p>And one final note - resque 2.0 is currently heavy development, you you might want to stick to <a href="https://github.com/resque/resque/tree/1-x-stable">1-x-stable</a> branch.</p>]]></content:encoded></item></channel></rss>