How to use handle_tasks method in autotest

Best Python code snippet using autotest_python

tasks.py

Source:tasks.py Github

copy

Full Screen

...9from monitor.models import MonitorTask, ObjectData10from monitor.services import MonitorService11from utils.baidu_translate import BaiduTranslate12logger = get_task_logger(__name__)13def handle_tasks(tasks):14 for task in tasks:15 logger.info('Monitor task %s has started' % task.name)16 try:17 MonitorService.distribute_task(task)18 except Exception as e:19 logger.error(str(e))20 logger.info('Monitor task %s done' % task.name)21@periodic_task(run_every=(crontab(minute='*/5')),22 name="monitor_5_minute_update", ignore_result=True)23def monitor_5_minute_update():24 logger.info('monitor_5_minute_update has started')25 tasks = MonitorTask.objects.filter(26 triggered=False,27 frequency=MonitorFrequency.FIVE_MINUTES)28 handle_tasks(tasks)29@periodic_task(run_every=(crontab(minute=0, hour='*/1')),30 name="monitor_1_hour_update", ignore_result=True)31def monitor_1_hour_update():32 logger.info('monitor_1_hour_update has started')33 tasks = MonitorTask.objects.filter(34 triggered=False,35 frequency=MonitorFrequency.ONE_HOUR)36 handle_tasks(tasks)37@periodic_task(run_every=(crontab(minute=0, hour='*/12')),38 name="monitor_half_day_update", ignore_result=True)39def monitor_half_day_update():40 logger.info('monitor_half_day_update has started')41 tasks = MonitorTask.objects.filter(42 triggered=False,43 frequency=MonitorFrequency.HALF_DAY)44 handle_tasks(tasks)45@periodic_task(run_every=(crontab(minute='*/5')),46 name="monitor_trump", ignore_result=True)47def monitor_trump():48 REDIRECT_URI = 'http://127.0.0.1:8000/test'49 # c = Client(settings.WEIBO_API_KEY, settings.WEIBO_API_SECRET, REDIRECT_URI)50 # print(c.authorize_url)51 # c.set_code('647d0955d4baf7ab376bb6f67028e88a')52 # {'uid': '1576273817', 'access_token':'','expires_at': 1491418799, 'remind_in': '2621205'}53 token = {'uid': '1576273817', 'access_token': settings.WEIBO_TRUMP_ACCESS_TOKEN,54 'expires_at': 1491418799,55 'remind_in': '2621205'}56 api = twitter.Api(consumer_key=settings.TWITTER_CONSUMER_KEY,57 consumer_secret=settings.TWITTER_CONSUMER_SECRET,58 access_token_key=settings.TWITTER_ACCESS_TOKEN_KEY,...

Full Screen

Full Screen

external_task_manager.py

Source:external_task_manager.py Github

copy

Full Screen

1# Copyright (C) 20222# Moscow3# PUBLISHED MATERIAL.4#5# Authors: Vasiliev Ivan <open.source.can1can@gmail.com>6#7import asyncio8import logging9from dataclasses import dataclass10from typing import List, NoReturn1112from connectors.camunda_connector.connector import CamundaConnector13from connectors.camunda_connector.defs import ExternalTask14from external_tasks.external_task_handler import AbstractExternalTaskHandler1516logger = logging.getLogger(__file__)171819class ExternalTaskManager:20 @dataclass21 class Context:22 camunda_connector: CamundaConnector = None2324 def __init__(self,25 context: Context,26 ):27 self.camunda_task_connector = context.camunda_connector.external_task28 self.__topic_to_processor = {}29 self.__task_ids = set()3031 def register_external_task_handler(self, external_task_handler: AbstractExternalTaskHandler):32 self.__topic_to_processor[external_task_handler.topic_name] = external_task_handler.process_camunda_task3334 async def run_monitoring(self) -> NoReturn:35 while True:36 try:37 logger.debug(f"{self.__class__.__name__}: monitoring cycle started.")38 task_list: List[ExternalTask] = await self.camunda_task_connector.get_list()39 # logger.info(f"task_list: {task_list}")40 handle_tasks = []41 for task in task_list:42 if task.topic_name in self.__topic_to_processor:43 handle_tasks.append(asyncio.create_task(self.__topic_to_processor[task.topic_name](task)))44 await asyncio.gather(*handle_tasks)45 except Exception as er:46 logger.exception(f"{self.__class__.__name__}.run.error: {repr(er)}")47 #48 # logger.debug(f"{self.__class__.__name__}: monitoring cycle ended.") ...

Full Screen

Full Screen

producer.py

Source:producer.py Github

copy

Full Screen

...14 progressbar = tqdm.tqdm(15 desc="Scraping Proggress", total=queue.qsize(), position=0, leave=False, unit=' images'16 )17 asyncio.set_event_loop(self.loop)18 tasks = [self.handle_tasks(task_id, queue, progressbar) for task_id in range(self.max_threads)]19 try:20 self.loop.run_until_complete(asyncio.wait(tasks))21 finally:22 self.loop.close()23 progressbar.clear()...

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