Last active
February 22, 2016 18:52
-
-
Save myhrvold/20cc7b2c357aa94e679b to your computer and use it in GitHub Desktop.
Schemaless Triggers Example: Simplified Asynchronous Billing
This file contains 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
# We instantiate a client for talking with the Schemaless instance. | |
schemaless_client = SchemalessClient(datastore='mezzanine') | |
# We register the bill_rider function for the BASE column. | |
@trigger(column='BASE') | |
def bill_rider(row_key): | |
# row_key is the UUID of the trip | |
status = schemaless_client.get_cell_latest(row_key, 'STATUS') | |
if status.is_completed: | |
# This means we have already billed the rider. | |
return | |
# Otherwise we try to bill. | |
# We fetch the base trip information from the BASE column | |
trip_info = schemaless_client.get_cell_latest(row_key, 'BASE') | |
# We bill the the rider | |
result = call_to_credit_card_processor_for_billing_trip(trip_info) | |
if result != 'SUCCESS': | |
# By raising an exception we let Schemaless triggers retry later | |
raise CouldNotBillRider() | |
# We billed the rider successfully and write it back to Mezzanine | |
schemaless_client.put(row_key, status, body={'is_completed': True, 'result': result}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment