How to use my_task_2 method in locust

Best Python code snippet using locust

main.py

Source:main.py Github

copy

Full Screen

1import time2from airflow import DAG3from airflow.operators.python import PythonOperator4from airflow.utils.dates import days_ago5from airflow.configuration import conf6from statsd import StatsClient7STATSD_HOST = conf.get("metrics", "statsd_host")8STATSD_PORT = conf.get("metrics", "statsd_port")9STATSD_PREFIX = conf.get("metrics", "statsd_prefix")10def task(run_time, **context):11 metric_name = f'dag.{context["dag"].dag_id}.{context["task"].task_id}.my_counter'12 client = StatsClient(host=STATSD_HOST, port=STATSD_PORT, prefix=STATSD_PREFIX)13 for i in range(0, run_time):14 time.sleep(1)15 client.incr(metric_name)16 print(i)17default_args = {18 'owner': 'airflow',19 'start_date': days_ago(5)20}21dag = DAG(22 'my_dag',23 default_args=default_args,24 description='',25 schedule_interval="*/2 * * * *",26 catchup=False27)28my_task_1 = PythonOperator(29 task_id='my_task',30 python_callable=task,31 op_args=[5],32 dag=dag,33 provide_context=True34)35my_task_2 = PythonOperator(36 task_id='my_task_2',37 python_callable=task,38 op_args=[2],39 dag=dag,40 provide_context=True41)...

Full Screen

Full Screen

subscriber2.py

Source:subscriber2.py Github

copy

Full Screen

2from celery import Celery3import celery_pubsub4worker = Celery('cpe', broker='redis://redis:6379/0')5@celery.task6def my_task_2(*args, **kwargs):7 return "task 2 done"...

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 locust 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