Skip to content

Commit

Permalink
Support for skipping devices for selection in Commando & its subclasses
Browse files Browse the repository at this point in the history
+ Just return None from Commando.select_next_device()
+ Commando._add_worker() change slightly to expect None and move on.
  • Loading branch information
jathanism committed Feb 4, 2015
1 parent 79e9cef commit dd6f7f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ New Features
------------

+ Support for Pica8 routers and switches has been added!
+ An ehancement to `~trigger.cmds.Commando.select_next_device()` to support
skipping a `~trigger.netdevices.NetDevice` object for selection. If you
overload this method in a subclass and want to skip the device, just return
``None``!

.. _v1.4.8:

Expand Down
9 changes: 7 additions & 2 deletions trigger/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
__maintainer__ = 'Jathan McCollum'
__email__ = 'jathan@gmail.com'
__copyright__ = 'Copyright 2009-2013, AOL Inc.; 2014 Salesforce.com'
__version__ = '2.4'
__version__ = '2.4.1'

import collections
import datetime
Expand Down Expand Up @@ -231,11 +231,13 @@ def select_next_device(self, jobs=None):
abstracted out so that this behavior may be customized, such as for
future support for incremental callbacks.
If a device is determined to be invalid, you must return ``None``.
:param jobs:
(Optional) The jobs queue. If not set, uses ``self.jobs``.
:returns:
A `~trigger.netdevices.NetDevice` object
A `~trigger.netdevices.NetDevice` object or ``None``.
"""
if jobs is None:
jobs = self.jobs
Expand All @@ -249,6 +251,9 @@ def _add_worker(self):
"""
while self.jobs and self.curr_conns < self.max_conns:
device = self.select_next_device()
if device is None:
log.msg('No device returned when adding worker. Moving on.')
continue

self._increment_connections()
log.msg('connections:', self.curr_conns)
Expand Down

0 comments on commit dd6f7f3

Please sign in to comment.