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

Add start and stop hatching events #199

Merged
merged 1 commit into from
Sep 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions locust/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def fire(self, **kwargs):

report_to_master = EventHook()
"""
*report_to_master* is used when Locust is running in --slave mode. It can be used to attach
data to the dicts that are regularly sent to the master. It's fired regularly when a report
*report_to_master* is used when Locust is running in --slave mode. It can be used to attach
data to the dicts that are regularly sent to the master. It's fired regularly when a report
is to be sent to the master server.

Note that the keys "stats" and "errors" are used by Locust and shouldn't be overridden.
Expand All @@ -77,7 +77,7 @@ def fire(self, **kwargs):

slave_report = EventHook()
"""
*slave_report* is used when Locust is running in --master mode and is fired when the master
*slave_report* is used when Locust is running in --master mode and is fired when the master
server receives a report from a Locust slave server.

This event can be used to aggregate data from the locust slave servers.
Expand All @@ -101,3 +101,27 @@ def fire(self, **kwargs):
"""
*quitting* is fired when the locust process in exiting
"""

master_start_hatching = EventHook()
"""
*master_start_hatching* is fired when we initiate the hatching process on the master.

This event is especially usefull to detect when the 'start' button is clicked on the web ui.
"""

master_stop_hatching = EventHook()
"""
*master_stop_hatching* is fired when terminate the hatching process on the master.

This event is especially usefull to detect when the 'stop' button is clicked on the web ui.
"""

locust_start_hatching = EventHook()
"""
*locust_start_hatching* is fired when we initiate the hatching process on any locust worker.
"""

locust_stop_hatching = EventHook()
"""
*locust_stop_hatching* is fired when terminate the hatching process on any locust worker.
"""
4 changes: 4 additions & 0 deletions locust/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def start_hatching(self, locust_count=None, hatch_rate=None, wait=False):
self.stats.clear_all()
self.stats.start_time = time()
self.exceptions = {}
events.locust_start_hatching.fire()

# Dynamically changing the locust count
if self.state != STATE_INIT and self.state != STATE_STOPPED:
Expand Down Expand Up @@ -177,6 +178,7 @@ def stop(self):
self.hatching_greenlet.kill(block=True)
self.locusts.kill(block=True)
self.state = STATE_STOPPED
events.locust_stop_hatching.fire()

def log_exception(self, node_id, msg, formatted_tb):
key = hash(formatted_tb)
Expand Down Expand Up @@ -285,6 +287,7 @@ def start_hatching(self, locust_count, hatch_rate):
if self.state != STATE_RUNNING and self.state != STATE_HATCHING:
self.stats.clear_all()
self.exceptions = {}
events.master_start_hatching.fire()

for client in self.clients.itervalues():
data = {
Expand All @@ -307,6 +310,7 @@ def start_hatching(self, locust_count, hatch_rate):
def stop(self):
for client in self.clients.hatching + self.clients.running:
self.server.send(Message("stop", None, None))
events.master_stop_hatching.fire()

def quit(self):
for client in self.clients.itervalues():
Expand Down