Skip to content

Instantly share code, notes, and snippets.

@vonconrad
Last active November 12, 2020 03:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vonconrad/a9d6cba18568b601b39cbdfaa11ae37d to your computer and use it in GitHub Desktop.
Save vonconrad/a9d6cba18568b601b39cbdfaa11ae37d to your computer and use it in GitHub Desktop.
class WeeklyAppointmentsProjector
include Projector
processes_events :appointment_scheduled,
:appointment_rescheduled,
:appointment_name_changed,
:appointment_canceled
table :weekly_appointments do
# ...
end
def project(event)
end
end
if event.type == :appointment_scheduled
table.insert(
year: event.body.start_time.year,
week_of_year: event.body.start_time.cweek,
appointment_id: event.aggregate_id,
appointment_name: event.body.name,
appointment_start_time: event.body.start_time,
appointment_end_time: event.body.end_time,
)
end
if event.type == :appointment_rescheduled
table
.where(appointment_id: event.aggregate_id)
.update(
year: event.body.start_time.year,
week_of_year: event.body.start_time.cweek,
appointment_start_time: event.body.start_time,
appointment_end_time: event.body.end_time,
)
end
if event.type == :appointment_canceled
table
.where(appointment_id: event.aggregate_id)
.delete
end
table.where(year: 2016, week_of_year: 13)
class AppointmentDetailProjector
include Projector
processes_events :appointment_scheduled,
:appointment_rescheduled,
:appointment_name_changed,
:appointment_location_moved,
:appointment_canceled
table :appointment_detail do
# ...
end
def project(event)
end
end
class InvitationSender
include DownstreamEventProcessor
processes_events :participant_invited
def process(event)
InvitationEmailer.deliver!(
email: event.body.participant_email
appointment_details: event.body.appointment_details
)
emit_event Event.new(
type: :invitation_sent,
aggregate_id: event.aggregate_id
)
end
end
def process_order
ActiveRecord::Base.transaction do
charge_credit_card
do_fraud_checks
save_order
generate_invoice
send_invoice
generate_shipping_label
send_shipping_label_to_warehouse
and_all_the_other_things
end
end
def process_order
ActiveRecord::Base.transaction do
charge_credit_card
do_fraud_checks
order = save_order
InvoiceGenerator.perform_async(order.id)
InvoiceSender.perform_async(order.id)
ShippingLabelGenerator.perform_async(order.id)
ShippingLabelDeliverer.perform_async(order.id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment