Ronny Pfannschmidt avatar Ronny Pfannschmidt committed d5c9596

take more state names from the module

Comments (0)

Files changed (4)

juggler/handlers/shedule.py

 from logbook import Logger
-from ..model import Task, Project
+from ..model import Task, Project, states as s
 from .utils import watches_for, steps_from_template
 
 log = Logger('shedule', level='info')
 
 
-@watches_for(Task, 'new')
+@watches_for(Task, s.new)
 def new_task_generate_steps(db, task):
     log.debug('get project {}', task.project)
     project = db.get(task.project, schema=Project)
         task.status = 'preparing'
     else:
         bulk += steps_from_template(project, task)
-        task.status = 'pending'
+        task.status = s.pending
     log.debug('save_bulk, {}', bulk)
     db.bulk_save(bulk)
     log.info('generated steps for {task._id}', task=task)
 
 
-@watches_for(Task, 'claiming')
+@watches_for(Task, s.claiming)
 def approve_claimed_task(db, task):
     # this asumes only one claim manager is running ever
     # we operate on a first come first serve basis
     all_docs = db.all_current_docs_for(task)
 
     for doc in all_docs:
-        if doc._rev != task._rev and doc.status != 'claiming':
+        if doc._rev != task._rev and doc.status != s.claiming:
             # conflict already solved by one
             # of the contenders proceeding
             # delete that exact revision
             break
     else:
         # no solution yet, accept the claim
-        task.status = 'claimed'
+        task.status = s.claimed
         db.save_doc(task)
         log.info('claimed {task._id} for {task.owner}', task=task)

juggler/handlers/slave.py

 from couchdbkit.exceptions import ResourceConflict
-from ..model import Task
+from ..model import Task, states as s
 from .utils import watches_for
 
 from logbook import Logger
 log = Logger('slave')
 
 
-@watches_for(Task, 'pending')
+@watches_for(Task, s.pending)
 def claim_pending_task(db, task, owner):
-    task.status = 'claiming'
+    task.status = s.claiming
     task.owner = owner.name
     try:
         db.save_doc(task)
         )
 
 
-@watches_for(Task, 'claimed', _id=lambda kw: kw['id'])
+@watches_for(Task, s.claimed, _id=lambda kw: kw['id'])
 def wait_for_one_claiming_task(db, task, id, owner):
     log.info(
         "worker {owner.name} waited for {task._id} of {task.owner}",
         return task
 
 
-@watches_for(Task, 'claimed', owner=lambda kw: kw['owner'])
+@watches_for(Task, s.claimed, owner=lambda kw: kw['owner'])
 def run_one_claimed_task(db, task, owner, run):
     log.info('dispatching task {task._id}', task=task)
     run(task)

juggler/model/states.py

+new = 'new'
 
 received = 'received'
+
 valid = 'valid'
+invalid = 'invalid'
 ready = 'ready'
 
+pending = 'pending'
+claiming = 'claiming'
+claimed = 'claimed'
+
 building = 'building'
 
 running = 'running'

testing/handlers/test_inbox.py

 import pytest
 from juggler import model
+from juggler.model import states as s
 from juggler.handlers import inbox
 
 from testing import with_quick_change_timeout
 @with_quick_change_timeout
 def test_inbox_simple_validate(db):
     #XXX: test a invalid case
-    order = model.Order(_id='order', status='received')
+    order = model.Order(_id='order', status=s.received)
     db.save_doc(order)
     inbox.order_validate(db)
     db.refresh(order)
-    assert order.status == 'valid'
+    assert order.status == s.valid
 
 
 @with_quick_change_timeout
 def test_valid_order_simple_ready(db):
-    order = model.Order(status='valid')
+    order = model.Order(status=s.valid)
     db.save_doc(order)
     inbox.valid_order_prepare(db)
     db.refresh(order)
-    assert order.status == 'ready'
+    assert order.status == s.ready
 
 
 @with_quick_change_timeout
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.