コード例 #1
0
        public async Task OnPost()
        {
            if (ModsetName != null)
            {
                _hangfireManager.ScheduleJob <ServerStartupService>(
                    x => x.StartServer(ModsetName, CancellationToken.None));
            }
            else
            {
                if (MissionTitle is null)
                {
                    throw new Exception("Mission with no name selected.");
                }

                _hangfireManager.ScheduleJob <ServerStartupService>(
                    x => x.StartServerForMission(MissionTitle, CancellationToken.None));
            }

            // Reload all data to prevent user having to refresh
            await OnGet();
        }
コード例 #2
0
        public async Task <Result> PerformMaintenance(CancellationToken cancellationToken)
        {
            var serverShutdownJob = _hangfireManager.ScheduleJob <ServerStartupService>(x => x.ShutdownServer(2302, false, CancellationToken.None));

            var missionsPreparationJob = BackgroundJob.ContinueJobWith <IMissionPreparationService>(
                serverShutdownJob.Value,
                x => x.PrepareForUpcomingMissions(CancellationToken.None));

            var startServerForNextMissionJob = BackgroundJob.ContinueJobWith <IMissionPreparationService>(
                missionsPreparationJob,
                x => x.StartServerForNearestMission(CancellationToken.None));

            return(Result.Success());
        }
コード例 #3
0
        public void ScheduleJob_OtherJobExistsDateTimeNull_JobQueued()
        {
            var otherScheduledJob =
                PrepareQueuedOrScheduledJob <ScheduledJobDto, DummyClass>(DummyClassSecondMethodName, DateTime.Now);
            var scheduledJobList = PrepareJobList(new[] { otherScheduledJob });

            AddScheduledJobs(scheduledJobList);

            var result = _hangfireManager.ScheduleJob <DummyClass>(x => x.DoNothing(CancellationToken.None));

            using (new AssertionScope())
            {
                result.ShouldBeSuccess();
                AssertScheduleCalled(Times.Never());
                AssertEnqueueCalled();
            }
        }
コード例 #4
0
        public IActionResult StartServer([FromBody] ServerStartRequest startRequest)
        {
            var serverShutdownJob = _hangfireManager
                                    .ScheduleJob <ServerStartupService>(
                x => x.ShutdownServer(
                    startRequest.Port,
                    false,
                    CancellationToken.None),
                startRequest.ScheduleAt);

            if (serverShutdownJob.IsFailure)
            {
                return(Problem(serverShutdownJob.Error));
            }

            var result = _hangfireManager.ContinueJobWith <ServerStartupService>(
                serverShutdownJob.Value,
                x => x.StartServer(startRequest.ModsetName, CancellationToken.None));

            return(result.Match(
                       onSuccess: Accepted,
                       onFailure: error => (IActionResult)BadRequest(error)));
        }
コード例 #5
0
        public IActionResult UpdateMods([FromBody] ModsUpdateRequest modsUpdateRequest)
        {
            var serverShutdownJob = _hangfireManager
                                    .ScheduleJob <ServerStartupService>(
                x => x.ShutdownServer(2302, false, CancellationToken.None),
                modsUpdateRequest.ScheduleAt);

            if (serverShutdownJob.IsFailure)
            {
                return(Problem(serverShutdownJob.Error));
            }

            var result = modsUpdateRequest.ModsetName is null
                ? _hangfireManager.ContinueJobWith <ModsUpdateService>(
                serverShutdownJob.Value,
                x => x.UpdateAllMods(CancellationToken.None))
                : _hangfireManager.ContinueJobWith <ModsUpdateService>(
                serverShutdownJob.Value,
                x => x.UpdateModset(modsUpdateRequest.ModsetName, CancellationToken.None));

            return(result.Match(
                       onSuccess: Accepted,
                       onFailure: error => (IActionResult)BadRequest(error)));
        }