class AWSAppAutoScalingClient implements AppAutoScalingClient {

    @Override
    public Completable deleteScalableTarget(String jobId) {
        DeregisterScalableTargetRequest deRegisterRequest = new DeregisterScalableTargetRequest();
        deRegisterRequest.setResourceId(
                AWSAppAutoScalingUtil.buildGatewayResourceId(jobId,
                        awsAppScalingConfig.getAWSGatewayEndpointPrefix(),
                        awsAppScalingConfig.getRegion(),
                        awsAppScalingConfig.getAWSGatewayEndpointTargetStage()));
        deRegisterRequest.setServiceNamespace(SERVICE_NAMESPACE);
        deRegisterRequest.setScalableDimension(SCALABLE_DIMENSION);

        return RetryWrapper.wrapWithExponentialRetry(String.format("deleteScalableTarget for job %s", jobId),
                Observable.create(emitter -> awsAppAutoScalingClientAsync.deregisterScalableTargetAsync(deRegisterRequest, new AsyncHandler<DeregisterScalableTargetRequest, DeregisterScalableTargetResult>() {
                    @Override
                    public void onError(Exception exception) {
                        if (exception instanceof ObjectNotFoundException) {
                            logger.info("Scalable target does not exist anymore for job {}", jobId);
                            emitter.onCompleted();
                        } else {
                            logger.error("Deregister scalable target exception {} - {}", jobId, exception.getMessage());
                            awsAppAutoScalingMetrics.registerAwsDeleteTargetError(exception);
                            emitter.onError(exception);
                        }
                    }

                    @Override
                    public void onSuccess(DeregisterScalableTargetRequest request, DeregisterScalableTargetResult deregisterScalableTargetResult) {
                        int httpStatusCode = deregisterScalableTargetResult.getSdkHttpMetadata().getHttpStatusCode();
                        logger.info("De-registered scalable target for {}, status {}", jobId, httpStatusCode);
                        awsAppAutoScalingMetrics.registerAwsDeleteTargetSuccess();
                        emitter.onCompleted();
                    }
                }), Emitter.BackpressureMode.NONE)).toCompletable();
    }

    @Inject public  AWSAppAutoScalingClient(AWSCredentialsProvider awsCredentialsProvider,
                                   AWSAppScalingConfig awsAppScalingConfig,
                                   Registry registry);
    @VisibleForTesting  AWSAppAutoScalingClient(AWSApplicationAutoScalingAsync awsAppAutoScalingClientAsync, AWSAppScalingConfig awsAppScalingConfig, Registry registry);

}