Ejemplo n.º 1
0
 public SocialMsgManager(
     DistributeManager _distributeManager,
     IDistributedCache _distributedCache,
     OryxWebSocketPool _wsPool,
     RabbitMQClient _rabbitMQClient
     )
 {
     distributedCache  = _distributedCache;
     wsPool            = _wsPool;
     rabbitMQClient    = _rabbitMQClient;
     distributeManager = _distributeManager;
 }
Ejemplo n.º 2
0
        //private ConnectionFactory factory;

        public RabbitMQClient(DistributeManager _distributeManager)
        {
            //创建连接工厂
            //引入全局应用ID
            EnvID = _distributeManager.DistributeSystemID;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Start a new reporting task.
        /// </summary>
        /// <param name="taskConfig">Job file json as string</param>
        /// <param name="taskId">Id of the task</param>
        public Guid RunTask(string taskConfig, Guid taskId)
        {
            Task.Run(() =>
            {
                var restTask = new RestTask();

                try
                {
                    logger.Debug($"Start rest task with id {taskId}...");
                    WorkingCount++;
                    taskCounter.Inc(WorkingCount);
                    var restStatus = new RestTaskStatus()
                    {
                        Status = 1, ProcessMessage = "Report job will be started...."
                    };
                    var tokenSource = new CancellationTokenSource();
                    restTask        = new RestTask()
                    {
                        TokenSource = tokenSource, TaskStatus = restStatus, StartTime = DateTime.Now
                    };
                    taskPool.TryAdd(taskId, restTask);

                    restStatus.Status         = 1;
                    restStatus.ProcessMessage = "Report job is running...";
                    var taskFolder            = Path.Combine(Options.TempFolder, taskId.ToString());
                    Directory.CreateDirectory(taskFolder);
                    var jObject      = JObject.Parse(taskConfig) as dynamic;
                    JArray guidArray = jObject?.uploadGuids ?? null;
                    if (guidArray != null)
                    {
                        foreach (var item in guidArray)
                        {
                            var uploadFolder = Path.Combine(Options.TempFolder, item.Value <string>());
                            logger.Debug($"Copy file from {uploadFolder} to {taskFolder}.");
                            CopyFiles(uploadFolder, taskFolder);
                        }
                    }
                    logger.Debug($"The Task {taskId} was started.");
                    var manager = new JobManager(GetJobParameter(taskFolder));
                    manager.Run(taskConfig?.ToString(), taskId.ToString(), tokenSource.Token);

                    restStatus.Status         = 2;
                    restStatus.ProcessMessage = "Report job is distributed...";
                    var jobResults            = GetResults(taskId, true);
                    var distManager           = new DistributeManager();
                    var distResult            = distManager.Run(jobResults, tokenSource.Token);
                    jobResults.ForEach(j => j.Reports.ToList().ForEach(r => r.Data = null));
                    if (distResult != null)
                    {
                        logger.Debug($"Distribute result: '{distResult}'");
                        restStatus.DistributeResult = distResult;
                        restStatus.JsonJobResults   = JsonConvert.SerializeObject(jobResults);
                        restStatus.Status           = 3;
                    }
                    else
                    {
                        logger.Debug("No distribute result.");
                        restStatus.ErrorMessage   = distManager.ErrorMessage;
                        restStatus.JsonJobResults = JsonConvert.SerializeObject(jobResults);
                        restStatus.Status         = -1;
                    }

                    restTask.Finish  = true;
                    restTask.EndTime = DateTime.Now;
                    logger.Debug($"Cleanup old rest tasks...");
                    Cleanup();
                    WorkingCount--;
                    taskCounter.Inc(WorkingCount);
                    logger.Debug($"The Task {taskId} was finished.");
                }
                catch (Exception ex)
                {
                    logger.Error(ex, $"The rest task '{taskId}' has a fatal error.");
                    if (restTask != null)
                    {
                        restTask.EndTime = DateTime.Now;
                    }
                }
            });
            return(taskId);
        }