예제 #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());
        }
        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();
            }
        }
        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)));
        }