Drools Fusion 有“现在”的概念吗?

发布于 2024-10-12 04:54:55 字数 449 浏览 3 评论 0原文

我正在尝试编写一条规则,延迟触发,直到自上次触发以来至少过去 15 分钟。然而,Drools Fusion 中的时间运算符仅允许推理两个彼此相关的事件,而不允许推理一个与当前时间相关的事件。

我想要这样的事情:

rule "some rule"
when
    not LastFiredEvent(this before[0m, 15m] NOW)
    …

我已经诉诸于编写一个每秒触发并插入一个心跳事件(也撤回先前的心跳)的规则,我可以在其他规则中使用它来充当当前时间。

我觉得这相当不优雅;我是否遗漏了一些东西,或者 Drools Fusion 真的没有这方面的东西吗?

注意。我不是寻找延迟触发的规则或只能触发15分钟倍数的规则;如果过去 17 分钟内没有发生任何事情,则规则必须立即触发以响应新事件。

I'm trying to write a rule that delays firing until, at least, 15 minutes have passed since the last firing. However, the temporal operators in Drools Fusion only allow reasoning about two events in relation to each other and not one event in relation to the current time.

I would like something like this:

rule "some rule"
when
    not LastFiredEvent(this before[0m, 15m] NOW)
    …

I have resorted to writing a rule that fires every second and inserts a heartbeat event (also retracting the previous heartbeat), which I can use in other rules to serve as the current time.

I find this rather inelegant; am I missing something or does Drools Fusion really not have something for this?

NB. I am not looking for delayed firing of rules or rules that can only fire on multiples of 15 minutes; if nothing has happened in the last 17 minutes, the rule must fire immediately in response to a new event.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素染倾城色 2024-10-19 04:54:55

尽管“NOW”的概念乍一看似乎很简单,但事实并非如此,因为它是不明确的,并且取决于它根据运行环境可以采用的不同语义。 Drools Fusion 确实有一个“现在”的概念当您在 STREAM 模式下运行它时,但它与您上面所要求的不同。这里的解释有点长,所以让我们重点关注你的问题。

首先,你说:“我正在尝试编写一个延迟触发的规则......”然后你说:“我不是在寻找延迟触发规则......”,所以我对你需要什么感到困惑。

如果您想延迟规则,您可以使用计时器属性:

rule X
   timer( int: 15m )
...

如果您想在某个时间间隔内发生或未发生事件时触发规则,您可以使用滑动窗口。例如:

rule "Event did not happen in the last 15m"
when
   not( SomeEvent() over time:window(15m) )
...

希望有帮助。顺便说一句,尝试将您的问题发布到 Drools 邮件列表,因为这样您会更容易获得答案。我看到你的帖子只是因为一个朋友向我询问了这件事。

干杯,
埃德森

Although the concept of "NOW" might seem simple at first, it is not, as it is ambiguous and depends on the different semantics it can take based on the running environment. Drools Fusion does have a concept of "NOW" when you run it in STREAM mode, but it is different from what you are asking above. The explanation is a bit long to be done here, so lets focus on your problem.

First, you say: "I'm trying to write a rule that delays firing..." and then your say: "I am not looking for delayed firing of rules...", so I am confused about what you need.

If you want to delay the rule you can use the timer attribute:

rule X
   timer( int: 15m )
...

If you want to fire a rule in case an event did or did not happen within an interval, you can use sliding windows. E.g.:

rule "Event did not happen in the last 15m"
when
   not( SomeEvent() over time:window(15m) )
...

Hope that helps. And BTW, try posting your questions to the Drools mailing list as it will be easier for you to get an answer. I only saw your post because a friend pinged me about it.

Cheers,
Edson

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文