mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-06 05:29:40 +00:00
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Sync Flatpak repo (push) Blocked by required conditions
Build and Release / Collect Flatpak artifacts (push) Blocked by required conditions
Build and Release / Verify (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
85 lines
3.3 KiB
C#
85 lines
3.3 KiB
C#
namespace AIStudio.Tools.Services;
|
|
|
|
/// <remarks>
|
|
/// A watcher here is whatever an indexer uses to notice that one of its data sources changed, a file
|
|
/// system watcher for local files, an interval for mailboxes. The indexers own them; this service
|
|
/// only decides when they run.
|
|
/// </remarks>
|
|
public sealed partial class DataSourceEmbeddingService
|
|
{
|
|
/// <summary>
|
|
/// Lets every indexer track changes to its data sources, or stops all tracking.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Tracking runs only while local data sources refresh on their own, and not before the startup
|
|
/// hash check is done.
|
|
/// </remarks>
|
|
private void RefreshWatchers()
|
|
{
|
|
if (!settingsManager.ConfigurationData.App.DataSourceIndexing.AutomaticRefresh)
|
|
{
|
|
this.RemoveAllWatchers();
|
|
return;
|
|
}
|
|
|
|
if (Volatile.Read(ref this.startupHashCheckCompleted) == 0)
|
|
{
|
|
logger.LogDebug("File watchers are not activated yet because the startup persisted hash check has not completed.");
|
|
this.RemoveAllWatchers();
|
|
return;
|
|
}
|
|
|
|
var supportedSources = this.GetConfiguredIndexedSources();
|
|
foreach (var indexer in this.indexers)
|
|
indexer.TrackChanges(supportedSources.Where(indexer.Supports).ToList(), this.RequestRunAsync);
|
|
}
|
|
|
|
private void RemoveWatcher(string dataSourceId)
|
|
{
|
|
foreach (var indexer in this.indexers)
|
|
indexer.StopTracking(dataSourceId);
|
|
}
|
|
|
|
private void RemoveAllWatchers()
|
|
{
|
|
foreach (var indexer in this.indexers)
|
|
indexer.StopTrackingAll();
|
|
}
|
|
|
|
private void DisposeWatchers()
|
|
{
|
|
foreach (var indexer in this.indexers)
|
|
indexer.Dispose();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Queues the run an indexer asked for after it noticed a change, or because its interval came round.
|
|
/// </summary>
|
|
/// <param name="dataSourceId">The id of the data source which changed.</param>
|
|
/// <param name="refreshMode">Why the indexer asks.</param>
|
|
private async Task RequestRunAsync(string dataSourceId, DataSourceEmbeddingRefreshMode refreshMode)
|
|
{
|
|
if (!this.TryGetConfiguredIndexedSource(dataSourceId, out var dataSource))
|
|
return;
|
|
|
|
if (this.statuses.TryGetValue(dataSourceId, out var status) && IsWaitingForSignIn(status))
|
|
{
|
|
logger.LogDebug("Skipped the requested run of data source '{DataSourceId}' because its sign-in failed and waits for the user. RefreshMode={RefreshMode}.", dataSourceId, refreshMode);
|
|
return;
|
|
}
|
|
|
|
await this.QueueDataSourceAsync(dataSource, true, refreshMode);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Whether a data source waits for the user since its sign-in failed.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Then only the user starts its next run, by saving a new password or with a retry. The indexer
|
|
/// would not sign in on any other run either, but every one of them would make the row of the
|
|
/// data source change from failed to queued and back, every interval anew.
|
|
/// </remarks>
|
|
/// <param name="status">The current status of the data source.</param>
|
|
internal static bool IsWaitingForSignIn(DataSourceEmbeddingStatus status) => status.Attention is DataSourceAttention.AUTH_FAILED;
|
|
}
|