Ronny Pfannschmidt avatar Ronny Pfannschmidt committed fd02dd7

start putting state names into a module to unify things

Comments (0)

Files changed (5)

juggler/handlers/inbox.py

-from ..model import Order, Task
+from ..model import Order, Task, states as s
 from .utils import watches_for, generate_specs
 
 from logbook import Logger
 log = Logger('inbox')
 
 
-@watches_for(Order, 'received')
+@watches_for(Order, s.received)
 def order_validate(db, order):
     #XXX: validate
-    order.status = 'valid'
+    order.status = s.valid
     db.save_doc(order)
     log.info('order {order._id} valid')
 
 
-@watches_for(Order, 'valid')
+@watches_for(Order, s.valid)
 def valid_order_prepare(db, order):
     #XXX: fill in axis from project/task
-    order.status = 'ready'
+    order.status = s.ready
     db.save_doc(order)
     log.info('order {order._id} ready')
 
 
-@watches_for(Order, 'ready')
+@watches_for(Order, s.ready)
 def ready_order_generate_tasks(db, order):
     bulk = [order]
     oid = order._id
         )
         bulk.append(job)
 
-    order.status = 'building'
+    order.status = s.building
     db.bulk_save(bulk)
     log.info('order {order._id} building')

juggler/model/states.py

+
+received = 'received'
+valid = 'valid'
+ready = 'ready'
+
+building = 'building'
+
+running = 'running'
+
+complete = 'complete'
+failed = 'failed'

juggler/process/baseproc.py

 import logbook
 from juggler import async
 from juggler.model import utils
+from juggler.model import states as s
 
 log = logbook.Logger('Proc', level='info')
 
             self.save_with_batch(doc)
             returncode = getattr(doc, 'returncode', None)
             if returncode is not None and self.step is not None:
-                self.finish_step('complete' if returncode == 0 else 'failed')
+                self.finish_step(s.complete if returncode == 0 else s.failed)
         log.debug('store thread stop {}', self.step._id)
 
     def finish_step(self, newstate):

juggler/service.py

 from .handlers.utils import watch_for
 import logbook
 from couchdbkit import ResourceConflict
+from juggler.model import states as s
 
 log = logbook.Logger('juggler', level='info')
 
         procdir = ProcDir(self.db, self.path.join(task.project), task)
         steps = procdir.find_steps()
         assert steps
-        task.status = 'building'
+        task.status = s.building
         try:
             self.save_doc(task)
             log.debug('building {}', task._id)
                 'run {task._id} step {step.index}',
                 task=task, step=step)
             procdir.run(step)
-        task.status = 'completed'
+            #XXX: test for break
+            if step.status != s.complete:
+                break
+        # a task ends with the state of the last step finished
+        # which may be completed, failed or canceled
+        task.status = step.status
         log.info('completed {}', task._id)
         self.save_doc(task)

testing/process/test_events.py

 import copy
 from juggler.model import Step
+from juggler.model import states as s
 from juggler.process.subprocess import python_template, subprocess_template
 
 
     procdir.run(step)
     checks = [
         ('type', "juggler:step",
-         'status', "running"),
+         'status', s.running),
         ('line', 'somefile\n'),
         ('returncode', 0),
         ('type', "juggler:step",
-         'status', "complete"),
+         'status', s.complete),
     ]
     check_events(procdir, checks)
 
     procdir.run(step)
     checks = [
         ('type', "juggler:step",
-         'status', "running"),
+         'status', s.running),
         ('returncode', 1),
         ('type', "juggler:step",
-         'status', "failed"),
+         'status', s.failed),
     ]
     check_events(procdir, checks)
 
     procdir.run(doc)
     checks = [
         ('type', "juggler:step",
-         'status', "running"),
+         'status', s.running),
         ('line', '1\n'),
         ('returncode', 0),
         ('type', "juggler:step",
-         'status', "complete"),
+         'status', s.complete),
     ]
     check_events(procdir, checks)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.