You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow specifying the number of tasks to retrieve for a client (#385)
* Allow specifying the number of tasks to retrieve for a client in ClientGetTask method
* Maintain compatibility for older clients by limiting task retrieval to one for versions 1.0 and below
* Update Unregister method to unassign tasks before client removal; add SQL schema change for Publisher column
* Add Verifying status to task enumeration; update SQL schema for Signatures_Roms
* Update Unregister method to unassign tasks based on multiple current statuses
/// Retrieves the next available task for the specified client, or the currently assigned one if it exists.
261
+
/// Retrieves the next available tasks for the specified client. Returns unassigned pending tasks and any tasks already assigned to this client in Assigned or InProgress status.
262
262
/// </summary>
263
263
/// <param name="clientAPIKey">The API key of the client.</param>
264
264
/// <param name="publicId">The public client ID.</param>
// Use a transaction with SELECT FOR UPDATE SKIP LOCKED to prevent race conditions
274
294
// when multiple clients request jobs simultaneously.
275
295
// The FOR UPDATE SKIP LOCKED ensures that each concurrent client gets a different task.
296
+
// Selects: unassigned pending tasks (status=0, client_id IS NULL) OR tasks assigned to this client in Assigned/InProgress status (status=10/20, client_id=@client_id)
276
297
DateTimenow=DateTime.UtcNow;
277
298
278
299
// Step 1: SELECT with FOR UPDATE SKIP LOCKED (locks the row)
stringselectSql=@"SELECT tq.id AS id, tq.create_time AS create_time, tq.dataobjectid AS dataobjectid, tq.task_name AS task_name, tq.status AS status, tq.client_id AS client_id, tq.parameters AS parameters, tq.result AS result, tq.error_message AS error_message, tq.start_time AS start_time, tq.completion_time AS completion_time
282
303
FROM Task_Queue tq
283
304
LEFT JOIN Task_Queue_Capabilities tqc ON tq.id = tqc.task_queue_id
284
-
WHERE tq.status = 0
285
-
AND (tq.client_id IS NULL OR tq.client_id = @client_id)
305
+
WHERE ((tq.status = 0 AND tq.client_id IS NULL) OR ((tq.status = 10 OR tq.status = 20) AND tq.client_id = @client_id))
286
306
AND NOT EXISTS (
287
307
SELECT 1
288
308
FROM Task_Queue_Capabilities tqc_required
@@ -291,7 +311,7 @@ AND tqc_required.capability_id NOT IN (" + string.Join(", ", client.Capabilities
291
311
)
292
312
GROUP BY tq.id
293
313
ORDER BY tq.create_time ASC
294
-
LIMIT 1
314
+
LIMIT "+numberOfTasks+@"
295
315
FOR UPDATE SKIP LOCKED;";
296
316
297
317
// UPDATE using the same logic to identify the task
@@ -308,8 +328,7 @@ SELECT id FROM (
308
328
SELECT tq.id
309
329
FROM Task_Queue tq
310
330
LEFT JOIN Task_Queue_Capabilities tqc ON tq.id = tqc.task_queue_id
311
-
WHERE tq.status = 0
312
-
AND (tq.client_id IS NULL OR tq.client_id = @client_id)
331
+
WHERE ((tq.status = 0 AND tq.client_id IS NULL) OR ((tq.status = 10 OR tq.status = 20) AND tq.client_id = @client_id))
313
332
AND NOT EXISTS (
314
333
SELECT 1
315
334
FROM Task_Queue_Capabilities tqc_required
@@ -318,7 +337,7 @@ AND tqc_required.capability_id NOT IN (" + string.Join(", ", client.Capabilities
Copy file name to clipboardExpand all lines: hasheous-lib/Models/TaskClientModel.cs
+12Lines changed: 12 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -250,6 +250,18 @@ public ClientModel Refresh(DataRow? row = null)
250
250
/// </summary>
251
251
publicasyncTaskUnregister()
252
252
{
253
+
// update the database to unassign any tasks currently assigned to this client
254
+
awaitConfig.database.ExecuteCMDAsync("UPDATE Task_Queue SET client_id = NULL, status = @status WHERE client_id = @id AND status IN (@current_status1, @current_status2, @current_status3, @current_status4, @current_status5)",newDictionary<string,object>
255
+
{
256
+
{"@id",this.Id},
257
+
{"@status",QueueItemStatus.Pending},
258
+
{"@current_status1",QueueItemStatus.Pending},
259
+
{"@current_status2",QueueItemStatus.Assigned},
260
+
{"@current_status3",QueueItemStatus.Verifying},
261
+
{"@current_status4",QueueItemStatus.Failed},
262
+
{"@current_status5",QueueItemStatus.Cancelled}
263
+
});
264
+
253
265
// update the database to remove this client
254
266
awaitConfig.database.ExecuteCMDAsync("DELETE FROM Task_Clients WHERE id = @id",newDictionary<string,object>
0 commit comments