def nightly_task(): log.info("batch started") hub.threadingLocal = threading_local() hub.begin() last = BatchRecord.select(orderBy=BatchRecord.q.last_handled).reversed() if last.count(): last_rec = last[0] from_when = last_rec.last_handled else: from_when = datetime.date.today() last_handled = datetime.datetime.now() current = BatchRecord(first_handled=from_when, last_handled=last_handled) hub.commit() try: current.artists_updated = update_artists(queries_per_run) current.venues_updated = update_venues() cleanup_db() current.email_sent, current.artist_pings, current.venue_pings = send_email(from_when, last_handled) current.finished = datetime.datetime.now() hub.commit() except Exception, inst: import traceback hub.rollback() for admin in Group.by_group_name("admin").users: util.email( admin.email_address, "BandRadar <*****@*****.**>", "batch error", "Batch failed, Andy is on it!\n\n" + traceback.format_exc(), )
def __init__(self, uri=None, supports_transactions=True): if not uri: uri = config.get("dejavu.dburi") self.uri = uri self.supports_transactions = supports_transactions self.threadingLocal = threading_local() hub_registry.add(self)
def __call__(self, *args, **kw): applogger.debug("schedSafe: begin") hub.threadingLocal = threading_local() hub.begin() try: ret = self.f(*args, **kw) applogger.debug("schedSafe: %s returned %s" % (self.f.__name__, ret)) finally: commit_all() end_all() applogger.debug("schedSafe: done")
def hourly_task(): hub.threadingLocal = threading_local() hub.begin() # notify admins of pending events added by users events_pending = Event.select(Event.q.approved == None) pending_count = events_pending.count() unnotified = events_pending.filter(Event.q.admin_notified == False) if unnotified.count(): for event in unnotified: event.admin_notified = True for admin in Group.by_group_name("admin").users: util.email( admin.email_address, "BandRadar <*****@*****.**>", "%d events in queue" % pending_count, "There are events in the pending queue.", ) hub.commit()
def __init__(self, name='obj'): self.name = name self.threadingLocal = threading_local()
def reset(self): """Used for testing purposes. This drops all of the connections that are being held.""" self.threadingLocal = threading_local()