Beispiel #1
0
        public ConcurrentTaskExecution(IDistributedMutex distributedMutex, IKernel kernel, IRuntimeSettings settings)
        {
            _distributedMutex = distributedMutex;
            _kernel           = kernel;

            _defaultConfiguration = DefaultConfiguration(settings, out _preventConcurrentTaskExecutionOnAllTasks);
        }
Beispiel #2
0
        private void Initialize(WorkflowHost host, string templateData)
        {
            _log   = ClassLogger.Create(GetType());
            _dblog = DebugOnlyLogger.Create(_log);

            _host = host;


            _workspaceContainerName = WorkflowShared.WorkflowInstanceWorkspaceName(Id);

            Workspace = Catalog.Preconfigure()
                        .Add(WorkspaceLocalConfig.WorkspaceName, _workspaceContainerName)
                        .ConfiguredResolve <IWorkspace>(_workflowWorkspaceKey);


            if (null == _wfLock)
            {
                _wfLock = ConstructLock(Id);
            }



            SpecifyUsingTemplate(templateData);

            var instance = new WorkflowInstanceInfo
            {
                Id                 = Id,
                TemplateName       = Name,
                LastActivity       = DateTime.UtcNow,
                NextActivationTime = DateTime.UtcNow,
                Status             = WorkflowStatus.Active.ToString(),
            };

            _instanceData.Store(instance);
        }
Beispiel #3
0
        private WorkflowAgent(WorkflowHost host, string existing, CancellationToken ct, IDistributedMutex dm,
                              string templateData, string workflowDataRepositoryKey, string workflowMessagingKey, string workflowWorkspaceKey)
        {
            Id      = existing;
            _ct     = ct;
            _wfLock = dm;

            _workflowDataRepositoryKey = workflowDataRepositoryKey;
            _workflowWorkspaceKey      = workflowWorkspaceKey;

            _instanceData = Catalog.Preconfigure().ConfigureWorkflowDataRepository <WorkflowInstanceInfo>()
                            .ConfiguredResolve <IDataRepositoryService <WorkflowInstanceInfo,
                                                                        WorkflowInstanceInfo,
                                                                        DataEnvelope <WorkflowInstanceInfo, NoMetadata>,
                                                                        NoMetadata,
                                                                        DatumEnvelope <WorkflowInstanceInfo, NoMetadata>,
                                                                        NoMetadata> >
                                (_workflowDataRepositoryKey);

            _triggers = Catalog.Preconfigure().ConfigureWorkflowDataRepository <WorkflowTrigger>()
                        .ConfiguredResolve <IDataRepositoryService <WorkflowTrigger,
                                                                    WorkflowTrigger,
                                                                    DataEnvelope <WorkflowTrigger, NoMetadata>,
                                                                    NoMetadata,
                                                                    DatumEnvelope <WorkflowTrigger, NoMetadata>,
                                                                    NoMetadata> >
                            (_workflowDataRepositoryKey);

            Initialize(host, templateData);
        }
