Skip to content

Commit 04bfb2b

Browse files
committed
Allow to update worker and status in a single operation; ensure the worker is updated when an announced task is started
1 parent 64ae3d4 commit 04bfb2b

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

dotNet/CoreHelpers.Extensions.Logging.Tasks/TaskLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public TaskLogger(ITaskLoggerFactory taskLoggerFactory)
5656
_currentTaskLogger = _taskLoggerFactory.CreateTaskLogger(castedState.TaskId);
5757

5858
// ensure the task is running now
59-
_taskLoggerFactory.UpdateTaskStatus(castedState.TaskId, TaskStatus.Running).GetAwaiter().GetResult();
59+
_taskLoggerFactory.UpdateTaskStatus(castedState.TaskId, TaskStatus.Running, castedState.TaskWorker).GetAwaiter().GetResult();
6060

6161
// done
6262
return new TaskLoggerScope(castedState, this);

dotNet/CoreHelpers.Extensions.Logging.Tasks/TaskLoggerExtension.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public static ILoggingBuilder AddTaskLogger(this ILoggingBuilder builder)
1616

1717
public static ITaskLoggerTypedScope? BeginTaskScope(this ILogger logger, string taskId)
1818
=> BeginTypedTaskScope(logger, new TaskLoggerState() { TaskId = taskId, IsTaskAnnounced = true });
19-
20-
public static ITaskLoggerTypedScope? BeginTaskScope(this ILogger logger, string taskId, string metaDataString)
21-
=> BeginTypedTaskScope(logger, new TaskLoggerState() { TaskId = taskId, IsTaskAnnounced = true, MetaData = metaDataString });
19+
20+
public static ITaskLoggerTypedScope? BeginTaskScope(this ILogger logger, string taskId, string taskWorker)
21+
=> BeginTypedTaskScope(logger, new TaskLoggerState() { TaskId = taskId, IsTaskAnnounced = true, TaskWorker = taskWorker });
2222

2323
public static ITaskLoggerTypedScope? BeginNewTaskScope(this ILogger logger, string taskType, string taskSource, string taskWorker)
2424
=> BeginTypedTaskScope(logger, new TaskLoggerState() { TaskId = string.Empty, TaskType = taskType, TaskSource = taskSource, TaskWorker = taskWorker, IsTaskAnnounced = false });

dotNet/CoreHelpers.TaskLogging.Abstractions/ITaskLoggerFactory.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ public interface ITaskLoggerFactory
6464
/// <returns></returns>
6565
Task UpdateTaskStatus(string taskId, TaskStatus taskStatus);
6666

67+
/// <summary>
68+
/// Update the task status of a given task including the worker
69+
/// </summary>
70+
/// <param name="taskId"></param>
71+
/// <param name="taskStatus"></param>
72+
/// <param name="taskWorker"></param>
73+
/// <returns></returns>
74+
Task UpdateTaskStatus(string taskId, TaskStatus taskStatus, string taskWorker);
75+
6776
/// <summary>
6877
/// Allows to update the worker of a task, especially useful for task reassignment
6978
/// </summary>

dotNet/CoreHelpers.TaskLogging/AzureStorageTableTaskLoggerFactory.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,22 @@ public Task<string> AnnounceTask(string taskType, string taskSource, string task
6464

6565
public async Task UpdateTaskStatus(string taskKey, TaskStatus taskStatus)
6666
{
67+
await UpdateTaskStatus(taskKey, taskStatus, string.Empty);
68+
}
69+
70+
public async Task UpdateTaskStatus(string taskKey, TaskStatus taskStatus, string taskWorker)
71+
{
6772
// build the task entity
6873
var taskEntity = new AzureTableTaskEntity()
6974
{
7075
PartitionKey = taskKey,
7176
RowKey = taskKey,
7277
TaskState = taskStatus.ToString()
7378
};
79+
80+
// check the worker
81+
if (!string.IsNullOrEmpty(taskWorker))
82+
taskEntity.TaskWorker = taskWorker;
7483

7584
// adjust the timings
7685
if (taskStatus == TaskStatus.Running)

0 commit comments

Comments
 (0)