Does Drools Fusion have a concept of "now"? - rules

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.

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

Related

Is there a way to define a trigger that runs reliably at a datetime specified as a field in the updated/created object?

The question
Is it possible (and if so, how) to make it so when an object's field x (that contains a timestamp) is created/updated a specific trigger will be called at the time specified in x (probably calling a serverless function)?
My Specific context
In my specific instance the object can be seen as a task. I want to make it so when the task is created a serverless function tries to complete the task and if it doesn't succeed it updates the record with the partial results and specifies in a field x when the next attempt should happen.
The attempts should not span at a fixed interval. For example, a task may require 10 successive attempts at approximately every 30 seconds, but then it may need to wait 8 hours.
There currently is no way to (re)trigger a Cloud Function on a node after a certain timespan.
The closest you can get is by regularly scheduling a cron job to run on the list of tasks. For more on that, see this sample in the function-samples repo, this blog post by Abe, and this video where Jen explains them.
I admit I never like using this cron-job approach, since you have to query the list to find the items to process. A while ago, I wrote a more efficient solution that runs a priority queue in a node process. My code was a bit messy, so I'm not quite ready to share it, but it wasn't a lot (<100 lines). So if the cron-trigger approach doesn't work for you, I recommend investigating that direction.

xProc - Pausing a pipeline and continue it when certain event occurs

I'm fairly new to xProc and xPath, but I've been asked to solve the following problem:
Step 2 receives data via the secondary port from step 1. Step 2 contains a p:for-each, which saves a document into a folder for each element that passes the for-each.
(Part A)
These documents (let's say I receive 6 documents from for-each) lay in the same directory and get filtered by p:directory-list and are eventually stored in one single document, containing the whole path of every document the for-each created. (Part B)
So far, so good.
The problem is that Part A seems to be too slow. Part B already tries to read the data Step A
stores while the directory is still empty. Meaning, I'm having a performance / synchronization problem.
And now comes the question:
Is it possible to let the pipeline wait and to let it continue as soon as a certain event occurs?
That's what I'm imagining:
Step B waits as long as necessary until the directory, which Step A stores the data in, is no longer empty. I read something about
dbxml:breakpoint, but unfortunately I couldn't find more information than the name and
a short description of what it seems to do:
Set a breakpoint, optionally based upon a condition, that will cause pipeline operation to pause at the breakpoint, possibly requiring user intervention to continue and/or issuing a message.
It would be awesome if you know more about it and could give an example of how it's used. It would also help if you know a workaround or another way to solve this problem.
UPDATE:
After searching google for half an eternity, I found SMIL which's timesheets seem to do the trick. Has anyone experience with throwing XML / xProc and SMIL together?
Back towards the end of 2009 I proposed the concept of 'Orchestrating XProc with SMIL' http://broadcast.oreilly.com/2009/09/xproc-and-smil-orchestrating-p.html in a blog post on the O'Reilly Network.
However, I'm not sure that this (XProc + Time) is the solution to your problem. It's not entirely clear, to me, from you description what's happening. Are you implying that you're trying to write something to disk and then read it in a subsequent step? You need to keep stuff in the pipeline in order to ensure you can connect outputs to subsequent inputs.

Using setFire, setAhead, etc, without calling execute()

I'm extending an open-source AdvancedRobot in Robocode. That robot uses setFire to shoot, but never calls execute (doesn't appear in the code). I'm wondering how it's possible to still be able to shoot (it does). SetFire's doc says : This call returns immediately, and will not execute until you call execute() or take an action that executes.
I have no idea what "take an action that executes" mean.
Even better, what does "action" mean ?
My main goal was to do something every time a bullet is fired, so I have overridden the fire and fireBullet methods, but that doesn't work with the "set" methods (since it's possible to call it several times, ovveriding the previous order each time and shooting only when you "call execute() or take an action that executes"). So, maybe there is a way around.
Whatever, I'd be glad if anyone could help on any of those concerns.
Thank you very much.
This question sure is old, but for future reference:
Actions that execute are basically "stuff the robot can do that doesn't start with set", like fire or ahead, and so on. Calling any of these will also execute.
If you want to do something special every time a bullet is fired, you can use the following:
if (setFireBullet(someBulletPower) != null) {
// you only land here when a REAL bullet is fired,
// that is, when the gun heat was down.
}
Of course this only works if the open source bot you're extending is executing (it seems to be doing that, though I can't be sure if it is doing this every turn without knowing the code).

Asterisk - Any way to end/cancel the queue wrap-up time?

Any way to end the queue wrap-up time?
We define a wrap-up time of 60 seconds to allow the agents to finish their notes from a call. In some cases, the full 60 seconds is not needed and our agents would like to end their wrap-up time.
Note:I dont want use pause/unpause commands, because I am tracking the pause/unpause events to track the breaks (metting, launch, break, etc) times.
No, there are no way change wrapuptime dynamicaly.
But posible create dialplan/web page support which will pause/unpause or just not allow call device while puting notes.
You also can mark pauses created by web page, so not use it for track breaks.
Bit ancient question, but there is actually a tool which allows you to manage wrap up/pause/unpause of agents and gives you many more features to control/monitor your call center so it might be worth looking at. Have a look at OrderlyStatsSE.

howto avoid massive notification in DataBinding

I guess it's quite a common problem in databinding scenarios.
What do you usually do, if you are running a batch update and want to avoid that a propertychanged-dependend calculations/actions/whatever are executed for every single update?
The first thing which usually comes to my mind, is to either introduces a new boolean or unhook/hook the eventhandler, ...
What I don't like about this approaches is:
they introduce new complexity (has to be maintained, ...)
they are error prone, because you have to make sure that a suppressed notifications are sent afterwards
I'm wondering if somebody addressed this problem already in a more convenient way that is more easy to handle?
tia
Martin
Edit: not to missunderstand me. I know about the things .NET provides like RaiseListChangedEvents from BindingList, ... They are all addressing the problem in more/less the same way as I described, but I'm searching for a different way which doesn't have to listed drawbacks.
Maybe I'm on the wrong track, but I though I give it a try here...
There isn't a single one-size-fits-all solution, unfortunately. I've applied or seen the following solutions:
There are two singals. One signal is emitted when the change comes from a user action, the other always fires. This allows to distinguish between changes in the UI and updates by code.
A boolean to protect code
The property event framework stops propagating events automatically when a value didn't really change.
A freeze/thaw method on the signal or the signal manager (i.e. the whole framework)
A way to merge signals into a single one. You can do N updates and they get collected into M signals where M <= N. If you change the same property 100 times, you still only get 1 signal.
Queuing of signals (instead of synchronous execution). The queuing code can then merge signals, too. I've used this with great success in an application that doesn't have a "Save" button. All changes are saved to the database as you make them. When you change a text, the changes are merged over a certain time (namely until the previous DB update returns) and then, they are committed as a single change.
An API to set several values at once; only a single signal is emitted.
The signal framework can send signals at different levels of granularity. Say you have a person with a name. When you change the name, you get two signals: One for the name change and one "instance field changed". So if you only care "has something changed", then you can hook into the instance instead of all the fields.
What platform? The post makes me think .NET.
What is the underlying objects? For example, BindingList<T> as a source allows you to disable notifications by setting RaiseListChangedEvents to false while doing the update.
Other than that (or similar); yes, disconnect the binding during big updates
The easiest route to take is to use the BindingSource component for your data binding. Instead of binding your controls to a particular object (or IList), use that object as the DataSource for the BindingSource, then bind the controls to the BindingSource.
The BindingSource class has SuspendBinding() and ResumeBinding() functions.

Resources