Best Python code snippet using autotest_python
tasks.py
Source: tasks.py
...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,...
external_task_manager.py
Source: external_task_manager.py
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.")
...
producer.py
Source: producer.py
...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()...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!