Example #1
0
class TaskQueueORM(CustomDynamicDocument):
    """A queue of tasks corresponding to a procedure.

       Notes: Don't sort query results without having the index sorted
              or it will impact the performance.
    """

    spec = db.DynamicField()
    parser = db.StringField()
    status = db.StringField(
        default='WAITING', choices=['RUNNING', 'WAITING', 'ERROR', 'COMPLETE'])

    program = db.StringField()
    procedure = db.StringField()
    manager = db.StringField()

    # others
    priority: db.IntField(default=1)
    tag = db.StringField(default=None)

    # can reference ResultORMs or any ProcedureORM
    base_result = db.GenericLazyReferenceField(
        dbref=True)  # use res.id and res.document_type (class)

    created_on = db.DateTimeField(required=True)
    modified_on = db.DateTimeField(required=True)

    meta = {
        'collection':
        'task_queue',
        'indexes': [
            'created_on',
            'status',

            # Specification fields
            {
                'fields': ('program', 'procedure'),
            },  # new
            'manager',

            # order effects
            'tag',
            'priority',
            {
                'fields': ('base_result', ),
                'unique': True
            },  # new
        ]
    }

    def save(self, *args, **kwargs):
        """Override save to update modified_on."""
        self.modified_on = datetime.datetime.utcnow()
        if not self.created_on:
            self.created_on = datetime.datetime.utcnow()

        return super(TaskQueueORM, self).save(*args, **kwargs)
Example #2
0
 class DocOnlyA(me.Document):
     id = me.StringField(primary_key=True, default='main')
     generic = me.GenericLazyReferenceField(choices=[SubDocA])
Example #3
0
 class Doc(me.Document):
     id = me.StringField(primary_key=True, default='main')
     generic = me.GenericLazyReferenceField()