Skip to content

Commit

Permalink
docs: show off app.state and CircuitBreaker with more common example
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu committed Aug 26, 2024
1 parent cd52455 commit 0a69d16
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,21 @@ def exec_event1(log):
@app.on_(YFI.Approval)
# Any handler function can be async too
async def exec_event2(log: ContractLog):
if log.log_index % 7 == 6:
# If you ever want the app to immediately shutdown under some scenario, raise this exception
raise CircuitBreaker("Oopsie!")

# All `app.state` values are updated across all workers at the same time
app.state.logs_processed += 1
# Do any other long running tasks...
await asyncio.sleep(5)
return log.amount


@app.on_(chain.blocks)
# NOTE: You can have multiple handlers for any trigger we support
def check_logs(log):
if app.state.logs_processed > 20:
# If you ever want the app to immediately shutdown under some scenario, raise this exception
raise CircuitBreaker("Oopsie!")


# A final job to execute on Silverback shutdown
@app.on_shutdown()
def app_shutdown():
Expand Down

0 comments on commit 0a69d16

Please sign in to comment.