def add_backlog(self, task, entry, amount='', session=None): """Add single entry to task backlog If :amount: is not specified, entry will only be injected on next execution.""" snapshot = entry.snapshots.get('after_input') if not snapshot: if task.current_phase != 'input': # Not having a snapshot is normal during input phase, don't display a warning log.warning( 'No input snapshot available for `%s`, using current state' % entry['title']) snapshot = entry expire_time = datetime.now() + parse_timedelta(amount) backlog_entry = (session.query(BacklogEntry).filter( BacklogEntry.title == entry['title']).filter( BacklogEntry.task == task.name).first()) if backlog_entry: # If there is already a backlog entry for this, update the expiry time if necessary. if backlog_entry.expire < expire_time: log.debug('Updating expiry time for %s' % entry['title']) backlog_entry.expire = expire_time else: log.debug('Saving %s' % entry['title']) backlog_entry = BacklogEntry() backlog_entry.title = entry['title'] backlog_entry.entry = snapshot backlog_entry.task = task.name backlog_entry.expire = expire_time session.add(backlog_entry)
def add_backlog(self, task, entry, amount='', session=None): """Add single entry to task backlog If :amount: is not specified, entry will only be injected on next execution.""" snapshot = entry.snapshots.get('after_input') if not snapshot: if task.current_phase != 'input': # Not having a snapshot is normal during input phase, don't display a warning log.warning( 'No input snapshot available for `%s`, using current state' % entry['title'] ) snapshot = entry expire_time = datetime.now() + parse_timedelta(amount) backlog_entry = ( session.query(BacklogEntry) .filter(BacklogEntry.title == entry['title']) .filter(BacklogEntry.task == task.name) .first() ) if backlog_entry: # If there is already a backlog entry for this, update the expiry time if necessary. if backlog_entry.expire < expire_time: log.debug('Updating expiry time for %s' % entry['title']) backlog_entry.expire = expire_time else: log.debug('Saving %s' % entry['title']) backlog_entry = BacklogEntry() backlog_entry.title = entry['title'] backlog_entry.entry = snapshot backlog_entry.task = task.name backlog_entry.expire = expire_time session.add(backlog_entry)
def get_injections(self, task, session=None): """Insert missing entries from backlog.""" entries = [] for backlog_entry in get_entries(task=task.name, session=session): entry = backlog_entry.entry # this is already in the task if task.find_entry(title=entry['title'], url=entry['url']): continue log.debug('Restoring %s' % entry['title']) entries.append(entry) if entries: log.verbose('Added %s entries from backlog' % len(entries)) # purge expired purged = clear_entries(task=task.name, all=False, session=session) log.debug('%s entries purged from backlog' % purged) return entries
def on_task_abort(self, task, config): """Remember all entries until next execution when task gets aborted.""" if task.entries: log.debug( 'Remembering all entries to backlog because of task abort.') self.learn_backlog(task)
def on_task_abort(self, task, config): """Remember all entries until next execution when task gets aborted.""" if task.entries: log.debug('Remembering all entries to backlog because of task abort.') self.learn_backlog(task)