def _move_file(self, filename): s3 = boto3.client('s3', aws_access_key_id=settings.AWS_KEY, aws_secret_access_key=settings.AWS_SECRET) if MoveRequest.objects.filter(filename=filename, status=MoveRequest.STATUS_RUNNING).count(): print("There is already a running task for the file %s" % filename) return True request = MoveRequest.objects.filter(filename=filename, status__in=[MoveRequest.STATUS_ERROR, MoveRequest.STATUS_QUEUED]).first() if not request: request = MoveRequest(filename=filename) request.status = MoveRequest.STATUS_RUNNING request.save() try: s3.copy_object(Key=filename, Bucket=self.move_to, CopySource="%s/%s" % (self.move_from, filename)) s3.delete_object(Bucket=self.move_from, Key=filename) request.status = MoveRequest.STATUS_COMPLETED request.save() except Exception as e: print(e) request.status = MoveRequest.STATUS_ERROR request.save() return False return True
def _move_file(self, s3, filename): if MoveRequest.objects.filter(filename=filename, status=MoveRequest.STATUS_RUNNING).count(): print("There is already a running task for the file %s" % filename) return True request = MoveRequest.objects.filter(filename=filename, status__in=[MoveRequest.STATUS_ERROR, MoveRequest.STATUS_QUEUED]).first() if not request: request = MoveRequest(filename=filename) request.status = MoveRequest.STATUS_RUNNING request.save() try: yield from s3.copy_object(Key=filename, Bucket=self.move_to, CopySource="%s/%s" % (self.move_from, filename)) yield from s3.delete_object(Bucket=self.move_from, Key=filename) request.status = MoveRequest.STATUS_COMPLETED request.save() except Exception as e: print(e) request.status = MoveRequest.STATUS_ERROR request.save() return False return True
def _move_file(self, s3, filename): if MoveRequest.objects.filter( filename=filename, status=MoveRequest.STATUS_RUNNING).count(): print("There is already a running task for the file %s" % filename) return True request = MoveRequest.objects.filter( filename=filename, status__in=[MoveRequest.STATUS_ERROR, MoveRequest.STATUS_QUEUED]).first() if not request: request = MoveRequest(filename=filename) request.status = MoveRequest.STATUS_RUNNING request.save() try: yield from s3.copy_object(Key=filename, Bucket=self.move_to, CopySource="%s/%s" % (self.move_from, filename)) yield from s3.delete_object(Bucket=self.move_from, Key=filename) request.status = MoveRequest.STATUS_COMPLETED request.save() except Exception as e: print(e) request.status = MoveRequest.STATUS_ERROR request.save() return False return True
def _move_file(self, filename): s3 = boto3.client('s3', aws_access_key_id=settings.AWS_KEY, aws_secret_access_key=settings.AWS_SECRET) if MoveRequest.objects.filter( filename=filename, status=MoveRequest.STATUS_RUNNING).count(): print("There is already a running task for the file %s" % filename) return True request = MoveRequest.objects.filter( filename=filename, status__in=[MoveRequest.STATUS_ERROR, MoveRequest.STATUS_QUEUED]).first() if not request: request = MoveRequest(filename=filename) request.status = MoveRequest.STATUS_RUNNING request.save() try: s3.copy_object(Key=filename, Bucket=self.move_to, CopySource="%s/%s" % (self.move_from, filename)) s3.delete_object(Bucket=self.move_from, Key=filename) request.status = MoveRequest.STATUS_COMPLETED request.save() except Exception as e: print(e) request.status = MoveRequest.STATUS_ERROR request.save() return False return True