-
Notifications
You must be signed in to change notification settings - Fork 2
/
blocks-demo.py
executable file
·46 lines (39 loc) · 1.75 KB
/
blocks-demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
import asyncio
import json
import aioflureedb
async def blockmon(block, instant):
print("BLOCK DONE: ", block, instant)
async def new_user(obj_id, flakes, new_obj, operation, block_meta):
print("NEW ROLE:", obj_id, flakes)
print(" :", new_obj, operation)
print(json.dumps(block_meta, indent=4, sort_keys=True))
async def dropped_user(obj_id, flakes, old_obj, operation, block_meta):
print("DROPPED ROLE:", obj_id, flakes)
print(" :", old_obj, operation)
print(json.dumps(block_meta, indent=4, sort_keys=True))
async def updated_user(obj_id, flakes, old_obj, new_obj, operation, block_meta):
print("UPDATED ROLE:", obj_id, flakes)
print(" :", old_obj, new_obj, operation)
print(json.dumps(block_meta, indent=4, sort_keys=True))
async def journal_entry(obj):
print(json.dumps(obj, indent=4, sort_keys=True))
async def blocks_demo():
print("Connecting to FlureeDB")
async with aioflureedb.FlureeClient(port=8090) as flureeclient:
print("Waiting till Fluree is ready")
await flureeclient.health.ready()
print("Looking up database")
db = await flureeclient["dla/latestforprod"]
print("Opening database")
async with db() as database:
print("Initializing monitor")
database.monitor_init(blockmon, start_block=0, rewind=720000)
database.monitor_register_create("_role", new_user)
database.monitor_register_delete("_role", dropped_user)
database.monitor_register_update("_role", updated_user)
database.monitor_instant("journal/timestamp", journal_entry, 0)
print("Running Monitor")
await database.monitor_untill_stopped()
LOOP = asyncio.get_event_loop()
LOOP.run_until_complete(blocks_demo())