Browse Source

Serialize mismatched args before enqueue

Avoids invalid casts when the provided args are not of runtime type TArgs. The method now checks for a direct TArgs instance and calls EnqueueAsync directly; otherwise it serializes and deserializes the args via Serializer to produce a TArgs instance before enqueuing. This preserves the fast path for matching types while safely handling boxed or different runtime argument representations.
pull/25059/head
SALİH ÖZKARA 3 weeks ago
parent
commit
e615b31924
  1. 8
      framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueue.cs

8
framework/src/Volo.Abp.BackgroundJobs.RabbitMQ/Volo/Abp/BackgroundJobs/RabbitMQ/JobQueue.cs

@ -80,7 +80,13 @@ public class JobQueue<TArgs> : IJobQueue<TArgs>
BackgroundJobPriority priority,
TimeSpan? delay)
{
return await EnqueueAsync((TArgs)args, priority, delay);
if (args is TArgs typedArgs)
{
return await EnqueueAsync(typedArgs, priority, delay);
}
var serializedArgs = Serializer.Serialize(args);
return await EnqueueAsync((TArgs)Serializer.Deserialize(serializedArgs, typeof(TArgs)), priority, delay);
}
public virtual async Task<string?> EnqueueAsync(

Loading…
Cancel
Save