Skip to content

Instantly share code, notes, and snippets.

@myhrvold
Last active February 22, 2016 18:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myhrvold/20cc7b2c357aa94e679b to your computer and use it in GitHub Desktop.
Save myhrvold/20cc7b2c357aa94e679b to your computer and use it in GitHub Desktop.
Schemaless Triggers Example: Simplified Asynchronous Billing
# 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