Ejemplo n.º 1
0
    def create_pointer(self, node, execution: Execution):
        ''' Given a node, its process, and a specific execution of the former
        create a persistent pointer to the current execution state '''
        pointer = Pointer(
            node_id=node.id,
            name=node.name,
            description=node.description,
        ).save()

        pointer.proxy.execution.set(execution)

        return pointer
Ejemplo n.º 2
0
    def start(self, node, input, mongo, user_identifier):
        # the first set of values
        context = compact_values(input)

        # save the data
        execution = Execution(
            process_name=self.filename,
            name=self.get_name(context),
            name_template=self.name_template(),
            description=self.get_description(context),
            description_template=self.description_template(),
            started_at=datetime.now(),
            status='ongoing',
        ).save()

        pointer = Pointer(
            node_id=node.id,
            name=node.get_name(context),
            description=node.get_description(context),
            started_at=execution.started_at,
            status='ongoing',
        ).save()
        pointer.execution.set(execution)

        # log to mongo
        collection = mongo[self.config['POINTER_COLLECTION']]
        collection.insert_one(pointer_entry(
            node,
            pointer.name,
            pointer.description,
            execution,
            pointer
        ))

        collection = mongo[self.config['EXECUTION_COLLECTION']]
        collection.insert_one(execution_entry(
            execution,
            self.get_state(),
        ))

        # trigger rabbit
        from .tasks import handle

        handle.delay(json.dumps({
            'command': 'step',
            'pointer_id': pointer.id,
            'user_identifier': user_identifier,
            'input': input,
        }))

        return execution
Ejemplo n.º 3
0
    def _create_pointer(self, node_id: str, name: str, description: str,
                        execution: Execution):
        ''' Given a node, its process, and a specific execution of the former
        create a persistent pointer to the current execution state '''
        pointer = Pointer(
            node_id=node_id,
            name=name,
            description=description,
            started_at=datetime.now(),
            status='ongoing',
        ).save()

        pointer.execution.set(execution)

        return pointer
Ejemplo n.º 4
0
    def start(self, node, input, mongo, channel, user_identifier):
        # save the data
        execution = Execution(
            process_name=self.filename,
            name=self.get_name(input),
            description=self.get_description(input),
        ).save()
        pointer = Pointer(
            node_id=node.id,
            name=node.name,
            description=node.description,
        ).save()
        pointer.proxy.execution.set(execution)

        # log to mongo
        collection = mongo[self.config['POINTER_COLLECTION']]
        collection.insert_one(node.pointer_entry(execution, pointer))

        collection = mongo[self.config['EXECUTION_COLLECTION']]
        collection.insert_one({
            '_type': 'execution',
            'id': execution.id,
            'name': execution.name,
            'description': execution.description,
            'status': 'ongoing',
            'started_at': datetime.now(),
            'finished_at': None,
            'state': self.get_state(),
            'values': {},
            'actors': {},
        })

        # trigger rabbit
        channel.basic_publish(
            exchange='',
            routing_key=self.config['RABBIT_QUEUE'],
            body=json.dumps({
                'command': 'step',
                'pointer_id': pointer.id,
                'user_identifier': user_identifier,
                'input': input,
            }),
            properties=pika.BasicProperties(
                delivery_mode=2,
            ),
        )

        return execution
Ejemplo n.º 5
0
def make_pointer(
    process_name,
    node_id,
    execution_status=None,
    pointer_status=None,
):
    exc = Execution(
        process_name=process_name,
        status=execution_status or 'ongoing',
    ).save()
    ptr = Pointer(
        node_id=node_id,
        status=pointer_status or 'ongoing',
    ).save()
    ptr.execution.set(exc)

    return ptr
Ejemplo n.º 6
0
def make_pointer(process_name, node_id):
    exc = Execution(process_name=process_name, ).save()
    ptr = Pointer(node_id=node_id, ).save()
    ptr.proxy.execution.set(exc)

    return ptr