Skip to content

Commit b6fdd0a

Browse files
committed
lua find fix
1 parent 719b302 commit b6fdd0a

2 files changed

Lines changed: 15 additions & 16 deletions

File tree

Core.TaskProcessor.SampleWebApi/Program.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@
7070

7171
//var discarded = await proc.DiscardDeadTasksAsync("default");
7272

73-
//await proc.UpsertScheduleAsync(new ScheduleData
74-
//{
75-
// Id = "refresh",
76-
// Tenant = "core",
77-
// Queue = "default",
78-
// Cron = "0 */2 * * * *",
79-
// Timezone = "Etc/UTC",
80-
// Unique = true
81-
//}, () => faulty.DoFaultyStuff());
82-
83-
await proc.EnqueueTaskAsync("default", "core", () => faulty.DoFaultyStuff());
73+
await proc.UpsertScheduleAsync(new ScheduleData
74+
{
75+
Id = "refresh",
76+
Tenant = "core",
77+
Queue = "default",
78+
Cron = "*/10 * * * * *",
79+
Timezone = "Etc/UTC",
80+
Unique = true
81+
}, () => svc.DoSomething("test"));
82+
83+
//await proc.EnqueueTaskAsync("default", "core", () => faulty.DoFaultyStuff());
8484
//await proc.EnqueueTaskAsync("default", "core", () => svc.DoSomethingAsync("test", CancellationToken.None));
8585
//await proc.EnqueueTaskAsync("default", "core", () => svc.DoSomethingAsync("test-delay", CancellationToken.None), delayUntil: DateTimeOffset.UtcNow.AddSeconds(5));
8686
}

Core.TaskProcessor/TaskProcessor.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using StackExchange.Redis;
33
using System.Collections.Concurrent;
44
using System.Linq.Expressions;
5-
using System.Threading.Tasks;
65
using System.Threading.Tasks.Dataflow;
76

87
namespace Core.TaskProcessor;
@@ -282,7 +281,7 @@ public async Task<bool> FetchAsync()
282281
var res = await db.ScriptEvaluateAsync($@"
283282
for i, queue in ipairs(KEYS) do
284283
285-
if string.find(queue, '[fair]') then
284+
if string.find(queue, '%[fair%]') ~= nil then
286285
local tenant = redis.call('hrandfield', queue.."":fairness"");
287286
288287
if tenant then
@@ -540,7 +539,7 @@ await db.ScriptEvaluateAsync($@"
540539
for j, w in ipairs(r) do
541540
redis.call('zadd', ""{Prefix("queues")}"", t, v);
542541
543-
if string.find(q, '[fair]') then
542+
if string.find(q, '%[fair%]') ~= nil then
544543
local tenant = redis.call('hget', q..':'..w, 'tenant');
545544
redis.call('hincrby', q..':fairness', tenant);
546545
redis.call('lpush', q..':'..tenant, taskId);
@@ -597,7 +596,7 @@ public async Task<long> RetryDeadTasksAsync(string queue, int? retries = null, l
597596
redis.call('hincrby', '{Prefix("batch:")}'..batchId, 'failed', -1)
598597
redis.call('hset', '{Prefix("batch:")}'..batchId, 'state', 'go')
599598
600-
if string.find(KEYS[1], '[fair]') then
599+
if string.find(KEYS[1], '%[fair%]') ~= nil then
601600
local tenant = redis.call('hget', ""{Prefix("task:")}""..taskId, 'tenant');
602601
redis.call('hincrby', KEYS[1]..':fairness', tenant);
603602
redis.call('lpush', KEYS[1]..':'..tenant, taskId);
@@ -853,7 +852,7 @@ private async Task CompleteBatchAsync(TaskContext task, IDatabase db)
853852
854853
redis.call('zadd', ""{Prefix("queues")}"", t, q);
855854
856-
if string.find(queue, '[fair]') then
855+
if string.find(queue, '%[fair%]') ~= nil then
857856
local tenant = redis.call('hget', '{Prefix("task:")}'..taskId, 'tenant');
858857
redis.call('hincrby', '{Prefix("queue:")}'..q..':fairness', tenant);
859858
redis.call('lpush', '{Prefix("queue:")}'..q..':'..tenant, taskId);

0 commit comments

Comments
 (0)