diff --git a/blaster/blast.py b/blaster/blast.py index 29e6f25..6c58efd 100644 --- a/blaster/blast.py +++ b/blaster/blast.py @@ -11,7 +11,11 @@ class Blaster(CalcTimeMixin, LoggerMixin): - """Blaster's main class.""" + """Blast a list of tasks concurrently. + + The primary focus of this class is to processes a list of tasks given as + input and run them all concurrently. + """ def __init__(self, tasks, log_level='info'): """Constructor. @@ -49,8 +53,13 @@ def correlate_data(self): task[key] = value def blastoff(self, raise_on_failure=False): - """Blast off a list of tasks concurrently calling each tasks methods - defined. + """Blast off tasks concurrently call their defined methods. + + Each task has a list of methods to execute. This method will create + x amount of processes (start them) and then begin to add the tasks to + a queue. It will begin to process the tasks and run their methods they + have defined. Once all tasks are finsihed in the queue, it will handle + the results and return them back to the user. :param raise_on_failure: Whether to raise exception on failure. :type raise_on_failure: bool diff --git a/blaster/core.py b/blaster/core.py index d2a0595..76b062e 100644 --- a/blaster/core.py +++ b/blaster/core.py @@ -12,7 +12,7 @@ class BlasterError(Exception): - """Blaster's base exception class.""" + """Blaster's base error to raise.""" def __init__(self, message, results=list()): """Constructor. @@ -71,6 +71,7 @@ def delta(self): """Calculate time delta between start and end times. :return: Hours, minutes, seconds + :rtype: int """ elapsed = self._end_time - self._start_time hours = elapsed // 3600 @@ -81,7 +82,7 @@ def delta(self): class TaskDefinition(dict): - """Task definition.""" + """The standard definition of a blaster task.""" def __init__(self, *args, **kwargs): """Constructor. @@ -108,7 +109,7 @@ def is_valid(self): class ResultsList(list): - """Results list.""" + """The standard results for a blaster run.""" def __init__(self): """Constructor.""" @@ -126,8 +127,12 @@ def analyze(self): return 0 def coordinate(self, task): - """Coordinate and update the list of results with their corresponding - task definitions. + """Update results with their corresponding task definitions. + + :param task: Task definition to compare too. + :type task: dict + :return: Matching result task to the task given. + :rtype: dict """ for item in self: try: diff --git a/examples/build_houses.py b/examples/build_houses.py index 94bbfcb..e0ce9aa 100644 --- a/examples/build_houses.py +++ b/examples/build_houses.py @@ -11,38 +11,49 @@ class House(object): - """Class to build a house.""" + """Build a house.""" def __init__(self, style, **kwargs): - """Constructor.""" + """Constructor. + + :param style: Style of the house to build. + :type style: str + """ self.style = style def foundation(self): + """Build the foundation.""" LOG.info('Building the foundation for %s house..' % self.style) sleep(1) def frame(self): + """Frame the house.""" LOG.info('Frame the house for %s house..' % self.style) sleep(1) def roof(self): + """Roof the house.""" LOG.info('Roof the house for %s house..' % self.style) sleep(1) def furnish(self): + """Furnish the house.""" LOG.info('Furnish the house for %s house..' % self.style) sleep(1) def enjoy(self): + """Enjoy the house.""" LOG.info('Enjoy your new %s house :)' % self.style) sleep(1) def post_build_tasks(self): + """Post build tasks after house is built.""" LOG.info('Perform post building tasks for %s house..' % self.style) sleep(1) if __name__ == '__main__': + # list of tasks (houses to be built) concurrently to save time tasks = [ { 'name': 'House 1', diff --git a/tests/examples/invalid.py b/tests/examples/invalid.py index 2c97891..35e5140 100644 --- a/tests/examples/invalid.py +++ b/tests/examples/invalid.py @@ -9,7 +9,7 @@ class InvalidCar(object): - """Class to build a invalid car.""" + """Build an invalid car.""" def __init__(self, **kwargs): """Constructor.""" @@ -17,11 +17,13 @@ def __init__(self, **kwargs): @staticmethod def exterior(): + """Build the car's exterior.""" LOG.info('Build exterior.') raise Exception('Unable to build exterior today.') sleep(1) @staticmethod def interior(): + """Build the car's interior.""" LOG.info('Build interior') sleep(1) diff --git a/tests/examples/valid.py b/tests/examples/valid.py index 69bc11b..ac19ff3 100644 --- a/tests/examples/valid.py +++ b/tests/examples/valid.py @@ -9,7 +9,7 @@ class ValidCar(object): - """Class to build a valid car.""" + """Build a valid car.""" def __init__(self, **kwargs): """Constructor.""" @@ -17,10 +17,12 @@ def __init__(self, **kwargs): @staticmethod def exterior(): + """Build the car's exterior.""" LOG.info('Build exterior.') sleep(1) @staticmethod def interior(): + """Build the car's interior.""" LOG.info('Build interior') sleep(1)