AlertManager

rulesx. AlertManager

The AlertManager class is responsible for managing alerts. It allows sending alerts immediately, scheduling them for later, and revoking them.

Constructor

new AlertManager(id, sendAlert, revokeAlert)

Description:
  • Creates a new AlertManager instance.

Source:
Parameters:
Name Type Description
id string

the identifier for this AlertManager instance, used for logging

sendAlert SendAlertCallback

the function to call when an alert should be sent

revokeAlert RevokeAlertCallback

the function to call when an alert should be revoked

Members

RESCHEDULE_MODE :Object

Description:
  • The modes for rescheduling alerts.

Source:

The modes for rescheduling alerts.

Type:
  • Object

Methods

(id) → {boolean}

Description:
  • Cancels a scheduled alert by its ID. If the alert is repeated, it will be stopped.

Source:
Parameters:
Name Type Description
id string

the unique identifier of the alert to be cancelled

Returns:

true if the alert was cancelled, else false

Type
boolean

changeDelayForScheduledAlert(id, newDelay) → {boolean}

Description:
  • Changes the delay of a scheduled alert.

    If no alert with the given ID is scheduled, do nothing.

Source:
Parameters:
Name Type Description
id string

the unique identifier for the alert

newDelay number

the new delay in minutes before the alert should become active

Returns:

true if the delay was changed, else false

Type
boolean

issueAlert(id, message, reissueopt, importantopt) → {boolean}

Description:
  • Issues an alert immediately.

    If the alert is muted, it will not be sent, except if important is set to true.

    If the alert is already active, do nothing by default. If reissue is set to true, issue the alert again.

Source:
Parameters:
Name Type Attributes Default Description
id string

the unique identifier for the alert

message string

the message to be displayed in the alert

reissue boolean <optional>
false

whether to re-issue the alert if it already has been issued

important boolean <optional>
false

whether the alert is important and should be sent even if muted

Returns:

true if the alert was issued, else false

Type
boolean

muteAlert(id, duration)

Description:
  • Mutes an alert by its ID for the specified duration.

Source:
Parameters:
Name Type Description
id string

the unique identifier for the alert

duration number

the duration in minutes for which the alert should be muted

revokeAlert(id) → {boolean}

Description:
  • Revokes an alert, no matter it has only been scheduled or already become active.

    If no alert with the given ID is scheduled or active, do nothing.

Source:
Parameters:
Name Type Description
id string

the unique identifier of the alert

Returns:

true if the alert was revoked, else false

Type
boolean

revokeAllAlerts() → {number}

Description:
  • Revokes all alerts that have been scheduled or already become active.

Source:
Returns:

the number of alerts that have been revoked

Type
number

scheduleAlert(id, message, delay, repeatopt, rescheduleopt, revalidateopt) → {boolean}

Description:
  • Schedules an alert to be issued after the specified delay.

    If an alert with the same ID is already scheduled, do nothing by default. Rescheduling behaviour can be controlled with the reschedule parameter. For values of reschedule, see #RESCHEDULE_MODE.

Source:
Parameters:
Name Type Attributes Default Description
id string

the unique identifier for the alert

message string

the message to be displayed in the alert

delay number

the delay in minutes before the alert should become active

repeat boolean <optional>
false

whether to repeat the alert after the delay, defaults to false

reschedule string <optional>

whether to reschedule an already scheduled alert, defaults to NO_RESCHEDULE

revalidate RevalidateAlertCallback <optional>

function to revalidate if the alert should be sent once the delay is over

Returns:

true if the alert was (re-)scheduled, else false

Type
boolean