|
|
@ -3,6 +3,7 @@ import json
|
|
|
|
import logging
|
|
|
|
import logging
|
|
|
|
import signal
|
|
|
|
import signal
|
|
|
|
import uuid
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
from collections import defaultdict
|
|
|
|
|
|
|
|
|
|
|
|
import argh
|
|
|
|
import argh
|
|
|
|
import gevent.backdoor
|
|
|
|
import gevent.backdoor
|
|
|
@ -41,6 +42,12 @@ rows_changed = prom.Counter(
|
|
|
|
['type', 'worksheet'],
|
|
|
|
['type', 'worksheet'],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
event_counts = prom.Gauge(
|
|
|
|
|
|
|
|
'event_counts',
|
|
|
|
|
|
|
|
'Number of rows in the database',
|
|
|
|
|
|
|
|
['sheet_name', 'category', 'poster_moment', 'state', 'errored'],
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class SheetSync(object):
|
|
|
|
class SheetSync(object):
|
|
|
|
|
|
|
|
|
|
|
|
# Time between syncs
|
|
|
|
# Time between syncs
|
|
|
@ -190,8 +197,12 @@ class SheetSync(object):
|
|
|
|
"""Return the entire events table as a map {id: event namedtuple}"""
|
|
|
|
"""Return the entire events table as a map {id: event namedtuple}"""
|
|
|
|
result = query(self.conn, "SELECT * FROM events")
|
|
|
|
result = query(self.conn, "SELECT * FROM events")
|
|
|
|
by_id = {}
|
|
|
|
by_id = {}
|
|
|
|
|
|
|
|
counts = defaultdict(lambda: 0)
|
|
|
|
for row in result.fetchall():
|
|
|
|
for row in result.fetchall():
|
|
|
|
by_id[row.id] = row
|
|
|
|
by_id[row.id] = row
|
|
|
|
|
|
|
|
counts[row.sheet_name, row.category, str(row.poster_moment), row.state, str(bool(row.error))] += 1
|
|
|
|
|
|
|
|
for labels, count in counts.items():
|
|
|
|
|
|
|
|
event_counts.labels(*labels).set(count)
|
|
|
|
return by_id
|
|
|
|
return by_id
|
|
|
|
|
|
|
|
|
|
|
|
def parse_row(self, row):
|
|
|
|
def parse_row(self, row):
|
|
|
|