public async Task AddOrUpdateLeaseAsync(ILease lease) { var tcs = new TaskCompletionSource <bool>(); if (!this.currentlyOwnedPartitions.TryAdd(lease.PartitionId, tcs)) { await this.leaseManager.UpdatePropertiesAsync(lease).ConfigureAwait(false); Logger.DebugFormat("partition {0}: updated", lease.PartitionId); return; } try { var updatedLease = await this.leaseManager.AcquireAsync(lease).ConfigureAwait(false); if (updatedLease != null) { lease = updatedLease; } Logger.InfoFormat("partition {0}: acquired", lease.PartitionId); } catch (Exception) { await this.RemoveLeaseAsync(lease).ConfigureAwait(false); throw; } IPartitionSupervisor supervisor = this.partitionSupervisorFactory.Create(lease); this.ProcessPartition(supervisor, lease).LogException(); }
private async Task ProcessPartition(IPartitionSupervisor partitionSupervisor, ILease lease) { try { await partitionSupervisor.RunAsync(this.shutdownCts.Token).ConfigureAwait(false); } catch (PartitionSplitException ex) { await this.HandleSplitAsync(lease, ex.LastContinuation).ConfigureAwait(false); } catch (TaskCanceledException) { Logger.DebugFormat("partition {0}: processing canceled", lease.PartitionId); } catch (Exception e) { Logger.WarnException("partition {0}: processing failed", e, lease.PartitionId); } await this.RemoveLeaseAsync(lease).ConfigureAwait(false); }