def set_saved_dir(file_pathe:FilePathe): try: saved_dir = file_pathe.path get_mothership(router).set_saved_dir(saved_dir) return return_success(f"saved_dir set to ({saved_dir})") except Exception as e: raise raised_exception("failed to set (saved_dir)", e)
def stop_scheduled_jobs(): try: assert get_continuous(router).is_running(), "should be running when trying to stop" get_continuous(router).stop_running_continuously() return return_success("stopped running") except Exception as e: raise raised_exception("failed to stop running", e)
def get_saved_dir(): try: saved_dir = get_mothership(router).get_saved_dir() file_pathe = FilePathe(path=saved_dir) return return_success(file_pathe) except Exception as e: raise raised_exception("failed to get (saved_dir)", e)
def remove_action(action_name: str): try: get_mothership(router).remove_action(action_name=action_name) return return_success( f"action ({action_name}) was successfully removed") except Exception as e: raise raised_exception(f"failed to remove action ({action_name})", e)
def start_scheduled_jobs(): try: assert not get_continuous(router).is_running(), "should not be running when trying to start" get_continuous(router).run_continuously() return return_success("started running") except Exception as e: raise raised_exception("failed to start running", e)
def add_scheduler(scheduler_name:str, scheduler=Depends(resolve_scheduler)): try: assert scheduler, f"couldn't resolve class for scheduler ({scheduler_name})" get_mothership(router).add_scheduler(scheduler_name=scheduler_name, scheduler=scheduler) return return_success(f"scheduler ({scheduler_name}) was successfully added") except Exception as e: raise raised_exception(f"failed to add scheduler ({scheduler_name})", e)
def get_action(action_name: str): try: action = get_mothership(router).get_action(action_name=action_name) return return_success(action) except Exception as e: raise raised_exception( f"failed to retrieve the action ({action_name})", e)
def add_action(action_name: str, action=Depends(resolve_action)): try: assert action, f"couldn't resolve class for action ({action_name})" get_mothership(router).add_action(action_name=action_name, action=action) return return_success(f"action ({action_name}) was successfully added") except Exception as e: raise raised_exception(f"failed to add action ({action_name})", e)
def update_action(action_name: str, dictionary: dict): try: get_mothership(router).update_action(action_name=action_name, dictionary=dictionary) return return_success( f"action ({action_name}) was successfully updated") except Exception as e: raise raised_exception(f"failed to update action ({action_name})", e)
def unschedule_action(action_name: str): try: get_mothership(router).unschedule_action(action_name=action_name) return return_success( f"action ({action_name}) was successfully unscheduled") except Exception as e: raise raised_exception(f"failed to unschedule action ({action_name})", e)
def execute_action(action_name: str): try: result = get_mothership(router).execute_action(action_name=action_name) return return_success({ 'msg': f"action ({action_name}) was successfully executed", 'result': result }) except Exception as e: raise raised_exception(f"failed to execute action ({action_name})", e)
def load_from_name(name:str): try: return return_success(get_mothership(router).load_from_name(name)) except Exception as e: raise raised_exception(f"failed to retrieve the Mothership from ({name})", e)
def execute_scheduler_actions(scheduler_name:str): try: result = get_mothership(router).execute_scheduler_actions(scheduler_name=scheduler_name) return return_success({'msg': f"scheduler ({scheduler_name}) actions were successfully executed", 'result':result}) except Exception as e: raise raised_exception(f"failed to execute scheduler ({scheduler_name}) actions", e)
def update_scheduler(scheduler_name:str, dictionary:dict): try: get_mothership(router).update_scheduler(scheduler_name=scheduler_name, dictionary=dictionary) return return_success(f"scheduler ({scheduler_name}) was successfully updated") except Exception as e: raise raised_exception(f"failed to update scheduler ({scheduler_name})", e)
def reschedule_all_schedulers(): try: get_mothership(router).reschedule_all_schedulers() return return_success("all schedulers were successfully unscheduled") except Exception as e: raise raised_exception("failed to unschedule all schedulers", e)
def unschedule_scheduler(scheduler_name:str): try: get_mothership(router).unschedule_scheduler(scheduler_name=scheduler_name) return return_success(f"scheduler ({scheduler_name}) was successfully unscheduled") except Exception as e: raise raised_exception(f"failed to unschedule scheduler ({scheduler_name})", e)
def job_count(): try: return return_success({'job_count':get_continuous(router).job_count()}) except Exception as e: raise raised_exception("failed to get job count", e)
def clear_mothership(): try: get_mothership(router).clear_all() return return_success("mothership cleared") except Exception as e: raise raised_exception("failed to clear the Mothership", e)
def load(): try: return return_success(get_mothership(router).load_current()) except Exception as e: raise raised_exception("failed to retrieve the Mothership", e)
def save(): try: get_mothership(router).save_current() return return_success(f"mothership saved to current") except Exception as e: raise raised_exception("failed to save the Mothership", e)
def get_scheduler(scheduler_name:str): try: scheduler = get_mothership(router).get_scheduler(scheduler_name=scheduler_name) return return_success(scheduler) except Exception as e: raise raised_exception(f"failed to retrieve the scheduler ({scheduler_name})", e)
def save_to_name(name:str): try: get_mothership(router).save_to_name(name) return return_success(f"mothership saved to ({name})") except Exception as e: raise raised_exception(f"failed to save the Mothership to ({name})", e)
def schedule_action(scheduler_name:str, action_name:str): try: get_mothership(router).schedule_action(scheduler_name=scheduler_name, action_name=action_name) return return_success(f"action ({action_name}) was successfully scheduled ({scheduler_name})") except Exception as e: raise raised_exception(f"failed to schedule ({scheduler_name}) action ({action_name})", e)