예제 #1
0
        /// <summary>
        /// add worker to table and ping to keep alive
        /// </summary>
        protected virtual async Task PingWorker(string activityId, IWorkerInfo worker)
        {
            // if ping was unsuccessful, keep pinging.  this is to address
            // the issue where site continue to run on an unassigned worker.
            if (!_pingResult || _pingWorkerUtc < DateTime.UtcNow)
            {
                // if PingWorker throws, we will not update the worker status
                // this worker will be stale and eventually removed.
                _pingResult = await _eventHandler.PingWorker(activityId, worker);

                _pingWorkerUtc = DateTime.UtcNow.Add(_settings.WorkerPingInterval);
            }

            // check if worker is valid for the site
            if (_pingResult)
            {
                await _table.AddOrUpdate(worker);

                _tracer.TraceUpdateWorker(activityId, worker, string.Format("Worker loadfactor {0} updated", worker.LoadFactor));
            }
            else
            {
                _tracer.TraceWarning(activityId, worker, string.Format("Worker does not belong to the site."));

                await _table.Delete(worker);

                _tracer.TraceRemoveWorker(activityId, worker, "Worker removed");

                throw new InvalidOperationException("The worker does not belong to the site.");
            }
        }
예제 #2
0
        private async Task DeleteAllWorkers(IWorkerTable table)
        {
            var workers = await table.List();

            foreach (var worker in workers)
            {
                await table.Delete(worker);
            }
        }