Skip to content

Commit 0c67ec9

Browse files
author
aden.chen
committed
Enhance CrontabService to log warnings for disabled triggers and update CrontabItemDocument to include TriggerType and ReentryProtection properties.
1 parent e31ef62 commit 0c67ec9

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/Infrastructure/BotSharp.Core.Crontab/Services/CrontabService.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@ public async Task ScheduledTimeArrived(CrontabItem item)
117117
{
118118
_logger.LogDebug($"ScheduledTimeArrived {item}");
119119

120-
if (!await HasEnabledTriggerRule(item)) return;
120+
var triggerEnabled = await HasEnabledTriggerRule(item);
121+
if (!triggerEnabled)
122+
{
123+
_logger.LogWarning("Crontab: {0}, Trigger is not enabled, skipping this occurrence.", item.Title);
124+
return;
125+
}
121126

122127
await HookEmitter.Emit<ICrontabHook>(_services, async hook =>
123128
{

src/Plugins/BotSharp.Plugin.MongoStorage/Collections/CrontabItemDocument.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class CrontabItemDocument : MongoBase
1818
public bool LessThan60Seconds { get; set; } = false;
1919
public IEnumerable<CronTaskMongoElement> Tasks { get; set; } = [];
2020
public DateTime CreatedTime { get; set; } = DateTime.UtcNow;
21+
public int TriggerType { get; set; }
22+
public bool ReentryProtection { get; set; } = true;
2123

2224
public static CrontabItem ToDomainModel(CrontabItemDocument item)
2325
{
@@ -36,7 +38,9 @@ public static CrontabItem ToDomainModel(CrontabItemDocument item)
3638
LastExecutionTime = item.LastExecutionTime,
3739
LessThan60Seconds = item.LessThan60Seconds,
3840
Tasks = item.Tasks?.Select(x => CronTaskMongoElement.ToDomainElement(x))?.ToArray() ?? [],
39-
CreatedTime = item.CreatedTime
41+
CreatedTime = item.CreatedTime,
42+
TriggerType = (CronTabItemTriggerType)item.TriggerType,
43+
ReentryProtection = item.ReentryProtection
4044
};
4145
}
4246

@@ -57,7 +61,9 @@ public static CrontabItemDocument ToMongoModel(CrontabItem item)
5761
LastExecutionTime = item.LastExecutionTime,
5862
LessThan60Seconds = item.LessThan60Seconds,
5963
Tasks = item.Tasks?.Select(x => CronTaskMongoElement.ToMongoElement(x))?.ToList() ?? [],
60-
CreatedTime = item.CreatedTime
64+
CreatedTime = item.CreatedTime,
65+
TriggerType = (int)item.TriggerType,
66+
ReentryProtection = item.ReentryProtection
6167
};
6268
}
6369
}

0 commit comments

Comments
 (0)