This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class VCR::Client | |
def current_cassette | |
cassetes.last | |
end | |
def configure | |
yield configuration | |
end | |
def configuration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module VCR | |
extend self | |
def current_cassette | |
cassetes.last | |
end | |
def configure | |
yield configuration | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<title>NewName</title> | |
</head> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def save(*) | |
create_or_update | |
rescue ActiveRecord::RecordInvalid | |
false | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
subscribe "any_id_i_want", "bus_event_type" => "task_changed", "state" => "opened" do |attributes| | |
TaskIndex.write(attributes["id"]) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
subscribe "task_changed", "bus_event_type" => "task_changed" do |attributes| | |
if attributes["state"] == 'opened' | |
TaskIndex.write(attributes["id"]) | |
end | |
end |