示例#1
0
    def ready(self):

        # We try until success if dev mode, if it fails the backend will not start
        # In production we let this app fails
        while True:
            try:
                # args is set to empty because fabric-sdk-py doesn't allow None args for invoke operations
                invoke_ledger(fcn='registerNode', args=[''], sync=True)
            except RpcError as e:
                if not settings.DEBUG:
                    raise
                logger.exception(e)
                time.sleep(5)
                logger.info('Retry to register the node to the ledger')
            else:
                logger.info('Node registered in the ledger')
                return
示例#2
0
    def cancel(self, request, pk):
        validate_pk(pk)

        try:
            compute_plan = invoke_ledger(fcn='cancelComputePlan',
                                         args={'key': pk},
                                         only_pkhash=False)
        except LedgerError as e:
            return Response({'message': str(e.msg)}, status=e.status)
        return Response(compute_plan, status=status.HTTP_200_OK)
示例#3
0
def create_ledger_assets(model, fcn, args, pkhashes, sync=False):
    try:
        instances = model.objects.filter(pk__in=pkhashes)
    except ObjectDoesNotExist:
        instances = None

    try:
        data = invoke_ledger(fcn=fcn, args=args, sync=sync)
    except LedgerTimeout:
        # LedgerTimeout herits from LedgerError do not delete
        # In case of timeout we keep the instances if it exists
        raise
    except LedgerError:
        # if not created on ledger, delete from local db
        if instances:
            instances.delete()
        raise

    if instances:
        instances.update(validated=True)
        data['validated'] = True

    return data
示例#4
0
def create_ledger_asset(model, fcn, args, pkhash, sync=False):
    try:
        instance = model.objects.get(pk=pkhash)
    except ObjectDoesNotExist:
        instance = None

    try:
        data = invoke_ledger(fcn=fcn, args=args, sync=sync)
    except LedgerTimeout:
        # LedgerTimeout herits from LedgerError do not delete
        # In case of timeout we keep the instance if it exists
        raise
    except LedgerError:
        # if not created on ledger, delete from local db
        if instance:
            instance.delete()
        raise

    if instance:
        instance.validated = True
        instance.save()
        data['validated'] = True

    return data
示例#5
0
def createLedgerAggregateTuple(args, sync=False):
    return invoke_ledger(fcn='createAggregatetuple', args=args, sync=sync)
示例#6
0
def updateLedgerDataSample(args, sync=False):
    return invoke_ledger(fcn='updateDataSample', args=args, sync=sync)
示例#7
0
def createLedgerTesttuple(args, sync=False):
    return invoke_ledger(fcn='createTesttuple', args=args, sync=sync)
示例#8
0
def createLedgerComputePlan(args, sync=False):
    return invoke_ledger(fcn='createComputePlan', args=args, sync=sync, only_pkhash=False)
示例#9
0
def updateLedgerDataManager(args, sync=False):
    return invoke_ledger(fcn='updateDataManager', args=args, sync=sync)
示例#10
0
def createLedgerCompositeTraintuple(args, sync=False):
    return invoke_ledger(fcn='createCompositeTraintuple', args=args, sync=sync)