Skip to content

Instantly share code, notes, and snippets.

View troex's full-sized avatar

Sergey B (Troex Nevelin) troex

View GitHub Profile
@Chocksy
Chocksy / kill_sidekiq_job.rb
Last active April 25, 2024 14:07
Kill sidekiq jobs by process id for busy jobs and by jid for other sets.
# FOR BUSY JOBS
# take the process_id from the /busy page in sidekiq and kill the longest running one.
workers = Sidekiq::Workers.new
long_process_id = 'integration.3:4:71111aaa111' # Eg: 'integration.3:4:71d1d7f4ef5a'
workers.each do |process_id, thread_id, work|
process = Sidekiq::Process.new('identity' => process_id)
process.stop! if process_id == long_process_id
end
# FOR SCHEDULED JOBS
@kfl62
kfl62 / mongoid_sort_habtm.rb
Last active October 3, 2015 01:38
HABTM relations return docs in the wrong order
class Some
include Mongoid::Document
field :some_field
has_and_belongs_to_many :habtms
def sorted_habtms
hbtm_ids.each_with_object([]){|id,a| h = habtms.find(id); a << h}
end
@troex
troex / unicorn.sh
Created April 4, 2011 20:57
Unicorn start/stop/restart script for Debian
#!/bin/sh
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs mysql
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: unicorn initscript
# Description: Unicorn is an HTTP server for Rack application
### END INIT INFO
@aaronvb
aaronvb / dj_recurring.rb
Created October 28, 2010 03:30
This will insert a job into the delayed_job queue outside of Ruby on Rails environment. Useful for recurring jobs using cron.
#!/usr/bin/env ruby
# put this somewhere in your project, ie: /lib
# use:
# crontab -e
# */30 * * * * /usr/bin/ruby /your_rails_project/lib/this_file.rb
# that will insert this job into your delayed_job queue every 30 minutes.
require 'rubygems'
require 'mysql'
@jamiew
jamiew / unicorn.rb
Created October 14, 2010 17:58 — forked from jimmysoho/gist:534668
Unicorn config for use with bundler and capistrano - fixes issues with environment pollution.rb
# My pimped out unicorn config, with incremental killof
# and all the latest capistrano & bundler-proofing
# @jamiew :: http://github.com/jamiew
application = "000000book.com"
environment = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'production'
app_path = "/srv/#{application}"
bundle_path = "#{app_path}/shared/bundle"
timeout 30