Ejemplo n.º 1
0
        public override void RemoveServer(string serverId)
        {
            if (serverId == null)
            {
                throw new ArgumentNullException(nameof(serverId));
            }

            // TODO: move to stored procedure
            Entities.Server server = Storage.Client.CreateDocumentQuery <Entities.Server>(Storage.Collections.ServerDocumentCollectionUri, QueryOptions)
                                     .Where(s => s.ServerId == serverId)
                                     .AsEnumerable()
                                     .FirstOrDefault();

            if (server != null)
            {
                Storage.Client.DeleteDocumentWithRetriesAsync(server.SelfLink).GetAwaiter().GetResult();
            }
        }
Ejemplo n.º 2
0
        public override void AnnounceServer(string serverId, ServerContext context)
        {
            if (serverId == null)
            {
                throw new ArgumentNullException(nameof(serverId));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // TODO: move to stored procedure
            Entities.Server server = Storage.Client.CreateDocumentQuery <Entities.Server>(Storage.Collections.ServerDocumentCollectionUri, QueryOptions)
                                     .Where(s => s.ServerId == serverId)
                                     .AsEnumerable()
                                     .FirstOrDefault();

            if (server != null)
            {
                server.LastHeartbeat = DateTime.UtcNow;
                server.Workers       = context.WorkerCount;
                server.Queues        = context.Queues;
            }
            else
            {
                server = new Entities.Server
                {
                    ServerId      = serverId,
                    Workers       = context.WorkerCount,
                    Queues        = context.Queues,
                    CreatedOn     = DateTime.UtcNow,
                    LastHeartbeat = DateTime.UtcNow
                };
            }

            Storage.Client.UpsertDocumentWithRetriesAsync(Storage.Collections.ServerDocumentCollectionUri, server).GetAwaiter().GetResult();
        }