Beispiel #4
0
        static Task PushPackageAsync([NotNull] INugetService nugetService, [NotNull] ISnapFilesystem filesystem,
                                     [NotNull] IDistributedMutex distributedMutex, [NotNull] INuGetPackageSources nugetSources,
                                     [NotNull] PackageSource packageSource, SnapChannel channel, [NotNull] string packageAbsolutePath,
                                     CancellationToken cancellationToken,
                                     [NotNull] ILog logger)
        {
            if (nugetService == null)
            {
                throw new ArgumentNullException(nameof(nugetService));
            }
            if (filesystem == null)
            {
                throw new ArgumentNullException(nameof(filesystem));
            }
            if (distributedMutex == null)
            {
                throw new ArgumentNullException(nameof(distributedMutex));
            }
            if (nugetSources == null)
            {
                throw new ArgumentNullException(nameof(nugetSources));
            }
            if (packageSource == null)
            {
                throw new ArgumentNullException(nameof(packageSource));
            }
            if (packageAbsolutePath == null)
            {
                throw new ArgumentNullException(nameof(packageAbsolutePath));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            if (!filesystem.FileExists(packageAbsolutePath))
            {
                throw new FileNotFoundException(packageAbsolutePath);
            }

            var packageName = filesystem.PathGetFileName(packageAbsolutePath);

            return(SnapUtility.RetryAsync(async() =>
            {
                if (!distributedMutex.Acquired)
                {
                    throw new Exception("Distributed mutex has expired. This is most likely due to intermittent internet connection issues " +
                                        "or another user is attempting to publish a new version. Please retry pack operation.");
                }

                logger.Info($"Pushing {packageName} to channel {channel.Name} using package source {packageSource.Name}");
                var pushStopwatch = new Stopwatch();
                pushStopwatch.Restart();
                await nugetService.PushAsync(packageAbsolutePath, nugetSources, packageSource, null, cancellationToken: cancellationToken);
                logger.Info($"Pushed {packageName} to channel {channel.Name} using package source {packageSource.Name} in {pushStopwatch.Elapsed.TotalSeconds:0.0}s.");
            }));
        }
Beispiel #5
0
 public void Dispose()
 {
     if (!_isDisposed)
     {
         _wfLock.Release();
         _wfLock = null;
         _bumpEvent.Dispose();
         _isDisposed = true;
     }
 }
Beispiel #6
0
        public override int ProcessItems()
        {
            if (_paused)
            {
                return(0);
            }

            _jobsMutex = Catalog.Preconfigure()
                         .Add(DistributedMutexLocalConfig.Name, ScheduledItem.MutexName)
                         .ConfiguredResolve <IDistributedMutex>();

            try
            {
                if (_jobsMutex.Wait(TimeSpan.FromMinutes(4)))
                {
                    var dueCount = 0;

                    using (_jobsMutex)
                    {
                        if (_jobsMutex.Open())
                        {
                            _dblog.InfoFormat("Worker {0} processing scheduled jobs",
                                              _hostEnv.GetCurrentHostIdentifier(
                                                  HostEnvironmentConstants.DefaultHostScope));


                            var due = _jobScheduler.GetDue();
                            dueCount = due.Count();

                            _log.InfoFormat("Processing {0} due jobs", due.Count());

                            foreach (var item in due)
                            {
                                _token.ThrowIfCancellationRequested();

                                _dblog.InfoFormat("Job due, starting {1} {2} : {0}", item.Message, item.Type, item.Route);
                                _jobScheduler.Reschedule(item);

                                var message = JsonConvert.DeserializeObject(item.Message, item.Type);
                                _sender.Send(message, item.Route);
                            }
                        }
                    }

                    return(dueCount);
                }
            }
            catch (Exception ex)
            {
                _log.ErrorFormat(string.Format("An Exception was Caught in {0} ERROR: {1}", this.GetType().Name, ex.Message));
            }

            return(0);
        }
        private const int DefaultTime = 30;//seconds

        public EsentBlobContainer()
        {
            var cf = Catalog.Factory.Resolve <IConfig>(SpecialFactoryContexts.Routed);

            _host      = cf[BlobContainerLocalConfig.ContainerHost];
            _container = cf[BlobContainerLocalConfig.ContainerName];

            _path = new Uri(string.Format("file:///{0}", Path.Combine(_host, _container))).LocalPath;

            mutex = Catalog.Preconfigure().Add(DistributedMutexLocalConfig.Name, "ApplicationDeployments").ConfiguredResolve <IDistributedMutex>();

            if (mutex.Wait(TimeSpan.FromSeconds(DefaultTime)))
            {
                _persistentDictionary = new Microsoft.Isam.Esent.Collections.Generic.PersistentDictionary <string, string>(_path);
                mutex.Release();
            }
            else
            {
                throw new TimeoutException("ApplicationDeployments Mutex Timeout");
            }
        }
Beispiel #8
0
        static async Task PushPackagesAsync([NotNull] PackOptions packOptions, [NotNull] ILog logger, [NotNull] ISnapFilesystem filesystem,
                                            [NotNull] INugetService nugetService, [NotNull] ISnapPackageManager snapPackageManager, [NotNull] IDistributedMutex distributedMutex, [NotNull] SnapAppsReleases snapAppsReleases,
                                            [NotNull] SnapApp snapApp, [NotNull] SnapChannel snapChannel,
                                            [NotNull] List <string> packages, CancellationToken cancellationToken)
        {
            if (packOptions == null)
            {
                throw new ArgumentNullException(nameof(packOptions));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (filesystem == null)
            {
                throw new ArgumentNullException(nameof(filesystem));
            }
            if (nugetService == null)
            {
                throw new ArgumentNullException(nameof(nugetService));
            }
            if (snapPackageManager == null)
            {
                throw new ArgumentNullException(nameof(snapPackageManager));
            }
            if (distributedMutex == null)
            {
                throw new ArgumentNullException(nameof(distributedMutex));
            }
            if (snapAppsReleases == null)
            {
                throw new ArgumentNullException(nameof(snapAppsReleases));
            }
            if (snapApp == null)
            {
                throw new ArgumentNullException(nameof(snapApp));
            }
            if (snapChannel == null)
            {
                throw new ArgumentNullException(nameof(snapChannel));
            }
            if (packages == null)
            {
                throw new ArgumentNullException(nameof(packages));
            }
            if (packages.Count == 0)
            {
                throw new ArgumentException("Value cannot be an empty collection.", nameof(packages));
            }

            logger.Info('-'.Repeat(TerminalBufferWidth));

            var pushDegreeOfParallelism = Math.Min(Environment.ProcessorCount, packages.Count);

            var nugetSources          = snapApp.BuildNugetSources(filesystem.PathGetTempPath());
            var pushFeedPackageSource = nugetSources.Items.Single(x => x.Name == snapChannel.PushFeed.Name);

            if (pushFeedPackageSource.IsLocalOrUncPath())
            {
                filesystem.DirectoryCreateIfNotExists(pushFeedPackageSource.SourceUri.AbsolutePath);
            }

            if (snapChannel.UpdateFeed.HasCredentials())
            {
                if (!logger.Prompt("y|yes", "Update feed contains credentials. Do you want to continue? [y|n]", infoOnly: packOptions.YesToAllPrompts))
                {
                    logger.Error("Publish aborted.");
                    return;
                }
            }

            logger.Info("Ready to publish application!");

            logger.Info($"Id: {snapApp.Id}");
            logger.Info($"Rid: {snapApp.Target.Rid}");
            logger.Info($"Channel: {snapChannel.Name}");
            logger.Info($"Version: {snapApp.Version}");
            logger.Info($"Feed name: {snapChannel.PushFeed.Name}");

            if (!logger.Prompt("y|yes", "Are you ready to push release upstream? [y|n]", infoOnly: packOptions.YesToAllPrompts))
            {
                logger.Error("Publish aborted.");
                return;
            }

            var stopwatch = new Stopwatch();

            stopwatch.Restart();

            logger.Info($"Pushing packages to default channel: {snapChannel.Name}. Feed: {snapChannel.PushFeed.Name}.");

            await packages.ForEachAsync(async packageAbsolutePath =>
                                        await PushPackageAsync(nugetService, filesystem, distributedMutex,
                                                               nugetSources, pushFeedPackageSource, snapChannel, packageAbsolutePath, logger, cancellationToken), pushDegreeOfParallelism);

            logger.Info($"Successfully pushed {packages.Count} packages in {stopwatch.Elapsed.TotalSeconds:F1}s.");

            var skipInitialBlock = pushFeedPackageSource.IsLocalOrUncPath();

            await BlockUntilSnapUpdatedReleasesNupkgAsync(logger, snapPackageManager, snapAppsReleases,
                                                          snapApp, snapChannel, TimeSpan.FromSeconds(15), cancellationToken, skipInitialBlock, packOptions.SkipAwaitUpdate);
        }
Beispiel #9
0
 public static WorkflowAgent AcquireSleepingOnLocked(IDistributedMutex wfLock, WorkflowHost host, string id,
                                                     CancellationToken ct, string templateData, string wfdrk, string wfmk, string wfwsk)
 {
     return(new WorkflowAgent(host, id, ct, wfLock, templateData, wfdrk, wfmk, wfwsk));
 }