Пример #1
0
        public void ExecuteLinkFixJobLinkTextNotRetainedIfNoCustomText()
        {
            var        iConfig         = Utilities.GetIConfigurationRoot();
            var        wikiAccessLogic = new WikiAccessLogic();
            var        log             = Utilities.GetLogger(iConfig, _output);
            var        jobData         = Utilities.GetRequestData(null);
            var        request         = Utilities.GetSampleLinkFixJobRequest();
            var        textFileManager = new TextFileManager();
            var        jobRetriever    = new TextFileJobRetriever(iConfig, "WikiJobTest.txt", textFileManager);
            LinkFixJob job             = (LinkFixJob)WikiJobFactory.GetWikiJob(request, log, wikiAccessLogic, iConfig, jobData, jobRetriever);

            job.Configuration = iConfig;
            job.Execute();
        }
Пример #2
0
        public override void Execute()
        {
            Log.Information("Job retrieval job starting");

            var jobApprovalLogic = new JobApprovalLogic(_userRetriever);
            int offset           = 0;
            int runin            = 5;
            List <JobStatus> statusesToProcess = new List <JobStatus>()
            {
                JobStatus.ToBeProcessed, JobStatus.PreApproved, JobStatus.Approved
            };

            try
            {
                bool requestIsValid   = true;
                var  requestsToUpdate = new List <WikiJobRequest>();
                //Get job definitions
                var requests = _jobRetriever.JobDefinitions?.Where(request => statusesToProcess.Contains(request.Status)).ToList();

                if (requests != null && requests.Count > 0)
                {
                    Log.Information($"Processing {requests.Count} requests");
                    foreach (WikiJobRequest request in requests)
                    {
                        Log.Information($"Processing retrieved request: {request.RawRequest}");
                        try
                        {
                            requestIsValid = true;
                            if (request.Status == JobStatus.ToBeProcessed)
                            {
                                Log.Information("Request is ToBeProcessed");
                                //Check For Automatic Approval
                                CheckForUserApproval(request, jobApprovalLogic);

                                //Save Job
                                JobData.SaveWikiJobRequest(request);

                                //Add to update list
                                requestsToUpdate.Add(request);
                            }
                            else
                            {
                                Log.Information("Request has been previously approved or preapproved");
                                var existingRequest = JobData.GetWikiJobRequestByID(request.ID);
                                requestIsValid = requestIsValid && request.RawRequest.Equals(existingRequest.RawRequest);
                                Log.Information($"Existing request {existingRequest.RawRequest} equals is {requestIsValid}");
                            }

                            if (requestIsValid && (request.Status == JobStatus.Approved || request.Status == JobStatus.PreApproved))
                            {
                                Log.Information("Scheduling request");
                                //Schedule jobs in 10 minute intervals
                                //How to deal with potential page edit overlaps? -> Check page lists and id overlaps;
                                var job = WikiJobFactory.GetWikiJob(request, Log, _wikiAccessLogic, Configuration, JobData, _jobRetriever);
                                JobManager.AddJob(() => job.Execute(), (s) => s.ToRunOnceIn(runin + offset).Minutes());
                                offset = offset + 10;
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex, $"Error processing request {request.RawRequest}:");
                        }
                    }

                    Log.Information("Saving requests");
                    //Update job status on the wiki page the job was retreived from
                    _jobRetriever.UpdateRequests(requestsToUpdate);
                }
                else
                {
                    Log.Information("No requests found.");
                }
                string keepAliveURL = Configuration["KeepAliveURL"];
                if (!string.IsNullOrEmpty(keepAliveURL))
                {
                    Log.Information("Keep Alive");
                    HttpGet(keepAliveURL); //hack to keep IIS server alive
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Error occurred while running JobRetrievalJob:");
            }
        }