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
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)
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
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
def createLedgerAggregateTuple(args, sync=False): return invoke_ledger(fcn='createAggregatetuple', args=args, sync=sync)
def updateLedgerDataSample(args, sync=False): return invoke_ledger(fcn='updateDataSample', args=args, sync=sync)
def createLedgerTesttuple(args, sync=False): return invoke_ledger(fcn='createTesttuple', args=args, sync=sync)
def createLedgerComputePlan(args, sync=False): return invoke_ledger(fcn='createComputePlan', args=args, sync=sync, only_pkhash=False)
def updateLedgerDataManager(args, sync=False): return invoke_ledger(fcn='updateDataManager', args=args, sync=sync)
def createLedgerCompositeTraintuple(args, sync=False): return invoke_ledger(fcn='createCompositeTraintuple', args=args, sync=sync)