Esempio n. 1
0
        public static ShutdownDelaySemaphore GetInstance()
        {
            if (_instance == null)
            {
                _instance = new ShutdownDelaySemaphore();
            }

            return(_instance);
        }
Esempio n. 2
0
        protected override void OnLockAcquired()
        {
            if (ScmHostingConfigurations.FunctionsSyncTriggersDelayBackground)
            {
                shutdownDelayed = ShutdownDelaySemaphore.GetInstance().Acquire(_traceFactory.GetTracer());
            }
            else
            {
                OperationManager.SafeExecute(() => {
                    // Create Sentinel file for DWAS to check
                    // DWAS will check for presence of this file incase a an app setting based recycle needs to be performed in middle of deployment
                    // If this is present, DWAS will postpone the recycle so that deployment goes through first
                    if (!String.IsNullOrEmpty(siteRoot))
                    {
                        FileSystemHelpers.CreateDirectory(Path.Combine(siteRoot, @"ShutdownSentinel"));
                        string sentinelPath = Path.Combine(siteRoot, @"ShutdownSentinel\Sentinel.txt");

                        if (!FileSystemHelpers.FileExists(sentinelPath))
                        {
                            var file = FileSystemHelpers.CreateFile(sentinelPath);
                            file.Close();
                        }

                        // DWAS checks if write time of this file is in the future then only postpones the recycle
                        FileInfoBase sentinelFileInfo     = FileSystemHelpers.FileInfoFromFileName(sentinelPath);
                        sentinelFileInfo.LastWriteTimeUtc = DateTime.UtcNow.AddMinutes(20);
                    }
                });
            }

            IRepositoryFactory repositoryFactory = RepositoryFactory;

            if (repositoryFactory != null)
            {
                IRepository repository = repositoryFactory.GetRepository();
                if (repository != null)
                {
                    // Clear any left over repository-related lock since we have the actual lock
                    repository.ClearLock();
                }
            }
        }
Esempio n. 3
0
        protected override void OnLockRelease()
        {
            base.OnLockRelease();

            if (ScmHostingConfigurations.FunctionsSyncTriggersDelayBackground && shutdownDelayed)
            {
                ShutdownDelaySemaphore.GetInstance().Release(_traceFactory.GetTracer());
            }
            else
            {
                OperationManager.SafeExecute(() => {
                    // Delete the Sentinel file to signal DWAS that deployment is complete
                    if (!String.IsNullOrEmpty(siteRoot))
                    {
                        string sentinelPath = Path.Combine(siteRoot, @"ShutdownSentinel\Sentinel.txt");

                        if (FileSystemHelpers.FileExists(sentinelPath))
                        {
                            FileSystemHelpers.DeleteFile(sentinelPath);
                        }
                    }
                });
            }
        }