Exemplo n.º 1
0
        private void RunTask()
        {
            ISolrResponseObject response = null;

            long lastResponseTime = DateTime.Now.Ticks;

            while (IsRunning)
            {
                //If the previous response was "busy", sleep for a teensy bit before retrying
                if ((response != null) && (response.Status == "busy"))
                {
                    Thread.Sleep(RESPONSE_BUSY_SLEEP_TIME_IN_MS);
                }

                //If we're not yet inside the recurrence interval, sleep for a teensy bit
                if (((DateTime.Now.Ticks - lastResponseTime) / TimeSpan.TicksPerMillisecond) < OperationModel.RecurrenceInterval)
                {
                    Thread.Sleep(OUTSIDE_INTERVAL_SLEEP_TIME_IN_MS);

                    //Set the response to null so we don't resleep
                    response = null;

                    //Restart the loop
                    continue;
                }

                //Execute and get the response
                response = GetSolrResponse(RestClient, OperationModel, out lastResponseTime);

                //If we don't recur, then exit after getting one response
                if (OperationModel.RecurrenceInterval == -1)
                {
                    IsRunning = false;
                }
            }

            _solrLog.AppendJobAction(OperationModel.Name, SolrLogAction.Stop);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the solr response.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="solrOperationModel">The solr operationModel.</param>
        /// <param name="responseTimeInTicks">The response time in ticks.</param>
        /// <returns>SolrScheduler.Objects.Models.SolrResponseObject.</returns>
        private ISolrResponseObject GetSolrResponse(IRestClient client, ISolrOperationModel solrOperationModel, out long responseTimeInTicks)
        {
            //Create request
            IRestRequest request = CreateRequestFromSolrOperation(solrOperationModel);

            //Start the timer and execute the request
            DateTime startResponseTime = DateTime.Now;

            IRestResponse response = client.Execute(request);

            //Get the time it took for the response to resolve
            DateTime stopResponseTime = DateTime.Now;

            responseTimeInTicks = stopResponseTime.Ticks;

            //Return the deserialized response
            ISolrResponseObject solrResponse = JsonConvert.DeserializeObject <SolrResponseObject>(response.Content);

            //Log the action
            _solrLog.AppendSolrAction(startResponseTime, stopResponseTime, solrOperationModel.Name, solrResponse);

            return(solrResponse);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Appends the action to the log stack.
        /// </summary>
        /// <param name="timeStampStarted">The time stamp started.</param>
        /// <param name="timeStampFinished">The time stamp finished.</param>
        /// <param name="operationName">Name of the operation.</param>
        /// <param name="response">The response.</param>
        public void AppendSolrAction(DateTime timeStampStarted, DateTime timeStampFinished, string operationName, ISolrResponseObject response)
        {
            string timeElapsed = $"{(timeStampFinished - timeStampStarted).TotalMilliseconds:0.0000}";

            StringBuilder entry = new StringBuilder();

            entry.Append($"{DateTime.Now}");
            entry.Append(response.Success ? "\tSuccess" : "\tFailed");
            entry.Append($"\t{operationName}");
            entry.Append($"\t{timeElapsed} ms\t");

            if (!string.IsNullOrEmpty(response.ImportResponse))
            {
                entry.Append($"\t{response.ImportResponse}");
            }


            _logCollection.Push(entry.ToString());

            if (_outputToFile)
            {
                WriteLog(operationName, entry.ToString());
            }

            OnLogAction?.Invoke(null);
        }