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 HardWorker | |
| include TResque::Worker | |
| inputs :name, :count | |
| def work | |
| # do something with self.name, self.count | |
| end | |
| end | |
| # enqueue |
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 HardWorker | |
| include Sidekiq::Worker | |
| def perform(name, count) | |
| # do something with name, count | |
| end | |
| end | |
| # enqueue | |
| HardWorker.perform_async('bob', 5) |
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
| # Whenever the user changes | |
| subscribe 'user_may_have_changed', bus_observer_touched: 'user' do |attributes| | |
| # update the profile in ElasticSearch | |
| ProfileStoreWorker.enqueue(user_id: 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
| class JobsController < ApplicationController | |
| def confirm | |
| @job = Job.find(params[:id]) | |
| authorize @job, :confirm? # authorization | |
| op = Organic::JobConfirmOp.new(current_user) | |
| op.submit!(params.merge(job_id: @job.id)) # perform action | |
| render :show # render template | |
| end | |
| 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 InvoiceJobOp < ::Backend::Op | |
| include Mixins::AtomicOperation # all in same transaction | |
| field :hours | |
| field :job_id | |
| validates :job_id, presence: true | |
| validate :validate_hour # hours given | |
| validate :validate_assignment # tasker is assigned | |
| # ... other checks |
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> |