Skip to content

Instantly share code, notes, and snippets.

View Diasporism's full-sized avatar

Logan Sears Diasporism

View GitHub Profile
@Diasporism
Diasporism / redis_and_resque.mkd
Last active March 13, 2024 08:37
How to configure Redis and Resque for your Rails app.

Redis and Resque

What this guide will cover: the code you will need in order to include Redis and Resque in your Rails app, and the process of creating a background job with Resque.

What this guide will not cover: installing Ruby, Rails, or Redis.

Note: As of this writing I am still using Ruby 1.9.3p374, Rails 3.2.13, Redis 2.6.11, and Resque 1.24.1. I use SQLite in development and Postgres in production.

Background jobs are frustrating if you've never dealt with them before. Over the past few weeks I've had to incorporate Redis and Resque into my projects in various ways and every bit of progress I made was very painful. There are many 'gotchas' when it comes to background workers, and documentation tends to be outdated or scattered at best.

@Diasporism
Diasporism / Merchant.most_revenue(x).rb
Last active December 13, 2015 20:49
These are all the methods that we use in order to return the top x merchants by revenue. It seems ugly and it's spread out between 3 or so classes. Also, we aren't sure how to handle converting total revenue and money into a BigDecimal. We just end up with a number like 0.237864E7637 instead of a readable number. Any thoughts on how we can impro…
#First method starts in the Merchant class
def self.most_revenue(rank)
if rank == 0
rank = 1
end
Transaction.get_successful_transaction
@merchant_revenues_array[0..(rank - 1)]
end