remove dependency of IEventPublisher in CrontabWatcher
This commit is contained in:
parent
c2f4de14fe
commit
93d1f34786
|
|
@ -46,7 +46,7 @@ public class CrontabWatcher : BackgroundService
|
|||
var cron = services.GetRequiredService<ICrontabService>();
|
||||
var crons = await cron.GetCrontable();
|
||||
|
||||
var publisher = services.GetRequiredService<IEventPublisher>();
|
||||
var publisher = services.GetService<IEventPublisher>();
|
||||
|
||||
foreach (var item in crons)
|
||||
{
|
||||
|
|
@ -88,8 +88,16 @@ public class CrontabWatcher : BackgroundService
|
|||
{
|
||||
_logger.LogInformation($"The current time matches the cron expression {item}");
|
||||
|
||||
await publisher.PublishAsync($"Crontab:{item.Title}", item.Cron);
|
||||
// cron.ScheduledTimeArrived(item);
|
||||
if (publisher != null)
|
||||
{
|
||||
await publisher.PublishAsync($"Crontab:{item.Title}", item.Cron);
|
||||
}
|
||||
else
|
||||
{
|
||||
var scope = _services.CreateScope();
|
||||
cron = scope.ServiceProvider.GetRequiredService<ICrontabService>();
|
||||
cron.ScheduledTimeArrived(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
Loading…
Reference in a new issue