Skip to content

Instantly share code, notes, and snippets.

@andersonvom
Last active August 29, 2015 14:06
Show Gist options
  • Save andersonvom/02a2c84447fcc522f651 to your computer and use it in GitHub Desktop.
Save andersonvom/02a2c84447fcc522f651 to your computer and use it in GitHub Desktop.
@APP.task(base=ErrorHandler)
def calc_mrr():
mrr_chord = chord(
chain(get_resources.s(key), calc_revenue.s())
for key in mrr_stacks
)
return mrr_chord(mrr_total.s()) # mrr_total receives a list of AsyncResult
# but I need the actual results (the output of calc_revenue,
# which is the values returned by _sum_revenues)
@APP.task(base=ErrorHandler, ignore_result=False)
def get_resources(key):
return {}
@APP.task(base=ErrorHandler, ignore_result=False)
def calc_revenue(res_dict):
calc_chord = chord(
calc_resource_revenue.s(...)
for resource in res_dict.get('resources', [])
)
return calc_chord(_sum_revenues.s()) # _sum_revenues receives a list a ints and returns a single int. Great! =D
@APP.task(base=ErrorHandler, ignore_result=False)
def _sum_revenues(revenues):
return sum(revenues)
@APP.task(base=ErrorHandler, ignore_result=False)
def calc_resource_revenue(resource, tenant_id, region):
return 1
@APP.task(base=ErrorHandler, ignore_result=False)
def mrr_total(revenues):
return round(sum(revenues), 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment