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 InvoiceChargeWorker | |
include TResque::Worker | |
inputs :invoice_id | |
worker_lock :to_id | |
def work | |
return unless needed? | |
invoice.charge! | |
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 UserIndexWorker | |
include TResque::Worker | |
inputs :user_id | |
queue_lock :user_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 InvoiceChargeWorker | |
include TResque::Worker | |
inputs :invoice_id | |
def work | |
return unless needed? | |
invoice.charge! | |
end | |
def needed? |
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 UserIndexWorker | |
include TResque::Worker | |
inputs :user_id | |
def work | |
Elasticsearch.index('users').write(user.attributes.slice(:id, :first_name, :last_name, :etc)) | |
end | |
def user | |
@user ||= User.find(user_id) |
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 UserIndexWorker | |
include TResque::Worker | |
inputs :id, :first_name, :last_name, :etc | |
def work | |
Elasticsearch.index('users').write(id, id: id, first_name: first_name, last_name: last_name, etc: etc) | |
end | |
end | |
# When user changes |
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 |