Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usecase for triggering a rule at a certain time everyday #1812

Open
madhurijain97 opened this issue Mar 29, 2023 · 2 comments
Open

Usecase for triggering a rule at a certain time everyday #1812

madhurijain97 opened this issue Mar 29, 2023 · 2 comments

Comments

@madhurijain97
Copy link

Description:
I have a usecase where we want a sql to run at a certain time everyday depending on different timezones. I see that we have triggers, but they are for injecting events and not for when to run the sql.

For eg.
I want to detecting missing events for 5 minutes and want this to be triggered at 2pm PST everyday. Documentation doesn’t have details related to this.

from not inputStream[key == "1234"] for 300 sec select "1234" as key insert into outputStream

Note: I need this to be run at a specific time everyday since this rule sends out alerts only once and we have certain logic in place to filter out the alerts based on inactive time.

Is it possible to have a query that does the following?
from not inputStream[key == "1234"] for 300 sec select "1234" as key insert into outputStream RUN_AT <TIME> TIMEZONE <TIMEZONE>

Affected Siddhi Version:

OS, DB, other environment details and versions:

Steps to reproduce:

Related Issues:

@mohammedyusuf380
Copy link

I can help to solve this issue @madhurijain97

@mohammedyusuf380
Copy link

steps to solve this issue 👍

" First step "
To achieve running a SQL query at a specific time every day based on different timezones in Siddhi, you can use the "corn" scheduler along with Siddhi's 'window' and 'trigger' extensions. Unfortunately, Siddhi does not directly support executing queries at specific times with time zones out of the box, but we can work around this limitation.

"Second step"

Here's how you can achieve your use case:

  1. Define a trigger that fires at a specific time every day in the desired timezone.
  2. Use a window to detect missing events for a certain duration.
  3. Use the trigger to start the window processing at the specified time.

Here's an example Siddhi application to illustrate this:

@app:name("MissingEventDetectorApp")
@app:description("Detect missing events and trigger an alert at a specific time every day in different timezones")

define stream InputStream (key string);
define stream OutputStream (key string);

-- Window to detect missing events for 5 minutes (300 seconds)
-- Adjust the duration based on your requirements
from every e1 = InputStream[key == "1234"] -> e2 = InputStream[key == "1234"] for 5 min
select e1.key as key
insert expired events into MissingEventStream;

-- Define your alerting logic here, for simplicity, let's just log the missing event
from MissingEventStream
select key
insert into AlertStream;

-- Trigger to start window processing at 2 PM every day in PST timezone
-- Adjust the cron expression and timezone according to your requirement
@info(name = 'Trigger')
from every cron: 0 0 14 ? * * * America/Los_Angeles
select currentTimeMillis() as triggerTime
insert into TriggerStream;

-- Start the processing of the window at the trigger time
from TriggerStream#window.time(1 sec)
join MissingEventStream
select triggerTime, key
insert into FinalAlertStream;

note

In this example:

The InputStream stream represents your input data.
The MissingEventStream stream captures events where the key "1234" is missing for 5 minutes.
The AlertStream stream represents the alerts for missing events.
The TriggerStream stream generates a trigger event at 2 PM every day in the PST timezone.
The FinalAlertStream stream captures the final alerts triggered by combining the trigger events and missing event detections.

note

Remember to adjust the cron expression, window duration, and timezone according to your specific requirements. Additionally, you may need to implement your own logic for handling alerts based on inactive time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants