Skip to content

Commit

Permalink
added start hooks for augmentors
Browse files Browse the repository at this point in the history
  • Loading branch information
bradygaster committed Feb 28, 2024
1 parent 1bb02c7 commit 71b914c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions Backend/Augmentors/BaseAugmentor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public abstract class BaseAugmentor(SemanticKernelWrapper semanticKernelWrapper,
protected ILogger<BaseAugmentor> logger = logger;

public abstract Task Load();
public virtual Task OnStarted() => Task.CompletedTask;
}
4 changes: 3 additions & 1 deletion Backend/Augmentors/UrlAugmentor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ public class UrlAugmentor(SemanticKernelWrapper semanticKernelWrapper,
private readonly HistoryApiClient historyApiClient = historyApiClient;
private readonly LiveUpdateService liveUpdateService = liveUpdateService;

public override async Task OnStarted() =>
await queueServiceClient.GetQueueClient("incoming-urls").CreateIfNotExistsAsync();

public override async Task Load()
{
var incomingQueueClient = queueServiceClient.GetQueueClient("incoming-urls");
await incomingQueueClient.CreateIfNotExistsAsync();

QueueMessage[] messages = await incomingQueueClient.ReceiveMessagesAsync(maxMessages: 8);

Expand Down
4 changes: 3 additions & 1 deletion Backend/Augmentors/UrlListAugmentor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ public class UrlListAugmentor(
LiveUpdateService liveUpdateService)
: AzureBlobBaseAugmentor(semanticKernelWrapper, logger, blobServiceClient)
{
public override async Task OnStarted() =>
await blobServiceClient.GetBlobContainerClient("incoming-urllist").CreateIfNotExistsAsync();

public override async Task Load()
{
var incomingContainerClient = blobServiceClient.GetBlobContainerClient("incoming-urllist");
await incomingContainerClient.CreateIfNotExistsAsync();

var archivedContainerClient = blobServiceClient.GetBlobContainerClient("archive-urllist");
await archivedContainerClient.CreateIfNotExistsAsync();
Expand Down
6 changes: 6 additions & 0 deletions Backend/Workers/AugmentationWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
await liveUpdateService.ShowSystemUpdate("System is up");
}
}

public override async Task StartAsync(CancellationToken cancellationToken)
{
await urlAugmentor.OnStarted();
await urlListAugmentor.OnStarted();
}
}

0 comments on commit 71b914c

Please sign in to comment.