Skip to content

Instantly share code, notes, and snippets.

class CreateDelayedJobGroups < ActiveRecord::Migration
def up
add_column(:delayed_jobs, :blocked, :boolean, default: false, null: false)
add_column(:delayed_jobs, :job_group_id, :integer)
add_index(:delayed_jobs, :job_group_id)
remove_index(:delayed_jobs, name: :delayed_jobs_priority)
execute <<-SQL
CREATE INDEX delayed_jobs_priority
config.jobs = ActiveSupport::OrderedOptions.new
# Controls whether or not workers report heartbeats
config.jobs.heartbeat_enabled = true
# How often workers should send heartbeats
config.jobs.heartbeat_interval_seconds = 60
# How long a worker can go without sending a heartbeat before they're considered dead
config.jobs.heartbeat_timeout_seconds = 3 * 60
# How often to check for dead workers
config.jobs.dead_worker_polling_interval_seconds = 60
CREATE VIEW product_stats AS
SELECT organization_id,
SUM(CASE WHEN status = 'active' THEN 1 END) active_count,
SUM(CASE WHEN status = 'inactive' THEN 1 END) inactive_count
FROM products
GROUP BY organization_id
@jturkel
jturkel / Gemfile
Last active August 29, 2015 13:56
group :test do
gem 'atomic'
end
> blogs = Blogs.limit(5).to_a
# SELECT * FROM blogs LIMIT 5
> blogs.each { |blog| blog.posts.to_a }
# SELECT * FROM posts WHERE blog_id IN (1,2,3,4,5)
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '4.1.7' # Works with '4.0.11'
gem 'closure_tree'
gem 'sqlite3'
GEMFILE
system 'bundle'
end