data init idk other stuff

This commit is contained in:
2025-04-18 15:19:57 -04:00
parent 8f35cedb4a
commit 03b43ce3ab
28 changed files with 3378 additions and 810 deletions

View File

@ -1,4 +1,4 @@
from app.db.database import transaction, get_db
from app.db.database import transaction
from app.services.scheduler.base_scheduler import BaseScheduler
import logging
@ -17,11 +17,10 @@ class SchedulerService:
self._service_manager = ServiceManager()
return self._service_manager
async def update_open_orders_hourly(self):
async def update_open_orders_hourly(self, db):
"""
Hourly update of orders from TCGPlayer API to database
"""
db = next(get_db())
try:
logger.info("Starting hourly order update")
# Get order management service
@ -39,14 +38,11 @@ class SchedulerService:
except Exception as e:
logger.error(f"Error updating open orders: {str(e)}")
raise
finally:
db.close()
async def update_all_orders_daily(self):
async def update_all_orders_daily(self, db):
"""
Daily update of all orders from TCGPlayer API to database
"""
db = next(get_db())
try:
logger.info("Starting daily order update")
# Get order management service
@ -64,21 +60,19 @@ class SchedulerService:
except Exception as e:
logger.error(f"Error updating all orders: {str(e)}")
raise
finally:
db.close()
async def start_scheduled_tasks(self):
async def start_scheduled_tasks(self, db):
"""Start all scheduled tasks"""
# Schedule open orders update to run hourly at 00 minutes
await self.scheduler.schedule_task(
task_name="update_open_orders_hourly",
func=self.update_open_orders_hourly,
func=lambda: self.update_open_orders_hourly(db),
interval_seconds=60 * 60, # 1 hour
)
# Schedule all orders update to run daily at 1 AM
await self.scheduler.schedule_task(
task_name="update_all_orders_daily",
func=self.update_all_orders_daily,
func=lambda: self.update_all_orders_daily(db),
interval_seconds=24 * 60 * 60, # 24 hours
)