public ElasticReminderEntry(ReminderEntry entry)
 {
     this.entry = entry;
     UniformHashCode = entry.GrainRef.GetUniformHashCode();
     ReminderName = entry.ReminderName;
     GrainRefKey = entry.GrainRef.ToKeyString();
     Period = entry.Period;
     ETag = entry.ETag ?? "0";
     StartAt = entry.StartAt;
     Id = CreateIdFrom(entry.GrainRef, entry.ReminderName);
 }
 private static async Task<string> UpsertReminder(IReminderTable reminder, GrainReference grainRef, string reminderName, DateTime startAt, TimeSpan period)
 {
     var reminderRow = new ReminderEntry
                       {
                           GrainRef = grainRef,
                           Period = period,
                           StartAt = startAt,
                           ReminderName = reminderName
                       };
     return await reminder.UpsertRow(reminderRow);
 }
Beispiel #3
0
 public ReminderTableData(ReminderEntry entry)
 {
     Reminders = new List <ReminderEntry> {
         entry
     };
 }
 public Task<string> UpsertRow(ReminderEntry entry)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Async method to put an entry into the remider table
        /// </summary>
        /// <param name="entry"> The entry to put </param>
        /// <returns> Return the entry ETag if entry was upsert successfully </returns>
        public async Task<string> UpsertRow(ReminderEntry entry)
        {
            var reminderId = ConstructReminderId(serviceId, entry.GrainRef, entry.ReminderName);

            var fields = new Dictionary<string, AttributeValue>
                {
                    { REMINDER_ID_PROPERTY_NAME, new AttributeValue(reminderId) },
                    { GRAIN_HASH_PROPERTY_NAME, new AttributeValue { N = entry.GrainRef.GetUniformHashCode().ToString() } },
                    { SERVICE_ID_PROPERTY_NAME, new AttributeValue(serviceId.ToString()) },
                    { GRAIN_REFERENCE_PROPERTY_NAME, new AttributeValue( entry.GrainRef.ToKeyString()) },
                    { PERIOD_PROPERTY_NAME, new AttributeValue(entry.Period.ToString()) },
                    { START_TIME_PROPERTY_NAME, new AttributeValue(entry.StartAt.ToString()) },
                    { REMINDER_NAME_PROPERTY_NAME, new AttributeValue(entry.ReminderName) },
                    { ETAG_PROPERTY_NAME, new AttributeValue { N = random.Next(int.MaxValue).ToString() } }
                };

            try
            {
                if (logger.IsVerbose) logger.Verbose("UpsertRow entry = {0}, etag = {1}", entry.ToString(), entry.ETag);

                await storage.PutEntryAsync(TABLE_NAME_DEFAULT_VALUE, fields);
                
                entry.ETag = fields[ETAG_PROPERTY_NAME].N;
                return entry.ETag;
            }
            catch (Exception exc)
            {
                logger.Warn(ErrorCode.ReminderServiceBase,
                    $"Intermediate error updating entry {entry.ToString()} to the table {TABLE_NAME_DEFAULT_VALUE}.", exc);
                throw;
            }
        }
        private async Task TestTableInsertRate(IReminderTable reminderTable, double numOfInserts)
        {
            DateTime startedAt = DateTime.UtcNow;

            try
            {
                List<Task<bool>> promises = new List<Task<bool>>();
                for (int i = 0; i < numOfInserts; i++)
                {
                    //"177BF46E-D06D-44C0-943B-C12F26DF5373"
                    string s = string.Format("177BF46E-D06D-44C0-943B-C12F26D{0:d5}", i);

                    var e = new ReminderEntry
                    {
                        //GrainId = GrainId.GetGrainId(new Guid(s)),
                        GrainRef = GrainReference.FromGrainId(GrainId.NewId()),
                        ReminderName = "MY_REMINDER_" + i,
                        Period = TimeSpan.FromSeconds(5),
                        StartAt = DateTime.UtcNow
                    };

                    int capture = i;
                    Task<bool> promise = Task.Run(async () =>
                    {
                        await reminderTable.UpsertRow(e);
                        Console.WriteLine("Done " + capture);
                        return true;
                    });
                    promises.Add(promise);
                    log.Info("Started " + capture);
                }
                log.Info("Started all, now waiting...");
                await Task.WhenAll(promises).WithTimeout(TimeSpan.FromSeconds(500));
            }
            catch (Exception exc)
            {
                log.Info("Exception caught {0}", exc);
            }
            TimeSpan dur = DateTime.UtcNow - startedAt;
            log.Info("Inserted {0} rows in {1}, i.e., {2:f2} upserts/sec", numOfInserts, dur, (numOfInserts / dur.TotalSeconds));
        }
 internal ReminderEntry GetReminderEntry(string eTag=null)
 {
     entry = new ReminderEntry();
     entry.ETag = eTag ?? ETag;
     entry.GrainRef = GrainReference.FromKeyString(GrainRefKey);
     entry.Period = Period;
     entry.ReminderName = ReminderName;
     entry.StartAt = StartAt;
     return entry;
 }
Beispiel #8
0
 public ReminderTableData(ReminderEntry entry)
 {
     Reminders = new List<ReminderEntry> {entry};
 }
 public void ElasticsearchReminderTable_ReadRow()
 {
     var tableTask = TestReminderTable.Init(ClusterConfig.Globals, SiloHost.Logger);
     tableTask.Wait();
     var new1 = new ReminderEntry() { ETag = null, GrainRef = GrainReference.FromKeyString(ExampleGrainRefKeyString), Period = TimeSpan.FromMinutes(1), ReminderName = "ElasticsearchReminderTable_ReadRow", StartAt = DateTime.UtcNow };
     var upsertTask = TestReminderTable.UpsertRow(new1);
     upsertTask.Wait();
     Assert.IsFalse(String.IsNullOrEmpty(upsertTask.Result));
     var readTask = TestReminderTable.ReadRow(GrainReference.FromKeyString(ExampleGrainRefKeyString), "ElasticsearchReminderTable_ReadRow");
     readTask.Wait();
     Assert.IsTrue(readTask.Result!=null);
 }