-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into Matvey-Kuk/multiple-bypass-keys
- Loading branch information
Showing
10 changed files
with
501 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
workflow: | ||
id: businesshours | ||
description: demonstrate how to do smth only when it's business hours | ||
triggers: | ||
- type: alert | ||
- type: manual | ||
actions: | ||
- name: dismiss-alert | ||
if: "keep.is_business_hours(timezone='America/New_York')" | ||
provider: | ||
type: mock | ||
with: | ||
enrich_alert: | ||
- key: buisnesshours | ||
value: "true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import os | ||
import time | ||
from typing import Dict, Tuple | ||
|
||
# Get polling interval from env | ||
POLLING_INTERVAL = int(os.getenv("PUSHER_POLLING_INTERVAL", "15")) | ||
|
||
|
||
class NotificationCache: | ||
_instance = None | ||
__initialized = False | ||
|
||
def __new__(cls): | ||
if cls._instance is None: | ||
cls._instance = super().__new__(cls) | ||
return cls._instance | ||
|
||
def __init__(self): | ||
if not self.__initialized: | ||
self.cache: Dict[Tuple[str, str], float] = {} | ||
self.__initialized = True | ||
|
||
def should_notify(self, tenant_id: str, event_type: str) -> bool: | ||
cache_key = (tenant_id, event_type) | ||
current_time = time.time() | ||
|
||
if cache_key not in self.cache: | ||
self.cache[cache_key] = current_time | ||
return True | ||
|
||
last_time = self.cache[cache_key] | ||
if current_time - last_time >= POLLING_INTERVAL: | ||
self.cache[cache_key] = current_time | ||
return True | ||
|
||
return False | ||
|
||
|
||
# Get singleton instance | ||
def get_notification_cache() -> NotificationCache: | ||
return NotificationCache() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.