public async Task <ReminderEntry> ReadRow(GrainReference grainRef, string reminderName) { try { var response = await ExecuteWithRetries(async() => { var pk = new PartitionKey(ReminderEntity.ConstructPartitionKey(this._serviceId, grainRef)); ItemResponse <ReminderEntity> response = null; try { response = await this._container.ReadItemAsync <ReminderEntity>( ReminderEntity.ConstructId(grainRef, reminderName), pk); } catch (CosmosException ce) when(ce.StatusCode == HttpStatusCode.NotFound) { return(null); } return(response.Resource); }).ConfigureAwait(false); return(response != null?this.FromEntity(response) : null); } catch (Exception exc) { this._logger.LogError(exc, $"Failure reading reminder {reminderName} for service {this._serviceId} and grain {grainRef.ToKeyString()}."); throw; } }
public async Task <bool> RemoveRow(GrainReference grainRef, string reminderName, string eTag) { try { var response = await ExecuteWithRetries(() => { var pk = new PartitionKey(ReminderEntity.ConstructPartitionKey(this._serviceId, grainRef)); return(this._container.DeleteItemAsync <ReminderEntity>( ReminderEntity.ConstructId(grainRef, reminderName), pk, new ItemRequestOptions { IfMatchEtag = eTag } )); }).ConfigureAwait(false); return(true); } catch (CosmosException dce) when(dce.StatusCode == HttpStatusCode.PreconditionFailed) { return(false); } catch (Exception exc) { this._logger.LogError(exc, $"Failure removing reminders for Service {this._serviceId} with grainId {grainRef.ToKeyString()} and name {reminderName}."); throw; } }
private ReminderEntity ToEntity(ReminderEntry entry) { return(new ReminderEntity { Id = ReminderEntity.ConstructId(entry.GrainRef, entry.ReminderName), PartitionKey = ReminderEntity.ConstructPartitionKey(this._serviceId, entry.GrainRef), ServiceId = this._serviceId, GrainHash = entry.GrainRef.GetUniformHashCode(), GrainId = entry.GrainRef.ToKeyString(), Name = entry.ReminderName, StartAt = entry.StartAt, Period = entry.Period }); }