Esempio n. 1
0
        /// <summary>
        /// Empty all the tasks out of the given tenants queue
        /// </summary>
        /// <param name="tenantId"></param>
        /// <returns>The tasks</returns>
        public IEnumerable <BackgroundTask> EmptyQueue(long tenantId)
        {
            var result = new List <BackgroundTask>();

            QueueActioner <BackgroundTask> actioner;

            if (!TenantActioners.TryGetValue(tenantId, out actioner))
            {
                throw new UnknownTenantException(tenantId);
            }

            BackgroundTask next = null;

            do
            {
                next = actioner.Queue.Dequeue();

                if (next != null)
                {
                    result.Add(next);
                }
            } while (next != null);

            return(result);
        }
Esempio n. 2
0
        public void EnqueueTask(long tenantId, BackgroundTask task)
        {
            QueueActioner <BackgroundTask> actioner;

            if (!TenantActioners.TryGetValue(tenantId, out actioner))
            {
                throw new UnknownTenantException(tenantId);
            }

            actioner.Queue.Enqueue(task);
        }
Esempio n. 3
0
 /// <summary>
 /// Get the queue name and lengths
 /// </summary>
 /// <returns></returns>
 public IEnumerable <QueueLengthEntry> QueueLengths()
 {
     return(TenantActioners.Select(entry =>
                                   new QueueLengthEntry
     {
         QueueName = entry.Value.Queue.Name,
         TenantName = TenantHelper.GetTenantName(entry.Key),
         TenantId = entry.Key,
         Length = entry.Value.Queue.Length
     }
                                   ));
 }
Esempio n. 4
0
        /// <summary>
        /// Add a tenant to manage the background tasks of
        /// </summary>
        /// <param name="tenantId"></param>
        public void AddTenant(long tenantId)
        {
            lock (_sync)
            {
                if (!TenantActioners.Keys.Contains(tenantId))
                {
                    var queue = _tenantQueueFactory.Create(tenantId);

                    TenantActioners.Add(tenantId, new QueueActioner <BackgroundTask>(queue, ProcessTask, _perTenantConcurrency));
                }
            }
        }