Пример #1
0
        async Task <object> Restarting(object message)
        {
            // we can't directly switch to Preparing upon receive of Restart message,
            // since in Preparing step we delete/create the files which are used
            // in Copying state and so we need to wait until all background jobs
            // are *actually* terminated (or failed)

            switch (message)
            {
            case Activate _:
                if (TerminateAllJobs())
                {
                    await Become(Preparing);
                }
                break;

            case BackgroundJobFailed _:
            case BackgroundJobTerminated _:
                if (!Jobs.Active().Any())
                {
                    await Become(Preparing);
                }
                break;

            default:
                return(Unhandled);
            }

            return(Done);
        }
Пример #2
0
        bool TerminateAllJobs()
        {
            var activeJobs = Jobs.Active();

            if (!activeJobs.Any())
            {
                return(true);
            }

            Array.ForEach(activeJobs, job => job.Terminate());
            return(false);
        }