juggler / 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')

class Juggler(object):
    def __init__(self, db, name, path=None):
        self.name = name
        self.db = db
        self.path = path

    def __repr__(self):
        return '<Juggler %r>' % self.db.dbname

    def watch_for(self, type, **kw):
        return watch_for(self.db, type, **kw)

    def all_current_docs_for(self, doc):
        schema = type(doc)
        items = self.db.get(doc._id, open_revs='all')
        docs = [item[u'ok'] for item in items if u'ok' in item]
        log.debug('versions {}', docs)
        if not isinstance(doc, dict):
            docs = [schema.wrap(item) for item in docs]
        return docs

    def save_doc(self, doc):

    def bulk_save(self, *k, **kw):
        self.db.bulk_save(*k, **kw)

    def get(self, *k, **kw):
        return self.db.get(*k, **kw)

    def run_task(self, task):
        #XXX: not cancelable yet
        assert self.path is not None
        from juggler.process.procdir import ProcDir
        procdir = ProcDir(self.db, self.path.join(task.project), task)
        steps = procdir.find_steps()
        assert steps
        task.status = s.building
            log.debug('building {}', task._id)
        except ResourceConflict:
            #XXX: test for this case
            log.error('building {} failed due to db conflict', task._id)
        for step in steps:
                'run {task._id} step {step.index}',
                task=task, step=step)
            #XXX: test for break
            if step.status != s.complete:
        # 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)
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.