self.state = 'error' self.result = traceback.format_exc() raise finally: self.time_stop = datetime.utcnow() session(self).flush(self) def join(self, poll_interval=0.1): '''Wait until this task is either complete or errors out, then return the result.''' while self.state not in ('complete', 'error'): time.sleep(poll_interval) self.query.find(dict(_id=self._id), refresh=True).first() result = self.result self.query.delete() return result @classmethod def list(cls, state='ready'): '''Print all tasks of a certain status to sys.stdout. Used for debugging.''' q = cls.query.find(dict(state=state)) lines = map(repr, q) return '\n'.join(lines) odm_session.mapper(TaskObject, TaskDoc)
from ming.odm import ForeignIdProperty, RelationProperty from lesson_2_0 import model as M sess = ThreadLocalODMSession(M.sess) class Forum(object): pass class Thread(object): pass class Post(object): pass sess.mapper(Forum, M.Forum, properties=dict( threads=RelationProperty('Thread'))) sess.mapper(Thread, M.Thread, properties=dict( forum_id=ForeignIdProperty('Forum'), forum=RelationProperty('Forum'), posts=RelationProperty('Post'))) sess.mapper(Post, M.Post, properties=dict( forum_id=ForeignIdProperty('Forum'), thread_id=ForeignIdProperty('Thread'), forum=RelationProperty('Forum'), thread=RelationProperty('Thread'))) Mapper.compile_all() class Product(object): pass
class Forum(object): pass class Thread(object): pass class Post(object): pass sess.mapper(Forum, M.Forum, properties=dict(threads=RelationProperty('Thread'))) sess.mapper(Thread, M.Thread, properties=dict(forum_id=ForeignIdProperty('Forum'), forum=RelationProperty('Forum'), posts=RelationProperty('Post'))) sess.mapper(Post, M.Post, properties=dict(forum_id=ForeignIdProperty('Forum'), thread_id=ForeignIdProperty('Thread'), forum=RelationProperty('Forum'), thread=RelationProperty('Thread'))) Mapper.compile_all()