def disable_tasks(self, target): periodic = PeriodicTask.objects(target=target) for p in periodic: periodic_document = periodic.get(name=p.name) if periodic_document.enabled: periodic_document.enabled = False periodic_document.save()
def rerun_all_walks(self): periodic = PeriodicTask.objects() for p in periodic: if not p.task == "splunk_connect_for_snmp.snmp.tasks.walk": continue logger.debug(p) periodic_document = periodic.get(name=p.name) periodic_document.run_immediately = True logger.debug("Got Schedule") periodic_document.save()
def delete_all_poll_tasks(self): periodic = PeriodicTask.objects() for p in periodic: if not p.task == "splunk_connect_for_snmp.snmp.tasks.poll": continue logger.debug(p) periodic_document = periodic.get(name=p.name) logger.debug("Got Schedule") periodic_document.delete() logger.debug("Deleting Schedule")
def delete_unused_poll_tasks(self, target: str, activeschedules: List[str]): periodic = PeriodicTask.objects(target=target) for p in periodic: if not p.task == "splunk_connect_for_snmp.snmp.tasks.poll": continue logger.debug(p) periodic_document = periodic.get(name=p.name) logger.debug("Got Schedule") if p.name not in activeschedules: if periodic_document.enabled: periodic_document.enabled = False logger.debug(f"Deleting Schedule: {periodic_document.name}")
def remove(task_name): ''' remove database entry using task_name as lookup''' next(PeriodicTask.objects(task_name=task_name)).delete()
def manage_task(self, run_immediately_if_new: bool = False, **task_data) -> None: periodic = PeriodicTask.objects(name=task_data["name"]) if periodic: logger.debug("Existing Schedule") isChanged = False periodic_document = periodic.get(name=task_data["name"]) for key, value in task_data.items(): if key == "interval": if not periodic_document.interval == PeriodicTask.Interval( **task_data["interval"]): periodic_document.interval = PeriodicTask.Interval( **task_data["interval"]) isChanged = True elif key == "crontab": if not periodic_document.crontab == PeriodicTask.Crontab( **task_data["crontab"]): periodic_document.crontab = PeriodicTask.Crontab( **task_data["crontab"]) isChanged = True elif key == "target": pass elif key == "total_run_count": periodic_document[key] = task_data[key] else: if key in periodic_document: if not periodic_document[key] == task_data[key]: periodic_document[key] = task_data[key] isChanged = True else: periodic_document[key] = task_data[key] isChanged = True else: logger.debug("New Schedule") isChanged = True periodic_document = PeriodicTask(task=task_data["task"]) periodic_document.name = task_data["name"] periodic_document.args = task_data["args"] periodic_document.kwargs = task_data["kwargs"] if "interval" in task_data: periodic_document.interval = PeriodicTask.Interval( **task_data["interval"]) else: periodic_document.crontab = PeriodicTask.Crontab( **task_data["crontab"]) periodic_document.enabled = task_data["enabled"] periodic_document.run_immediately = task_data.get( "run_immediately", run_immediately_if_new) if "total_run_count" in task_data: periodic_document["total_run_count"] = task_data[ "total_run_count"] if "target" in task_data: periodic_document["target"] = task_data["target"] if "options" in task_data: periodic_document["options"] = task_data["options"] logger.info( f"Periodic document to save: {periodic_document.to_json()}") if isChanged: periodic_document.save()
def delete_disabled_poll_tasks(self): periodic = PeriodicTask.objects(enabled=False) for p in periodic: periodic_document = periodic.get(name=p.name) periodic_document.delete() logger.debug("Deleting Schedule")