Esempio n. 1
0
        public async Task <IActionResult> DeleteMarkSession(
            string markSessionId
            )
        {
            if (string.IsNullOrEmpty(markSessionId))
            {
                return(BadRequest("markSessionId is not specified!"));
            }

            var backgroundJobId = await _markSessionHandler.DeleteMarkSession(markSessionId);

            return(Accepted(
                       value: backgroundJobId
                       ));
        }
        private async Task CleanMarkSessions(
            CancellationToken cancellationToken
            )
        {
            _loggerService.LogStartupInfoEvent("Hosted service started! Attemping to delete legacy mark sessions.");

            try
            {
                var markSessionModels = await _markSessionRepository.GetAll();

                foreach (var markSessionModel in markSessionModels)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }

                    if (markSessionModel.State == MarkSessionModel.StateMarking &&
                        !markSessionModel.IsMarkSessionRecentlyUpdated()
                        )
                    {
                        try
                        {
                            await _markSessionHandler.DeleteMarkSession(markSessionModel.Id.ToString());
                        }
                        catch (Exception e)
                        {
                            _loggerService.LogStartupErrorEvent(e);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _loggerService.LogStartupErrorEvent(e);
            }

            _loggerService.LogStartupInfoEvent("Hosted service stopped!");
        }