sync
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 3m3s

This commit is contained in:
2025-12-16 04:24:31 -08:00
parent 7f1fedf149
commit 644ae442ca

View File

@@ -39,8 +39,6 @@ try:
except ImportError:
CONSUL_LIBRARY = False
import schedule
# Configure logging
logging.basicConfig(
level=logging.INFO,
@@ -66,7 +64,7 @@ class WeightRecord:
class ConsulManager:
"""Manages all configuration and state in Consul K/V store"""
def __init__(self, host: str = "consul.service.dc1.consul", port: int = 8500, prefix: str = "fitbit-garmin-sync"):
def __init__(self, host: str = "localhost", port: int = 8500, prefix: str = "fitbit-garmin-sync"):
if not CONSUL_LIBRARY:
raise ImportError("python-consul library not installed. Please install it with: pip install python-consul")
@@ -832,7 +830,7 @@ class GarminClient:
class WeightSyncApp:
"""Main application class"""
def __init__(self, consul_host: str = "consul.service.dc1.consul", consul_port: int = 8500,
def __init__(self, consul_host: str = "localhost", consul_port: int = 8500,
consul_prefix: str = "fitbit-garmin-sync"):
self.consul = ConsulManager(consul_host, consul_port, consul_prefix)
self.fitbit = FitbitClient(self.consul)
@@ -1038,22 +1036,28 @@ class WeightSyncApp:
print(f"✅ Read-only mode {mode_text}")
print(f" {'Will NOT upload to Garmin' if new_mode else 'Will upload to Garmin'}")
def start_scheduler(self):
async def start_scheduler(self):
"""Start the sync scheduler"""
config = self.consul.get_config()
sync_interval = config.get('sync', {}).get('sync_interval_minutes', 60)
logger.info(f"Starting scheduler with {sync_interval} minute interval")
logger.info("Running initial sync...")
schedule.every(sync_interval).minutes.do(
lambda: asyncio.create_task(self.sync_weight_data())
)
# Run initial sync immediately
await self.sync_weight_data()
asyncio.create_task(self.sync_weight_data())
logger.info(f"Scheduled syncs will run every {sync_interval} minutes")
# Schedule periodic syncs
while True:
schedule.run_pending()
time.sleep(60)
try:
await asyncio.sleep(sync_interval * 60)
logger.info("Running scheduled sync...")
await self.sync_weight_data()
except Exception as e:
logger.error(f"Error in scheduled sync: {e}")
await asyncio.sleep(60) # Wait a minute before retrying
async def main():
@@ -1109,11 +1113,13 @@ async def main():
try:
config = app.consul.get_config()
read_only_mode = config.get('sync', {}).get('read_only_mode', False)
sync_interval = config.get('sync', {}).get('sync_interval_minutes', 60)
print("🚀 Starting scheduled sync...")
print(f"⏰ Sync interval: {sync_interval} minutes")
if read_only_mode:
print("📖 Running in read-only mode")
print("Press Ctrl+C to stop")
app.start_scheduler()
await app.start_scheduler()
except KeyboardInterrupt:
print("\n👋 Scheduler stopped")