Ejemplo n.º 1
0
        public void FireClients(Common.Job job, string batchId)
        {
            var jobContext = job.ToContext();

            if (Cache.GroupMapConnections.TryGetValue(jobContext.Group, out var connectionInfos))
            {
                bool fired = false;
                foreach (var connectionInfo in connectionInfos)
                {
                    if (Cache.ConnectionIdMapClassNames.TryGetValue(connectionInfo.ConnectionId, out var classNames))
                    {
                        if (classNames.Contains(jobContext.Name))
                        {
                            if (!fired)
                            {
                                fired = true;
                            }
                            Logger.LogInformation($"Fire job {job.Id}, batch {batchId} on clientip {connectionInfo.ClientIp}, connectionid {connectionInfo.ConnectionId}.");
                            _options.InsertJobHistory(batchId, job.Id, connectionInfo.ClientIp, connectionInfo.ConnectionId);
                            _hubContext.Clients.Client(connectionInfo.ConnectionId).SendAsync("Fire", jobContext, batchId);
                        }
                    }
                }

                if (!fired)
                {
                    Logger.LogInformation($"No client watch job {job.Name}.");
                }
            }
            else
            {
                throw new SchedulerNetException("No client connected.");
            }
        }
Ejemplo n.º 2
0
        public void FireClients(Common.Job job, string batchId)
        {
            var jobContext = job.ToContext();

            var connections = _cache.GetConnectionFromGroup(jobContext.Group).AsList();

            if (connections != null && connections.Count > 0)
            {
                bool fired = false;
                foreach (var connection in connections)
                {
                    var classNames = _cache.GetClassNames(connection.Id);

                    if (classNames.Contains(jobContext.Name))
                    {
                        if (!fired)
                        {
                            fired = true;
                        }
                        Logger.LogInformation($"[{connection.RemoteIp}, {connection.Id}] trigger job '{job.Id}', batch '{batchId}', group '{job.Group}'.");
                        _options.InsertJobHistory(batchId, job.Id, connection.RemoteIp, connection.Id);
                        _hubContext.Clients.Client(connection.Id).SendAsync("Fire", jobContext, batchId);
                    }
                }

                if (!fired)
                {
                    Logger.LogInformation($"No client watch job {job.Name}.");
                }
            }
            else
            {
                throw new SchedulerNetException("No client connected.");
            }
        }
Ejemplo n.º 3
0
        public override void Execute(CallbackJob job)
        {
            var batchId = Guid.NewGuid().ToString("N");

            Logger.LogInformation($"Execute callback job {JsonConvert.SerializeObject(job)}, batch {batchId}.");
            _options.InsertJobHistory(batchId, job.Id);
            var msg = new HttpRequestMessage(job.Method, job.Url)
            {
                Content = new StringContent(job.Content, Encoding.UTF8, "application/json")
            };
            var response = Client.SendAsync(msg).Result;

            response.EnsureSuccessStatusCode();
            _options.ChangeJobHistoryStatus(batchId, job.Id, null, null, JobStatus.Success);
        }