Beispiel #1
0
        protected override void OnCloseCallback()
        {
            WFCalculateTradeValuation workflow = _activeWorkflow;

            workflow?.Cancel("Server shutdown");
        }
Beispiel #2
0
        private void DequeueWorkerRequests(object notUsed)
        {
            // throttle callbacks to once per timer period
            DateTime dtNow = DateTime.Now;

            if ((dtNow - _lastManagedAt) < _requestManagerPeriod)
            {
                return;
            }
            _lastManagedAt = dtNow;

            try
            {
                // processing algorithm
                // - find oldest unprocessed (status==received) request and process it
                bool workToDo = true;
                while (workToDo && (GetState() == BasicServerState.Running))
                {
                    workToDo = false;
                    InternalTradeRevalRequest activeRequest        = null;
                    DateTimeOffset            oldestRequestCreated = DateTimeOffset.MaxValue;
                    _outstandingRequests.Locked(requests =>
                    {
                        foreach (InternalTradeRevalRequest request in requests.Values)
                        {
                            if ((request.LatestResult.Status == RequestStatusEnum.Received) &&
                                (request.Created < oldestRequestCreated) &&
                                (request.Request != null))
                            {
                                activeRequest        = request;
                                oldestRequestCreated = request.Created;
                            }
                        }
                        if (activeRequest != null)
                        {
                            // we have found a request to process
                            workToDo = true;
                        }
                    });

                    if (activeRequest != null)
                    {
                        // process request
                        TradeValuationRequest request = activeRequest.Request;
                        try
                        {
                            // run the valuation workflow
                            using (var workflow = new WFCalculateTradeValuation())
                            {
                                workflow.Initialise(_workContext);
                                activeRequest.Workflow = workflow;
                                _activeWorkflow        = workflow;
                                try
                                {
                                    WorkflowOutput <HandlerResponse> output = workflow.Execute(request);
                                    WorkflowHelper.LogErrors(Logger, output.Errors);
                                }
                                finally
                                {
                                    activeRequest.Workflow = null;
                                    _activeWorkflow        = null;
                                }
                            }
                        }
                        catch (Exception innerExcp)
                        {
                            Logger.Log(innerExcp);
                            // publish 'faulted' result
                            var response = new HandlerResponse
                            {
                                RequestId   = request.RequestId,
                                RequesterId = request.RequesterId,
                                //RequesterData = request.TradeId,
                                Status      = RequestStatusEnum.Faulted,
                                FaultDetail = new ExceptionDetail(innerExcp)
                            };
                            _workContext.Cache.SaveObject(response);
                        }
                    }
                } // while there is work to do
            }
            catch (Exception outerExcp)
            {
                // deserialisation error?
                Logger.Log(outerExcp);
            }
        }