locust icon indicating copy to clipboard operation
locust copied to clipboard

Want iteration control and worker shutdown

Open aazammazaa opened this issue 1 year ago • 1 comments

Prerequisites

Description

class UserBehavior1(SequentialTaskSet): max_iterations = 2

def on_start(self):
    self.iterations = 0    # Initialize the counter in the on_start method

@task
def my_task(self):
    if self.iterations >= self.max_iterations:
        self.user.environment.runner.stop()
    try:
        logging.info("hello2")
        self.client.get("/time")
        self.iterations += 1
    except Exception as e:
        logging.info(f"Error during request: {e}")
        raise RescheduleTaskImmediately

@task
def my_taskA(self):     
    logging.info("hello1A")
    self.user.environment.runner.stop()
`class WebsiteUser(HttpUser):
  def on_start(self):
      logging.info("thread started--------------------------------------------------------------")
  
  def on_stop(self):
      logging.info("thread stoped+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")

  wait_time = between(1, 5)
  tasks = [UserBehavior1]`

' I want to run this in worker node is this possible have ieration control and shutdown of task after 10 iteration. As defining a variable for iteration doesn't got the iteration counter correctly and also many time worker struck to stopped event

aazammazaa avatar Sep 03 '24 05:09 aazammazaa

Hi! locust-plugins offers something like that: https://github.com/SvenskaSpel/locust-plugins?tab=readme-ov-file#command-line-options

cyberw avatar Sep 03 '24 07:09 cyberw

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar Nov 03 '24 02:11 github-actions[bot]

This issue was closed because it has been stalled for 10 days with no activity. This does not necessarily mean that the issue is bad, but it most likely means that nobody is willing to take the time to fix it. If you have found Locust useful, then consider contributing a fix yourself!

github-actions[bot] avatar Nov 14 '24 02:11 github-actions[bot]