How to use add_result_listener method in yandex-tank

Best Python code snippet using yandex-tank

dynamic_scheduler.py

Source:dynamic_scheduler.py Github

copy

Full Screen

...48 executors=self.config.EXECUTORS, job_defaults=self.config.JOB_DEFAULTS)49 self.listener = Listener(self.scheduler, config_class)50 self.scheduler.add_listener(self.listener.add_job_listener, EVENT_JOB_ADDED)51 self.db_pool = PoolDB(self.config.DEFAULT_DB_URL)52 def add_result_listener(self):53 if self.config.IS_DYNAMIC_UPDATE_CRON: # 开启会耗时 降低性能54 self.scheduler.add_listener(self.listener.execute_job_listener, EVENT_JOB_EXECUTED | EVENT_JOB_ERROR)55 return self56 def add_job(self, func, trigger=None, args=None, kwargs=None, id=None, name=None,57 misfire_grace_time=undefined, coalesce=undefined, max_instances=undefined,58 next_run_time=undefined, jobstore='default', executor='default',59 replace_existing=False, **trigger_args):60 self.scheduler.add_job(func, trigger, args, kwargs, id, name,61 misfire_grace_time, coalesce, max_instances,62 next_run_time, jobstore, executor,63 replace_existing, **trigger_args)64 def add_job_with_default(self, func, cron_str=None,trigger=None, args=None, kwargs=None, id=None, name=None,65 misfire_grace_time=undefined, coalesce=True, max_instances=undefined,66 next_run_time=undefined, jobstore='default', executor='default',67 replace_existing=True, **trigger_args):68 """69 默认只需传入 func、id、cron表达式70 增加任务时设定一些默认选项,避免重复code, trigger 默认为 cron71 """72 trigger_ = self.config.DEFAULT_TRIGGER if trigger is None else trigger73 trigger_args_ = trigger_args74 if cron_str:75 trigger_args_.update(self.listener.translate_expression(cron_str))76 self.add_job(func, trigger_, args, kwargs, id, name,77 misfire_grace_time, coalesce, max_instances,78 next_run_time, jobstore, executor,79 replace_existing, **trigger_args_)80 def start(self, *args, **kwargs):81 existed_jobs = self.scheduler.get_jobs(jobstore='default')82 if existed_jobs:83 self.scheduler.start(*args, **kwargs)84 def clear_history(self):85 self.db_pool.execute(f'delete from {self.config.SCHEDULER_SCHEMA}.{self.config.SCHEDULER_TABLE}')86 def set_cron_task(self, func):87 """88 1. 给默认 cron表中定时任务 进行启动89 2. 设置 不同的func 的定时任务,通过job_id关联,job_id可设置为func_name90 # 依赖self.insert_cron_table 方法,先执行完给每个方法设定初始值;91 # 现在不依赖了,添加不存在的任务会自动存入cron中92 """93 cron_task = self.db_pool[f'select * from {self.config_class.SCHEMA_TABLE} where state = 1']94 if not cron_task.empty:95 for index, row in cron_task.iterrows():96 self.add_job_with_default(func, self.listener.translate_expression(row['expression']), id=row['job_id'])97 self.add_result_listener()98 # self.start()99 def insert_cron_table(self, func_list, expression_list):100 """批量传入方法列表、表达式列表,后期可改为dict"""101 value_str = [f"('{func.__name__}', '{express}')" for func, express in zip(func_list, expression_list)]102 value_str = ", ".join(value_str)103 insert_sql = f"insert into {self.config.SCHEMA_TABLE} (job_id, expression) values {value_str}"104 self.db_pool.insert(insert_sql)105 logger.success("写入cron表成功")106class StaticSchedulerProxy(DynamicSchedulerProxy):107 def __init__(self, config_class):108 super(StaticSchedulerProxy, self).__init__(config_class)109 self.scheduler.remove_listener(self.listener.add_job_listener)110 self.listener = Listener(self.scheduler, self.config)111 self.listener.IS_DYNAMIC_UPDATE_CRON = False112 self.scheduler.add_listener(self.listener.add_job_listener, EVENT_JOB_ADDED)113if __name__ == '__main__':114 def task():115 # print(datetime.datetime.now())116 # time.sleep(10)117 print('start time: ', datetime.datetime.now(), os.getpid(), threading.current_thread().name)118 return datetime.datetime.now()119 class Config(SchedulerConfig):120 DEFAULT_DB_URL = 'postgresql+psycopg2://postgres:123456@127.0.0.1:5432/postgres?utf-8'121 SCHEDULER_SCHEMA = 'public'122 s = DynamicSchedulerProxy(config_class=Config)123 s.clear_history()124 s.add_job_with_default(func=task, cron_str='* * */5', id='task')125 s.add_result_listener()...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

...90 self.main_layout = QVBoxLayout(self)91 self.main_layout.addWidget(self.ribbon)92 self.main_layout.addWidget(self.view)93 self.model.add_source_listener(self.view.set_left_image)94 self.model.add_result_listener(self.view.set_right_image)95 self.model.add_loading_listener(lambda loading: upscale_button.setEnabled(not loading))96 self.model.add_result_listener(lambda result: save_button.setEnabled(result is not None))97 self.model.add_source_listener(lambda source: upscale_button.setEnabled(source is not None))98 def dragEnterEvent(self, e):99 if e.mimeData().hasImage() or e.mimeData().hasUrls():100 e.accept()101 else:102 e.ignore()103 104 def dropEvent(self, e):105 if e.mimeData().hasImage():106 qtimage = e.mimeData().imageData()107 image = Image.fromqimage(qtimage)108 self.display_image(image)109 elif e.mimeData().urls()[0].scheme() == "file":110 url = e.mimeData().urls()[0].toString()...

Full Screen

Full Screen

game.py

Source:game.py Github

copy

Full Screen

...13 def __init__(self, player1: Player, player2: Player) -> None:14 self.player1 = player115 self.player2 = player216 pass17 def add_result_listener(self, result_listener: Callable[[Result, Player], None]):18 self.result_listeners.append(result_listener)19 def move(self, player: Player, move: Move):20 if player == self.player1:21 if self.player1Move != None:22 raise Exception("Player 1 already made their move")23 self.player1Move = move24 elif player == self.player2:25 if self.player2Move != None:26 raise Exception("Player 2 already made their move")27 self.player2Move = move28 else:29 raise Exception(f'Unknown player: {player.name}')30 if self.player1Move != None and self.player2Move != None:31 self.determine_result()...

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 yandex-tank 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