File tree Expand file tree Collapse file tree
src/Infrastructure/BotSharp.Core.Crontab/Services Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -116,6 +116,8 @@ public async Task ScheduledTimeArrived(CrontabItem item)
116116 {
117117 _logger . LogDebug ( $ "ScheduledTimeArrived { item } ") ;
118118
119+ if ( ! await HasEnabledTriggerRule ( item ) ) return ;
120+
119121 await HookEmitter . Emit < ICrontabHook > ( _services , async hook =>
120122 {
121123 if ( hook . Triggers == null || hook . Triggers . Contains ( item . Title ) )
@@ -127,4 +129,25 @@ await HookEmitter.Emit<ICrontabHook>(_services, async hook =>
127129 }
128130 } , item . AgentId ) ;
129131 }
132+
133+ /// <summary>
134+ /// Returns whether the trigger is treated as enabled for this schedule: <c>true</c> unless a rule with the
135+ /// same trigger name exists and is explicitly disabled (opt-out). Missing rules do not block.
136+ /// </summary>
137+ private async Task < bool > HasEnabledTriggerRule ( CrontabItem item )
138+ {
139+ var agentService = _services . GetRequiredService < IAgentService > ( ) ;
140+ // No agent context: do not gate (legacy / callers without AgentId).
141+ if ( string . IsNullOrEmpty ( item . AgentId ) ) return true ;
142+
143+ var agent = await agentService . GetAgent ( item . AgentId ) ;
144+ if ( agent == null )
145+ {
146+ _logger . LogWarning ( "Agent {AgentId} is not found" , item . AgentId ) ;
147+ return false ;
148+ }
149+
150+ // Opt-out only: block when a matching trigger rule exists and Disabled is true.
151+ return ! agent . Rules . Any ( r => r . TriggerName == item . Title && r . Disabled ) ;
152+ }
130153}
You can’t perform that action at this time.
0 commit comments