Skip to content

Commit

Permalink
formatting and reduce logging
Browse files Browse the repository at this point in the history
  • Loading branch information
v1r3n committed Jan 2, 2024
1 parent 2e13cdd commit 1a0b38e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
44 changes: 24 additions & 20 deletions Conductor/Client/Worker/WorkflowTaskExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,20 @@ private void Work4Ever(CancellationToken token)

WorkOnce(token);
}
catch (System.OperationCanceledException canceledException)
{
//Do nothing the operation was cancelled
_logger.LogTrace(
$"[{_workerSettings.WorkerId}] Operation Cancelled: {canceledException.Message}"
+ $", taskName: {_worker.TaskType}"
+ $", domain: {_worker.WorkerSettings.Domain}"
+ $", batchSize: {_workerSettings.BatchSize}"
);
Sleep(SLEEP_FOR_TIME_SPAN_ON_WORKER_ERROR);
}
catch (Exception e)
{

_logger.LogError(
$"[{_workerSettings.WorkerId}] worker error: {e.Message}"
+ $", taskName: {_worker.TaskType}"
Expand Down Expand Up @@ -130,28 +142,20 @@ private async void WorkOnce(CancellationToken token)
return new List<Task>();
}

try
{
var tasks = _taskClient.PollTask(_worker.TaskType, _workerSettings.WorkerId, _workerSettings.Domain,
availableWorkerCounter);
if (tasks == null)
{
tasks = new List<Models.Task>();
}

_logger.LogTrace(
$"[{_workerSettings.WorkerId}] Polled {tasks.Count} tasks"
+ $", taskType: {_worker.TaskType}"
+ $", domain: {_workerSettings.Domain}"
+ $", batchSize: {_workerSettings.BatchSize}"
);
return tasks;
}
catch (Exception e)
var tasks = _taskClient.PollTask(_worker.TaskType, _workerSettings.WorkerId, _workerSettings.Domain,
availableWorkerCounter);
if (tasks == null)
{
_logger.LogError($"Error polling for {_worker.TaskType}. Error = {e.Message}");
return new List<Task>();
tasks = new List<Models.Task>();
}

_logger.LogTrace(
$"[{_workerSettings.WorkerId}] Polled {tasks.Count} tasks"
+ $", taskType: {_worker.TaskType}"
+ $", domain: {_workerSettings.Domain}"
+ $", batchSize: {_workerSettings.BatchSize}"
);
return tasks;
}

private async void ProcessTasks(List<Models.Task> tasks, CancellationToken token)
Expand Down
3 changes: 1 addition & 2 deletions Tests/Worker/WorkerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ private async System.Threading.Tasks.Task<ConcurrentBag<string>> StartWorkflows(

private async System.Threading.Tasks.Task ExecuteWorkflowTasks(TimeSpan workflowCompletionTimeout)
{
var host = WorkflowTaskHost.CreateWorkerHost(Microsoft.Extensions.Logging.LogLevel.Debug);
host = WorkflowTaskHost.CreateWorkerHost(Microsoft.Extensions.Logging.LogLevel.Debug, new ClassWorker());
var host = WorkflowTaskHost.CreateWorkerHost(Microsoft.Extensions.Logging.LogLevel.Information, new ClassWorker());
await host.StartAsync();
Thread.Sleep(workflowCompletionTimeout);
await host.StopAsync();
Expand Down
1 change: 0 additions & 1 deletion Tests/Worker/Workers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public static TaskResult SimpleWorker(Conductor.Client.Models.Task task)
public TaskResult LazyWorker(Conductor.Client.Models.Task task)
{
var timeSpan = System.TimeSpan.FromMilliseconds(_random.Next(128, 2048));
Console.WriteLine($"Lazy worker is going to rest for {timeSpan.Milliseconds} ms");
System.Threading.Tasks.Task.Delay(timeSpan).GetAwaiter().GetResult();
return task.Completed();
}
Expand Down

0 comments on commit 1a0b38e

Please sign in to comment.