def update_datadoc_schedule(id, cron=None, enabled=None, kwargs=None): if kwargs is not None: kwargs_valid, kwargs_valid_reason = validate_datadoc_schedule_config( kwargs) api_assert(kwargs_valid, kwargs_valid_reason) if cron is not None: api_assert(validate_cron(cron), "Invalid cron expression") schedule_name = schedule_logic.get_data_doc_schedule_name(id) with DBSession() as session: assert_can_write(id, session=session) schedule = schedule_logic.get_task_schedule_by_name(schedule_name, session=session) api_assert(schedule, "Schedule does not exist") verify_data_doc_permission(id, session=session) updated_fields = {} if cron is not None: updated_fields["cron"] = cron if enabled is not None: updated_fields["enabled"] = enabled if kwargs is not None: updated_fields["kwargs"] = { **kwargs, "user_id": current_user.id, "doc_id": id, } return schedule_logic.update_task_schedule( schedule.id, session=session, **updated_fields, )
def update_schedule(id, **kwargs): allowed_fields = ["cron", "args", "kwargs", "enabled", "options"] filtered_kwargs = {k: v for k, v in kwargs.items() if k in allowed_fields} if "cron" in filtered_kwargs: api_assert(validate_cron(filtered_kwargs["cron"]), "Invalid cron expression") return logic.update_task_schedule(id=id, **filtered_kwargs)
def save(self): update_dict = {} for field in self.save_fields: update_dict[field] = getattr(self.model, field) update_task_schedule(self.model.id, **update_dict)
def _disable(self, model): update_task_schedule(model.id, enabled=False, no_changes=True)