Наследование: Hangfire.Raven.Entities.Identity.BaseEntity
Пример #1
0
        public override void AnnounceServer(string serverId, ServerContext context)
        {
            serverId.ThrowIfNull("serverId");
            context.ThrowIfNull("context");

            var data = new ServerData
            {
                WorkerCount = context.WorkerCount,
                Queues = context.Queues,
                StartedAt = DateTime.UtcNow,
            };

            using (var repository = new Repository()) {
                var servers = repository.Session.Query<RavenServer>()
                                .Where(t => t.Id == serverId)
                                .ToList();

                var queues = servers.SelectMany(t => JobHelper.FromJson<ServerData>(t.Data).Queues).ToList();
                queues.AddRange(data.Queues.Select(t => t).ToList());
                data.Queues = queues.ToArray();

                data.WorkerCount += servers.Select(t => JobHelper.FromJson<ServerData>(t.Data).WorkerCount).Sum(t => t);

                foreach (var item in servers) {
                    repository.Delete(item);
                }

                var server = new RavenServer
                {
                    Data = JobHelper.ToJson(data),
                    Id = serverId,
                    LastHeartbeat = DateTime.UtcNow
                };

                repository.Save(server);
            }
        }
Пример #2
0
        public override void Heartbeat(string serverId)
        {
            serverId.ThrowIfNull("serverId");

            using (var repository = _storage.Repository.OpenSession()) {
                var id = Repository.GetId(typeof(RavenServer), serverId);
                var server = repository.Load<RavenServer>(id);

                if (server == null) {
                    server = new RavenServer {
                        Id = id
                    };
                }

                server.LastHeartbeat = DateTime.UtcNow;

                repository.SaveChanges();
            }
        }
Пример #3
0
        public override void Heartbeat(string serverId)
        {
            serverId.ThrowIfNull("serverId");

            using (var repository = new Repository()) {
                var server = repository.Session.Load<RavenServer>(serverId);

                if (server == null) {
                    server = new RavenServer
                    {
                        Id = serverId
                    };
                }

                server.LastHeartbeat = DateTime.UtcNow;

                repository.Save(server);
            }
        }
Пример #4
0
        public override void AnnounceServer(string serverId, ServerContext context)
        {
            serverId.ThrowIfNull("serverId");
            context.ThrowIfNull("context");

            using (var repository = _storage.Repository.OpenSession()) {
                var id = Repository.GetId(typeof(RavenServer), serverId);
                var server = repository.Load<RavenServer>(id);

                if (server == null) {
                    server = new RavenServer() {
                        Id = id,
                        Data = new RavenServer.ServerData()
                    };

                    repository.Store(server);
                }

                // Merge Queues and WorkerCount
                server.Data.WorkerCount += context.WorkerCount;
                server.Data.Queues = context.Queues.Concat(server.Data.Queues ?? new List<string>()).Distinct();

                server.LastHeartbeat = DateTime.UtcNow;

                repository.SaveChanges();
            }
        }