def update(self, session, action=None, failed_action=None, completed_action=None, **params): self.update_with_mapping(params) if action: self.action.update_with_mapping(action) if failed_action: if self.failed_action: self.failed_action.update_with_mapping(failed_action) else: self.failed_action = TaskAction.polymorphic_create( failed_action) if completed_action: if self.completed_action: self.completed_action.update_with_mapping(completed_action) else: self.completed_action = TaskAction.polymorphic_create( completed_action) session.flush() if self.status == 'active' and not self.has_pending_task(session): self.reschedule(session, datetime.now(UTC))
def create(cls, session, tag, action, status='pending', occurrence=None, failed_action=None, completed_action=None, description=None, retry_backoff=None, retry_limit=2, retry_timeout=300, delta=None): if not occurrence: occurrence = current_timestamp() if delta: occurrence += timedelta(seconds=delta) task = ScheduledTask(tag=tag, status=status, description=description, occurrence=occurrence, retry_backoff=retry_backoff, retry_limit=retry_limit, retry_timeout=retry_timeout) if isinstance(action, dict): task.action = TaskAction.polymorphic_create(action) else: task.action = action if failed_action: if isinstance(failed_action, dict): task.failed_action = TaskAction.polymorphic_create(failed_action) else: task.failed_action = failed_action if completed_action: if isinstance(completed_action, dict): task.completed_action = TaskAction.polymorphic_create(completed_action) else: taks.completed_action = completed_action session.add(task) return task
def create(cls, session, tag, action, schedule_id, status='active', failed_action=None, completed_action=None, description=None, retry_backoff=None, retry_limit=2, retry_timeout=300, id=None): task = RecurringTask(tag=tag, status=status, description=description, schedule_id=schedule_id, retry_backoff=retry_backoff, retry_limit=retry_limit, retry_timeout=retry_timeout, id=id) task.action = TaskAction.polymorphic_create(action) if failed_action: task.failed_action = TaskAction.polymorphic_create(failed_action) if completed_action: task.completed_action = TaskAction.polymorphic_create( completed_action) session.add(task) if status == 'active': session.flush() task.reschedule(session, datetime.now(UTC)) return task
def update(self, session, action=None, failed_action=None, completed_action=None, **params): self.update_with_mapping(params) if action: self.action.update_with_mapping(action) if failed_action: if self.failed_action: self.failed_action.update_with_mapping(failed_action) else: self.failed_action = TaskAction.polymorphic_create(failed_action) if completed_action: if self.completed_action: self.completed_action.update_with_mapping(completed_action) else: self.completed_action = TaskAction.polymorphic_create(completed_action)
def create(cls, session, tag, action, status='pending', occurrence=None, failed_action=None, completed_action=None, description=None, retry_backoff=None, retry_limit=2, retry_timeout=300, delta=None): if not occurrence: occurrence = current_timestamp() if delta: occurrence += timedelta(seconds=delta) task = ScheduledTask(tag=tag, status=status, description=description, occurrence=occurrence, retry_backoff=retry_backoff, retry_limit=retry_limit, retry_timeout=retry_timeout) if isinstance(action, dict): task.action = TaskAction.polymorphic_create(action) else: task.action = action if failed_action: if isinstance(failed_action, dict): task.failed_action = TaskAction.polymorphic_create( failed_action) else: task.failed_action = failed_action if completed_action: if isinstance(completed_action, dict): task.completed_action = TaskAction.polymorphic_create( completed_action) else: taks.completed_action = completed_action session.add(task) return task
def create(cls, session, tag, action, topic, aspects=None, activation_limit=None, failed_action=None, completed_action=None, description=None, retry_backoff=None, retry_limit=2, retry_timeout=300, timeout=None, id=None): task = SubscribedTask(id=id, tag=tag, description=description, topic=topic, aspects=aspects, activation_limit=activation_limit, retry_backoff=retry_backoff, retry_limit=retry_limit, retry_timeout=retry_timeout, timeout=timeout) task.action = TaskAction.polymorphic_create(action) if failed_action: task.failed_action = TaskAction.polymorphic_create(failed_action) if completed_action: task.completed_action = TaskAction.polymorphic_create(completed_action) session.add(task) return task
def update(self, session, action=None, failed_action=None, completed_action=None, **params): self.update_with_mapping(params) if action: self.action.update_with_mapping(action) if failed_action: if self.failed_action: self.failed_action.update_with_mapping(failed_action) else: self.failed_action = TaskAction.polymorphic_create(failed_action) if completed_action: if self.completed_action: self.completed_action.update_with_mapping(completed_action) else: self.completed_action = TaskAction.polymorphic_create(completed_action) session.flush() if self.status == 'active' and not self.has_pending_task(session): self.reschedule(session, datetime.now(UTC))
def create(cls, session, tag, action, schedule_id, status='active', failed_action=None, completed_action=None, description=None, retry_backoff=None, retry_limit=2, retry_timeout=300, id=None): task = RecurringTask(tag=tag, status=status, description=description, schedule_id=schedule_id, retry_backoff=retry_backoff, retry_limit=retry_limit, retry_timeout=retry_timeout, id=id) task.action = TaskAction.polymorphic_create(action) if failed_action: task.failed_action = TaskAction.polymorphic_create(failed_action) if completed_action: task.completed_action = TaskAction.polymorphic_create(completed_action) session.add(task) if status == 'active': session.flush() task.reschedule(session, datetime.now(UTC)) return task
def update(self, session, action=None, failed_action=None, completed_action=None, **params): self.update_with_mapping(params) if action: self.action.update_with_mapping(action) if failed_action: if self.failed_action: self.failed_action.update_with_mapping(failed_action) else: self.failed_action = TaskAction.polymorphic_create( failed_action) if completed_action: if self.completed_action: self.completed_action.update_with_mapping(completed_action) else: self.completed_action = TaskAction.polymorphic_create( completed_action)
def create(cls, session, tag, action, topic, aspects=None, activation_limit=None, failed_action=None, completed_action=None, description=None, retry_backoff=None, retry_limit=2, retry_timeout=300, timeout=None, id=None): task = SubscribedTask(id=id, tag=tag, description=description, topic=topic, aspects=aspects, activation_limit=activation_limit, retry_backoff=retry_backoff, retry_limit=retry_limit, retry_timeout=retry_timeout, timeout=timeout) task.action = TaskAction.polymorphic_create(action) if failed_action: task.failed_action = TaskAction.polymorphic_create(failed_action) if completed_action: task.completed_action = TaskAction.polymorphic_create( completed_action) session.add(task) return task