| |
@@ -22,11 +22,13 @@
|
| |
|
| |
import re
|
| |
import datetime
|
| |
+ from typing import Counter
|
| |
|
| |
from sqlalchemy import desc
|
| |
|
| |
from oraculum.models.watchdog import WatchDogData, WatchDogStartPoint
|
| |
from oraculum.models.db_cache import CachedData
|
| |
+ from oraculum.models.counters import Counters
|
| |
from oraculum.utils.mailing_utils import send_mail
|
| |
|
| |
from oraculum import app, celery_app, db
|
| |
@@ -55,9 +57,6 @@
|
| |
from oraculum.utils.celery_utils import get_users_for_sync
|
| |
from oraculum import CACHE
|
| |
|
| |
- if app.config["ACTIVE_WATCHDOG"]:
|
| |
- redis_conn = celery_app.broker_connection().default_channel.client
|
| |
-
|
| |
# Prepare users and packages who meet criteria for sync
|
| |
cached_users = get_users_for_sync()
|
| |
cached_packages = set()
|
| |
@@ -71,6 +70,15 @@
|
| |
# Prepare data from db for watchdog emailing
|
| |
data_too_old = CachedData.query.filter(CachedData.time_created <= cache_cutoff).all()
|
| |
|
| |
+ # Orphaned counters
|
| |
+ if app.config["ACTIVE_WATCHDOG"]:
|
| |
+ counters = Counters.query.filter(Counters.counter != 0).all()
|
| |
+ for counter in counters:
|
| |
+ cached_counterpart = CachedData.query.filter(CachedData.provider == counter.what).first()
|
| |
+ if not cached_counterpart:
|
| |
+ counter.counter = 0
|
| |
+ db.session.commit()
|
| |
+
|
| |
# Find out what db line id to start with
|
| |
start_point = WatchDogStartPoint.query.first()
|
| |
|
| |
@@ -149,7 +157,10 @@
|
| |
|
| |
# Reset counter if ACTIVE_WATCHDOG
|
| |
if app.config["ACTIVE_WATCHDOG"]:
|
| |
- counter = redis_conn.getset(old_data.provider, 0)
|
| |
+ counter = Counters.query.with_for_update().filter_by(what=old_data.provider).first()
|
| |
+ if counter:
|
| |
+ counter.counter = 0
|
| |
+ db.session.commit()
|
| |
|
| |
try:
|
| |
if not app.config["SEND_ERROR_EMAILS"]:
|
| |
Counter manipulation should be atomic.
Perf difference of sync planning (kalev, 392 packages):