Skip to content

Commit

Permalink
Merge pull request #199 from skinp/start-stop-events
Browse files Browse the repository at this point in the history
Add start and stop hatching events
  • Loading branch information
Jahaja committed Sep 18, 2014
2 parents b2b9c97 + bdafcd9 commit 127b7f7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
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

0 comments on commit 127b7f7

Please sign in to comment.