public async Task Backup(EventActorState eventState) { var error = ""; var handler = HandlersFactory.GetProfilerHandler(_settingService, _loggerService); handler.Start(LOG_TAG, "Backup", null); try { // Enqueue the event to a queue so it can be processed by an Azure function or whatever if (_backupQueue != null) { var queueMessage = new CloudQueueMessage(JsonConvert.SerializeObject(eventState)); await _backupQueue.AddMessageAsync(queueMessage); } } catch (Exception ex) { error = ex.Message; throw new Exception(error); } finally { handler.Stop(error); } }
private async Task SetEntityStateAsync(EventActorState state) { await this.StateManager.SetStateAsync <EventActorState>(ActorStatePropertyName, state); // Just to make sure though it is probably not needed await this.SaveStateAsync(); }
public async Task Reload() { var error = ""; var handler = HandlersFactory.GetProfilerHandler(SettingService, LoggerService); handler.Start(LOG_TAG, "Reload", GetActorProperties()); try { // Given the actor id (which is the event id), re-load the event stats TicketEventStats stats = await DataStoreService.GetEventStats(this.Id.GetStringId()); var state = new EventActorState(stats); // Make sure the state is saved await SetEntityStateAsync(state); } catch (Exception ex) { error = ex.Message; } finally { handler.Stop(error); if (!string.IsNullOrEmpty(error)) { this.HealthReporterService.SendReportForService(HealthState.Error, GetHealthErrorMessage("GetStats", error)); } } }
/// <summary> /// This method is called whenever an actor is activated. /// An actor is activated the first time any of its methods are invoked. /// </summary> protected override async Task OnActivateAsync() { this.ActorLocationService = ServiceFactory.GetInstance().GetActorLocationService(); this.SettingService = ServiceFactory.GetInstance().GetSettingService(); this.LoggerService = ServiceFactory.GetInstance().GetLoggerService(); this.DataStoreService = ServiceFactory.GetInstance().GetDataStoreService(this.SettingService, this.LoggerService); this.HealthReporterService = ServiceFactory.GetInstance().GetHealtheReporterService(this.SettingService, this.LoggerService, ActorService.Context.PartitionId, ActorService.Context.ReplicaId, ActorService.Context.NodeContext.NodeName, ActorService.Context.ServiceName.ToString()); this.ExternalizationService = ServiceFactory.GetInstance().GetExternalizationService(this.SettingService, this.LoggerService); var error = ""; var message = ""; var handler = HandlersFactory.GetProfilerHandler(SettingService, LoggerService); handler.Start(LOG_TAG, "OnActivateAsync", GetActorProperties()); try { EventActorState state = await GetEntityStateAsync(); if (state == null) { await Reload(); } state = await this.StateManager.GetStateAsync <EventActorState>(ActorStatePropertyName); message = string.Format("Event Actor {0} activated", this.Id.GetStringId()); handler.Info(message); handler.Info("Starting a reminder to schedule state backups every " + SettingService.GetActorBackupReminderPeriodicInMinutes() + "mins"); await this.RegisterReminderAsync( BackupReminder, null, TimeSpan.FromMinutes(SettingService.GetActorBackupReminderDueInMinutes()), // Fire initially 5 minutes from now TimeSpan.FromMinutes(SettingService.GetActorBackupReminderPeriodicInMinutes())); // Every 60 minutes periodic firing } catch (Exception ex) { error = ex.Message; } finally { handler.Stop(error); if (!string.IsNullOrEmpty(error)) { this.HealthReporterService.SendReportForService(HealthState.Error, error); } } }