aboutsummaryrefslogtreecommitdiffstats
path: root/python/ops
diff options
context:
space:
mode:
Diffstat (limited to 'python/ops')
-rw-r--r--python/ops/product_loop.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/python/ops/product_loop.py b/python/ops/product_loop.py
new file mode 100644
index 00000000..58f7984c
--- /dev/null
+++ b/python/ops/product_loop.py
@@ -0,0 +1,33 @@
+from serenitas.utils import get_redis_queue
+from trade_dataclasses import DealKind
+from pickle import loads
+from .funds import Selene
+
+
+def upload_products():
+ selene = Selene()
+ cache = set()
+ while True:
+ pickle = q.lpop("product_queue")
+ trade_type, trade = loads(pickle)
+ if (h := hash(trade)) in cache: # we've gone full circle
+ break
+ else:
+ obj = DealKind[trade_type].from_dict(**trade)
+ product = obj.product
+ if product.status == "Pending":
+ q.rpush("product_queue", pickle)
+ selene.staging_queue.append(product.to_citco())
+ _cache |= h
+ buf, dest = selene.build_buffer()
+ selene.upload(buf, dest.name)
+
+
+async def gather_product():
+ loop = asynctio.get_running_loop()
+ end_time = loop.time() + 300
+ while True:
+ if loop.time() >= end_time:
+ do_something()
+ end_time = loop.time() + 300
+ await asyncio.sleep(1)