def opsi_task_delay(self, recon_scan=False, submarine_call=False, ap_limit=False): """ Delay the NextRun of all OpSi tasks. Args: recon_scan (bool): True to delay all tasks requiring recon scan 30 min. submarine_call (bool): True to delay all tasks requiring submarine call 60 min. ap_limit (bool): True to delay all tasks requiring action points 360 min. """ if not recon_scan and not submarine_call and not ap_limit: return None kv = dict_to_kv({'recon_scan': recon_scan, 'submarine_call': submarine_call, 'ap_limit': ap_limit}) def delay_tasks(task_list, minutes): next_run = datetime.now().replace(microsecond=0) + timedelta(minutes=minutes) for task in task_list: keys = f'{task}.Scheduler.NextRun' current = deep_get(self.data, keys=keys, default=datetime(2020, 1, 1, 0, 0)) if current < next_run: logger.info(f'Delay task `{task}` to {next_run} ({kv})') self.modified[keys] = next_run def is_submarine_call(task): return deep_get(self.data, keys=f'{task}.OpsiFleet.Submarine', default=False) \ or 'submarine' in deep_get(self.data, keys=f'{task}.OpsiFleetFilter.Filter', default='').lower() def is_force_run(task): return deep_get(self.data, keys=f'{task}.OpsiExplore.ForceRun', default=False) \ or deep_get(self.data, keys=f'{task}.OpsiObscure.ForceRun', default=False) \ or deep_get(self.data, keys=f'{task}.OpsiAbyssal.ForceRun', default=False) \ or deep_get(self.data, keys=f'{task}.OpsiStronghold.ForceRun', default=False) def is_special_radar(task): return deep_get(self.data, keys=f'{task}.OpsiExplore.SpecialRadar', default=False) if recon_scan: tasks = SelectedGrids(['OpsiExplore', 'OpsiObscure', 'OpsiStronghold']) tasks = tasks.delete(tasks.filter(is_force_run)).delete(tasks.filter(is_special_radar)) delay_tasks(tasks, minutes=30) if submarine_call: tasks = SelectedGrids(['OpsiExplore', 'OpsiDaily', 'OpsiObscure', 'OpsiAbyssal', 'OpsiStronghold', 'OpsiMeowfficerFarming']) tasks = tasks.filter(is_submarine_call).delete(tasks.filter(is_force_run)) delay_tasks(tasks, minutes=60) if ap_limit: tasks = SelectedGrids(['OpsiExplore', 'OpsiDaily', 'OpsiObscure', 'OpsiAbyssal', 'OpsiStronghold', 'OpsiMeowfficerFarming']) tasks = tasks.delete(tasks.filter(is_special_radar)) delay_tasks(tasks, minutes=360) self.save()
def opsi_task_delay(self, recon_scan=False, submarine_call=False, ap_limit=False): """ Delay the NextRun of all OpSi tasks. Args: recon_scan (bool): True to delay all tasks requiring recon scan 30 min. submarine_call (bool): True to delay all tasks requiring submarine call 60 min. ap_limit (bool): True to delay all tasks requiring action points 360 min. """ if not recon_scan and not submarine_call and not ap_limit: return None kv = dict_to_kv({ "recon_scan": recon_scan, "submarine_call": submarine_call, "ap_limit": ap_limit, }) def delay_tasks(task_list, minutes): next_run = datetime.now().replace(microsecond=0) + timedelta( minutes=minutes) for task in task_list: keys = f"{task}.Scheduler.NextRun" current = deep_get(self.data, keys=keys, default=DEFAULT_TIME) if current < next_run: logger.info(f"Delay task `{task}` to {next_run} ({kv})") self.modified[keys] = next_run def is_submarine_call(task): return (deep_get( self.data, keys=f"{task}.OpsiFleet.Submarine", default=False) or "submarine" in deep_get( self.data, keys=f"{task}.OpsiFleetFilter.Filter", default="").lower()) def is_force_run(task): return (deep_get( self.data, keys=f"{task}.OpsiExplore.ForceRun", default=False) or deep_get(self.data, keys=f"{task}.OpsiObscure.ForceRun", default=False) or deep_get(self.data, keys=f"{task}.OpsiAbyssal.ForceRun", default=False) or deep_get(self.data, keys=f"{task}.OpsiStronghold.ForceRun", default=False)) def is_special_radar(task): return deep_get(self.data, keys=f"{task}.OpsiExplore.SpecialRadar", default=False) if recon_scan: tasks = SelectedGrids( ["OpsiExplore", "OpsiObscure", "OpsiStronghold"]) tasks = tasks.delete(tasks.filter(is_force_run)).delete( tasks.filter(is_special_radar)) delay_tasks(tasks, minutes=27) if submarine_call: tasks = SelectedGrids([ "OpsiExplore", "OpsiDaily", "OpsiObscure", "OpsiAbyssal", "OpsiStronghold", "OpsiMeowfficerFarming", ]) tasks = tasks.filter(is_submarine_call).delete( tasks.filter(is_force_run)) delay_tasks(tasks, minutes=60) if ap_limit: tasks = SelectedGrids([ "OpsiExplore", "OpsiDaily", "OpsiObscure", "OpsiAbyssal", "OpsiStronghold", "OpsiMeowfficerFarming", ]) if get_os_reset_remain() > 0: delay_tasks(tasks, minutes=360) else: logger.info( "Just less than 1 day to OpSi reset, delay 2.5 hours") delay_tasks(tasks, minutes=150) self.update()