Skip to content

Instantly share code, notes, and snippets.

View bleonard's full-sized avatar

Brian Leonard bleonard

View GitHub Profile
class Main
def process_all
mutex = Mutex.new
queue = self.paths.dup
self.thread_count.times.map {
Thread.new do
while path = mutex.synchronize { queue.pop }
fetcher = ThreadedFetcher.new(path)
fetcher.fetch!
class Fetcher
def initialize(path)
@path = path
end
def fetch!
VCR.use_cassette('#{@path}/fetched') do
response = Net::HTTP.get_response(URI("api.http://example.com/#{@path}"))
process(response)
end
class VCR::Client
def current_cassette
cassetes.last
end
def configure
yield configuration
end
def configuration
module VCR
extend self
def current_cassette
cassetes.last
end
def configure
yield configuration
end
<head>
<title>NewName</title>
</head>
class Task < ActiveRecord::Base
after_save :sync_with_external
def sync_with_external
response = External.sync!(id: self.id, info: self.info)
if response.error?
self.errors.add(:base, "There was a problem, etc ...")
raise ActiveRecord::RecordInvalid.new(self)
end
true # I still do this out of superstition
def save(*)
create_or_update
rescue ActiveRecord::RecordInvalid
false
end
class TaskChangesSubscriber
include ResqueBus::Subscriber
subscribe :task_changed
subscribe :changed_when_opened, "bus_event_type" => "task_changed", "state" => "opened"
def task_changed(attributes)
# gets called for all task changes
end
def changed_when_opened
subscribe "any_id_i_want", "bus_event_type" => "task_changed", "state" => "opened" do |attributes|
TaskIndex.write(attributes["id"])
end
subscribe "task_changed", "bus_event_type" => "task_changed" do |attributes|
if attributes["state"] == 'opened'
TaskIndex.write(attributes["id"])
end
end