Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Want iteration control and worker shutdown #2883

Open
2 tasks done
aazammazaa opened this issue Sep 3, 2024 · 1 comment
Open
2 tasks done

Want iteration control and worker shutdown #2883

aazammazaa opened this issue Sep 3, 2024 · 1 comment

Comments

@aazammazaa
Copy link

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

@cyberw
Copy link
Collaborator

cyberw commented Sep 3, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants