Ejemplo n.º 1
0
 private async System.Threading.Tasks.Task ExecuteAsyncWithRetry()
 {
     await ExponentialRetry.ExecuteWithRetry(
         UploadAndAddpackageAndEnsureItIsReady,
         s => s == "",
         maxRetryCount : 3,
         timer : () => ExponentialRetry.Timer(ExponentialRetry.Intervals),
         taskDescription : $"running {nameof(UploadAndAddpackageAndEnsureItIsReady)}");
 }
Ejemplo n.º 2
0
        private async Task <string> UploadAndAddpackageAndEnsureItIsReady()
        {
            try
            {
                Log.LogMessage(
                    MessageImportance.High,
                    "Begin uploading Linux Package to feed service, RepositoryId {0}, Server {1}, Package to upload {2}.",
                    RepositoryId,
                    Server,
                    PathOfPackageToUpload);

                var linuxPackageRepositoryDestiny =
                    new LinuxPackageRepositoryDestiny(Username, Password, Server, RepositoryId);
                var uploadResponse = await new LinuxPackageRepositoryHttpPrepare(
                    linuxPackageRepositoryDestiny,
                    new FileUploadStrategy(PathOfPackageToUpload)).RemoteCall();

                var idInRepositoryService = new IdInRepositoryService(JObject.Parse(uploadResponse)["id"].ToString());

                var addPackageResponse = await new LinuxPackageRepositoryHttpPrepare(
                    linuxPackageRepositoryDestiny,
                    new AddPackageStrategy(
                        idInRepositoryService,
                        PackageNameInLinuxPackageRepository,
                        PackageVersionInLinuxPackageRepository,
                        linuxPackageRepositoryDestiny.RepositoryId)).RemoteCall();

                var queueResourceLocation = new QueueResourceLocation(addPackageResponse);

                Func <Task <string> > pullQueuedPackageStatus = new LinuxPackageRepositoryHttpPrepare(
                    linuxPackageRepositoryDestiny,
                    new PullQueuedPackageStatus(queueResourceLocation)).RemoteCall;

                await ExponentialRetry.ExecuteWithRetry(
                    pullQueuedPackageStatus,
                    s => s == "fileReady",
                    5,
                    () => ExponentialRetry.Timer(ExponentialRetry.Intervals),
                    $"PullQueuedPackageStatus location: {queueResourceLocation.Location}");

                Log.LogMessage(
                    MessageImportance.High,
                    "Upload to feed service is completed, queue resource location {0}",
                    queueResourceLocation.Location);

                return("");
            }
            catch (FailedToAddPackageToPackageRepositoryException e)
            {
                return(e.ToString());
            }
            catch (HttpRequestException e)
            {
                return(e.ToString());
            }
        }