Skip to content

Instantly share code, notes, and snippets.

@bleonard
Created March 5, 2017 22:10
Show Gist options
  • Select an option

  • Save bleonard/d9d80c8a2f9dc894d506e0d4dc3f08d4 to your computer and use it in GitHub Desktop.

Select an option

Save bleonard/d9d80c8a2f9dc894d506e0d4dc3f08d4 to your computer and use it in GitHub Desktop.
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
def perform
create_invoice! # record hours and such
generate_payment! # pending payment transaction
appointment_done! # note that appointment completed
if ongoing?
schedule_next_appointment! # schedule next if more
else
complete_assignment! # otherwise, no more
end
enqueue_background_workers! # follow up later on stuff
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment