How to use _recover_processes method in autotest

Best Python code snippet using autotest_python

monitor_db.py

Source:monitor_db.py Github

copy

Full Screen

...250 # run a refresh task first. If there is any action in the queue, refresh251 # will raise an exception.252 _drone_manager.execute_actions()253 # always recover processes254 self._recover_processes()255 if recover_hosts:256 self._recover_hosts()257 def _log_tick_msg(self, msg):258 if self._tick_debug:259 logging.debug(msg)260 def _log_extra_msg(self, msg):261 if self._extra_debugging:262 logging.debug(msg)263 def tick(self):264 """265 This is an altered version of tick() where we keep track of when each266 major step begins so we can try to figure out where we are using most267 of the tick time.268 """269 timer = autotest_stats.Timer('scheduler.tick')270 system_utils.DroneCache.refresh()271 self._log_tick_msg('Calling new tick, starting garbage collection().')272 self._garbage_collection()273 self._log_tick_msg('Calling _drone_manager.trigger_refresh().')274 _drone_manager.trigger_refresh()275 self._log_tick_msg('Calling _process_recurring_runs().')276 self._process_recurring_runs()277 self._log_tick_msg('Calling _schedule_delay_tasks().')278 self._schedule_delay_tasks()279 self._log_tick_msg('Calling _schedule_running_host_queue_entries().')280 self._schedule_running_host_queue_entries()281 self._log_tick_msg('Calling _schedule_special_tasks().')282 self._schedule_special_tasks()283 self._log_tick_msg('Calling _schedule_new_jobs().')284 self._schedule_new_jobs()285 self._log_tick_msg('Calling _drone_manager.sync_refresh().')286 _drone_manager.sync_refresh()287 # _run_cleanup must be called between drone_manager.sync_refresh, and288 # drone_manager.execute_actions, as sync_refresh will clear the calls289 # queued in drones. Therefore, any action that calls drone.queue_call290 # to add calls to the drone._calls, should be after drone refresh is291 # completed and before drone_manager.execute_actions at the end of the292 # tick.293 self._log_tick_msg('Calling _run_cleanup().')294 self._run_cleanup()295 self._log_tick_msg('Calling _find_aborting().')296 self._find_aborting()297 self._log_tick_msg('Calling _find_aborted_special_tasks().')298 self._find_aborted_special_tasks()299 self._log_tick_msg('Calling _handle_agents().')300 self._handle_agents()301 self._log_tick_msg('Calling _host_scheduler.tick().')302 self._host_scheduler.tick()303 self._log_tick_msg('Calling _drone_manager.execute_actions().')304 _drone_manager.execute_actions()305 self._log_tick_msg('Calling '306 'email_manager.manager.send_queued_emails().')307 with timer.get_client('email_manager_send_queued_emails'):308 email_manager.manager.send_queued_emails()309 self._log_tick_msg('Calling django.db.reset_queries().')310 with timer.get_client('django_db_reset_queries'):311 django.db.reset_queries()312 self._tick_count += 1313 def _run_cleanup(self):314 self._periodic_cleanup.run_cleanup_maybe()315 self._24hr_upkeep.run_cleanup_maybe()316 def _garbage_collection(self):317 threshold_time = time.time() - self._seconds_between_garbage_stats318 if threshold_time < self._last_garbage_stats_time:319 # Don't generate these reports very often.320 return321 self._last_garbage_stats_time = time.time()322 # Force a full level 0 collection (because we can, it doesn't hurt323 # at this interval).324 gc.collect()325 logging.info('Logging garbage collector stats on tick %d.',326 self._tick_count)327 gc_stats._log_garbage_collector_stats()328 def _register_agent_for_ids(self, agent_dict, object_ids, agent):329 for object_id in object_ids:330 agent_dict.setdefault(object_id, set()).add(agent)331 def _unregister_agent_for_ids(self, agent_dict, object_ids, agent):332 for object_id in object_ids:333 assert object_id in agent_dict334 agent_dict[object_id].remove(agent)335 # If an ID has no more active agent associated, there is no need to336 # keep it in the dictionary. Otherwise, scheduler will keep an337 # unnecessarily big dictionary until being restarted.338 if not agent_dict[object_id]:339 agent_dict.pop(object_id)340 def add_agent_task(self, agent_task):341 """342 Creates and adds an agent to the dispatchers list.343 In creating the agent we also pass on all the queue_entry_ids and344 host_ids from the special agent task. For every agent we create, we345 add it to 1. a dict against the queue_entry_ids given to it 2. A dict346 against the host_ids given to it. So theoritically, a host can have any347 number of agents associated with it, and each of them can have any348 special agent task, though in practice we never see > 1 agent/task per349 host at any time.350 @param agent_task: A SpecialTask for the agent to manage.351 """352 agent = Agent(agent_task)353 self._agents.append(agent)354 agent.dispatcher = self355 self._register_agent_for_ids(self._host_agents, agent.host_ids, agent)356 self._register_agent_for_ids(self._queue_entry_agents,357 agent.queue_entry_ids, agent)358 def get_agents_for_entry(self, queue_entry):359 """360 Find agents corresponding to the specified queue_entry.361 """362 return list(self._queue_entry_agents.get(queue_entry.id, set()))363 def host_has_agent(self, host):364 """365 Determine if there is currently an Agent present using this host.366 """367 return bool(self._host_agents.get(host.id, None))368 def remove_agent(self, agent):369 self._agents.remove(agent)370 self._unregister_agent_for_ids(self._host_agents, agent.host_ids,371 agent)372 self._unregister_agent_for_ids(self._queue_entry_agents,373 agent.queue_entry_ids, agent)374 def _host_has_scheduled_special_task(self, host):375 return bool(models.SpecialTask.objects.filter(host__id=host.id,376 is_active=False,377 is_complete=False))378 def _recover_processes(self):379 agent_tasks = self._create_recovery_agent_tasks()380 self._register_pidfiles(agent_tasks)381 _drone_manager.refresh()382 self._recover_tasks(agent_tasks)383 self._recover_pending_entries()384 self._check_for_unrecovered_verifying_entries()385 self._reverify_remaining_hosts()386 # reinitialize drones after killing orphaned processes, since they can387 # leave around files when they die388 _drone_manager.execute_actions()389 _drone_manager.reinitialize_drones()390 def _create_recovery_agent_tasks(self):391 return (self._get_queue_entry_agent_tasks()392 + self._get_special_task_agent_tasks(is_active=True))...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful