using MassTransit; using Tiku.Application.Jobs; using Tiku.Application.Security; using Tiku.Contracts; namespace Tiku.Infrastructure.Messaging; [ConsumerAuthorizationMetadata( "tenant", "dynamic-job-module", CapabilityOperation.Write, "background_job.execute", RequiresSystemScope = true)] internal sealed class BackgroundJobRequestedConsumer( IBackgroundJobService backgroundJobService, ITenantContextInitializer tenantContextInitializer) : IConsumer { public async Task Consume(ConsumeContext context) { var message = context.Message; tenantContextInitializer.InitializeSystem( message.TenantId, $"RabbitMQ background job {message.JobType}"); await backgroundJobService.ProcessRequestedAsync( message.JobId, message.TenantId, message.JobType, $"rabbitmq:{Environment.MachineName}", context.CancellationToken); } }