private async Task <UsersData> EnsureUserDataCreatedAsync() { var created = false; if (!await m_DataStore.ExistsAsync(UsersKey)) { m_CachedUsersData = new UsersData { Users = GetDefaultUsersData() }; await m_DataStore.SaveAsync(UsersKey, m_CachedUsersData); created = true; } m_FileChangeWatcher = m_DataStore.AddChangeWatcher(UsersKey, m_Runtime, () => { if (!m_IsUpdating) { m_CachedUsersData = AsyncHelper.RunSync(LoadUsersDataFromDiskAsync); } m_IsUpdating = false; }); if (!created) { m_CachedUsersData = await LoadUsersDataFromDiskAsync(); } return(m_CachedUsersData); }
public JobScheduler( IRuntime runtime, ILogger <JobScheduler> logger, IDataStoreFactory dataStoreFactory, IOptions <JobExecutorOptions> options) { m_Runtime = runtime; m_Logger = logger; m_DataStore = dataStoreFactory.CreateDataStore(new DataStoreCreationParameters { Component = runtime, LogOnChange = true, WorkingDirectory = runtime.WorkingDirectory }); AsyncHelper.RunSync(ReadJobsFileAsync); m_ScheduledJobs = new List <ScheduledJob>(); m_DataStore.AddChangeWatcher(c_DataStoreKey, runtime, () => { m_ScheduledJobs.Clear(); AsyncHelper.RunSync(() => StartAsync(isFromFileChange: true)); }); m_JobExecutors = new List <ITaskExecutor>(); foreach (var provider in options.Value.JobExecutorTypes) { m_JobExecutors.Add( (ITaskExecutor)ActivatorUtilitiesEx.CreateInstance(runtime.LifetimeScope, provider)); } }
public async Task <RegisteredCommandsData> GetRegisteredCommandsAsync() { if (m_Cache != null) { return(m_Cache); } m_Cache = await LoadCommandsFromDisk(); m_ChangeWatcher = m_DataStore.AddChangeWatcher(CommandsKey, m_Runtime, () => m_Cache = AsyncHelper.RunSync(LoadCommandsFromDisk)); return(m_Cache); }
private async Task MaybeLoadData() { if (m_FileWatcher != null) { return; } m_DataStore = m_Kits.Value.DataStore; await LoadFromDisk(); m_FileWatcher = m_DataStore.AddChangeWatcher(c_CooldownKey, m_Kits.Value, () => AsyncHelper.RunSync(LoadFromDisk)); }
public async Task <RegisteredCommandsData> GetRegisteredCommandsAsync() { if (m_Cache != null) { return(m_Cache); } m_Cache = await LoadCommandsFromDisk(); m_ChangeWatcher = m_DataStore.AddChangeWatcher(CommandsKey, m_Runtime, () => { m_Logger.LogInformation("Commands have been reloaded"); m_Cache = AsyncHelper.RunSync(async() => { var result = await LoadCommandsFromDisk(); await m_CommandStore.Value.InvalidateAsync(); return(result); }); }); return(m_Cache); }