Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/AI_Brain / sub_brains/money_agents/worker.cs |
| Date | Not specified in source |
| Repository | Janady13/AI_Brain |
| Revision | 6d0767aad08781eb5c4e1eb14a42ec92c437be78 |
| Branch | copilot/convert-python-files-to-csharp |
| Path or archive member | sub_brains/money_agents/worker.cs |
| Original SHA-256 | 53bf70ceb6caff2f79a07e12b8c10a57f03deedffa6cc390cbb0d787c6bf9385 |
| Git blob SHA | 998c5cabe11e99df54eeae814b610832076fff50 |
| Reading-copy SHA-256 | 53bf70ceb6caff2f79a07e12b8c10a57f03deedffa6cc390cbb0d787c6bf9385 |
Recovered source transcript
Download complete source text ↓90 lines · 2.4 KB
// Worker for money agents background tasks
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AIBrain.SubBrains.MoneyAgents
{
public class Worker
{
private bool isRunning;
private Dashboard dashboard;
private List<string> taskQueue;
public Worker(Dashboard dashboard)
{
this.dashboard = dashboard ?? new Dashboard();
this.taskQueue = new List<string>();
this.isRunning = false;
}
public async Task StartAsync(CancellationToken cancellationToken = default)
{
isRunning = true;
Console.WriteLine("Worker started");
while (isRunning && !cancellationToken.IsCancellationRequested)
{
await ProcessTasksAsync();
await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);
}
Console.WriteLine("Worker stopped");
}
public void Stop()
{
isRunning = false;
}
public void QueueTask(string task)
{
taskQueue.Add(task);
Console.WriteLine($"Task queued: {task}");
}
private async Task ProcessTasksAsync()
{
if (taskQueue.Count == 0)
{
return;
}
var tasksToProcess = new List<string>(taskQueue);
taskQueue.Clear();
foreach (var task in tasksToProcess)
{
await ProcessSingleTaskAsync(task);
}
}
private async Task ProcessSingleTaskAsync(string task)
{
Console.WriteLine($"Processing task: {task}");
// Simulate work
await Task.Delay(100);
// Simulate generating revenue
var random = new Random();
var revenue = (decimal)(random.NextDouble() * 100);
dashboard.AddRevenueStream(task, revenue);
Console.WriteLine($"Task completed: {task}, Revenue: ${revenue:F2}");
}
public Dictionary<string, object> GetStatus()
{
return new Dictionary<string, object>
{
["is_running"] = isRunning,
["pending_tasks"] = taskQueue.Count,
["dashboard_summary"] = dashboard.GetDashboardSummary()
};
}
}
}