optimize CronTabHook
This commit is contained in:
parent
0302ccc9c5
commit
093c681b6d
|
|
@ -1,13 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BotSharp.Core.Crontab.Abstraction
|
||||
{
|
||||
public interface ICrontabAuthenticationHook
|
||||
{
|
||||
void SetUserIdentity(CrontabItem item);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +1,20 @@
|
|||
namespace BotSharp.Core.Crontab.Abstraction;
|
||||
|
||||
public interface ICrontabHook
|
||||
public abstract class ICrontabHook
|
||||
{
|
||||
string[]? Triggers
|
||||
public string[]? Triggers
|
||||
=> null;
|
||||
|
||||
Task OnCronTriggered(CrontabItem item)
|
||||
public virtual void OnAuthenticate(CrontabItem item)
|
||||
{
|
||||
}
|
||||
|
||||
public Task OnCronTriggered(CrontabItem item)
|
||||
=> Task.CompletedTask;
|
||||
|
||||
Task OnTaskExecuting(CrontabItem item)
|
||||
public Task OnTaskExecuting(CrontabItem item)
|
||||
=> Task.CompletedTask;
|
||||
|
||||
Task OnTaskExecuted(CrontabItem item)
|
||||
public Task OnTaskExecuted(CrontabItem item)
|
||||
=> Task.CompletedTask;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,15 +115,12 @@ public class CrontabService : ICrontabService, ITaskFeeder
|
|||
public async Task ScheduledTimeArrived(CrontabItem item)
|
||||
{
|
||||
_logger.LogDebug($"ScheduledTimeArrived {item}");
|
||||
HookEmitter.Emit<ICrontabAuthenticationHook>(_services, hook =>
|
||||
{
|
||||
hook.SetUserIdentity(item);
|
||||
});
|
||||
|
||||
await HookEmitter.Emit<ICrontabHook>(_services, async hook =>
|
||||
{
|
||||
if (hook.Triggers == null || hook.Triggers.Contains(item.Title))
|
||||
{
|
||||
hook.OnAuthenticate(item);
|
||||
await hook.OnTaskExecuting(item);
|
||||
await hook.OnCronTriggered(item);
|
||||
await hook.OnTaskExecuted(item);
|
||||
|
|
|
|||
Loading…
Reference in a new issue