public async Task <ITask> GetTask(CancellationToken token)
        {
            await EnsureInit();

            ITransaction tx  = null;
            ITask        ret = null;

            try
            {
                tx = ServiceFabricUtils.CreateTransaction();
                await ServiceFabricUtils.DoWithTimeoutRetry(async() =>
                {
                    var result = await m_queue.TryDequeueAsync(tx, TimeSpan.FromSeconds(10), m_cancel);
                    if (result.HasValue)
                    {
                        ret = Utils.Deserialize <ITask>(result.Value);
                    }
                });

                if (ret == null)
                {
                    tx.Dispose(); return(null);
                }
                m_tx[ret] = tx;
                return(ret);
            }
            catch
            {
                ReleaseTx(ret, tx);
                throw;
            }
        }
예제 #2
0
        /// <inheritdocs/>
        public async Task DeleteEntry(Guid replicaId)
        {
            await EnsureChunkTables();

            using (var tx = ServiceFabricUtils.CreateTransaction())
            {
                await ServiceFabricUtils.DoWithTimeoutRetry(
                    async() => await m_chunktable.TryRemoveAsync(tx, replicaId));
            }
        }
        public async Task PostTask(ITask task)
        {
            await EnsureInit();

            using (var tx = ServiceFabricUtils.CreateTransaction())
            {
                await ServiceFabricUtils.DoWithTimeoutRetry(
                    async() => await m_queue.EnqueueAsync(tx, Utils.Serialize(task), TimeSpan.FromSeconds(10), m_cancel),
                    async() => await m_tagCounter.AddOrUpdateAsync(tx, task.Tag, 1, (k, v) => v + 1),
                    async() => await tx.CommitAsync());
            }
        }
예제 #4
0
        /// <inheritdocs/>
        public async Task SetChunks(Guid replicaId, IEnumerable <Chunk> chunks)
        {
            var payload = Utils.Serialize(chunks.ToArray());

            await EnsureChunkTables();

            using (var tx = ServiceFabricUtils.CreateTransaction())
            {
                await ServiceFabricUtils.DoWithTimeoutRetry(
                    async() => await m_chunktable.SetAsync(tx, replicaId, payload),
                    async() => await tx.CommitAsync());
            }
        }
 public async Task UpdateTask(ITask task)
 {
     if (!m_tx.TryGetValue(task, out var tx))
     {
         return;
     }
     try
     {
         await ServiceFabricUtils.DoWithTimeoutRetry(
             async() => await m_queue.EnqueueAsync(tx, Utils.Serialize(task), TimeSpan.FromSeconds(10), m_cancel),
             async() => await tx.CommitAsync());
     }
     finally
     {
         ReleaseTx(task, tx);
     }
 }
 public async Task RemoveTask(ITask task)
 {
     if (!m_tx.TryGetValue(task, out var tx))
     {
         return;
     }
     try
     {
         await ServiceFabricUtils.DoWithTimeoutRetry(
             async() => await m_tagCounter.AddOrUpdateAsync(tx, task.Tag, _ => 0, (k, v) => v - 1, TimeSpan.FromSeconds(10), m_cancel),
             async() => await tx.CommitAsync());
     }
     finally
     {
         ReleaseTx(task, tx);
     }
 }
        public async Task Wait(Guid tag)
        {
            await EnsureInit();

            await ServiceFabricUtils.DoWithTimeoutRetry(
                async() =>
            {
                using (var tx = ServiceFabricUtils.CreateTransaction())
                {
                    int cnt    = 0;
                    var result = await m_tagCounter.TryGetValueAsync(tx, tag, TimeSpan.FromSeconds(10), m_cancel);
                    if (result.HasValue)
                    {
                        cnt = result.Value;
                    }
                    if (cnt != 0)
                    {
                        throw new TimeoutException();
                    }
                }
            });
        }