Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def check_rate(cls, crawler, stage, sample=1):
q = session.query(func.count(cls.id))
q = q.filter(cls.crawler == crawler)
q = q.filter(cls.name == stage)
period = timedelta(seconds=sample * 60)
start = datetime.utcnow() - period
q = q.filter(cls.started_at >= start)
count = q.scalar()
return (float(count) / sample) / 60.0
def last_run(cls, crawler):
q = session.query(cls)
q = q.filter(cls.crawler == crawler)
q = q.order_by(cls.started_at.desc())
op = q.first()
if op is None:
return None
return op.started_at
def delete(cls, crawler):
pq = session.query(cls)
pq = pq.filter(cls.crawler == crawler)
pq.delete(synchronize_session=False)
def last_status(cls, crawler):
q = session.query(cls)
q = q.filter(cls.crawler == crawler)
q = q.order_by(cls.started_at.desc())
op = q.first()
if op is None:
return None
return op.status
def get(cls, **kwargs):
q = session.query(cls)
q = q.filter_by(**kwargs)
return q.all()
def delete(cls, crawler):
from memorious.model.event import Event
from memorious.model.result import Result
Event.delete(crawler)
Result.delete(crawler)
pq = session.query(cls)
pq = pq.filter(cls.crawler == crawler)
pq.delete(synchronize_session=False)