-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4200 from freelawproject/612-recap-search-alerts-…
…percolator 612 Introduced Percolator Recap Search Alerts
- Loading branch information
Showing
29 changed files
with
3,526 additions
and
537 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
36 changes: 36 additions & 0 deletions
36
cl/alerts/management/commands/cl_send_rt_percolator_alerts.py
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,36 @@ | ||
import time | ||
|
||
from cl.alerts.management.commands.cl_send_scheduled_alerts import ( | ||
query_and_send_alerts_by_rate, | ||
) | ||
from cl.alerts.models import Alert | ||
from cl.lib.command_utils import VerboseCommand | ||
|
||
|
||
class Command(VerboseCommand): | ||
help = """Send real-time alerts scheduled by the Percolator every 5 minutes. | ||
This process is performed to accumulate alerts that can be grouped into a | ||
single email if they belong to the same user. """ | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.options = {} | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
"--testing-mode", | ||
action="store_true", | ||
help="Use this flag for testing purposes.", | ||
) | ||
|
||
def handle(self, *args, **options): | ||
super().handle(*args, **options) | ||
testing_mode = options.get("testing_mode", False) | ||
while True: | ||
query_and_send_alerts_by_rate(Alert.REAL_TIME) | ||
if testing_mode: | ||
# Perform only 1 iteration for testing purposes. | ||
break | ||
|
||
# Wait for 5 minutes. | ||
time.sleep(300) |
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
29 changes: 29 additions & 0 deletions
29
cl/alerts/migrations/0011_add_schedule_alert_hit_content_type.py
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,29 @@ | ||
# Generated by Django 5.1.2 on 2024-10-18 20:18 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("alerts", "0010_pghistory_v3_4_0_trigger_update"), | ||
("contenttypes", "0002_remove_content_type_name"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="scheduledalerthit", | ||
name="content_type", | ||
field=models.ForeignKey( | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="contenttypes.contenttype", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="scheduledalerthit", | ||
name="object_id", | ||
field=models.PositiveIntegerField(null=True), | ||
), | ||
] |
11 changes: 11 additions & 0 deletions
11
cl/alerts/migrations/0011_add_schedule_alert_hit_content_type.sql
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,11 @@ | ||
BEGIN; | ||
-- | ||
-- Add field content_type to scheduledalerthit | ||
-- | ||
ALTER TABLE "alerts_scheduledalerthit" ADD COLUMN "content_type_id" integer NULL CONSTRAINT "alerts_scheduledaler_content_type_id_c1a4db47_fk_django_co" REFERENCES "django_content_type"("id") DEFERRABLE INITIALLY DEFERRED; SET CONSTRAINTS "alerts_scheduledaler_content_type_id_c1a4db47_fk_django_co" IMMEDIATE; | ||
-- | ||
-- Add field object_id to scheduledalerthit | ||
-- | ||
ALTER TABLE "alerts_scheduledalerthit" ADD COLUMN "object_id" integer NULL CHECK ("object_id" >= 0); | ||
CREATE INDEX "alerts_scheduledalerthit_content_type_id_c1a4db47" ON "alerts_scheduledalerthit" ("content_type_id"); | ||
COMMIT; |
25 changes: 25 additions & 0 deletions
25
cl/alerts/migrations/0012_add_schedule_alert_hit_content_type_index.py
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,25 @@ | ||
# Generated by Django 5.1.2 on 2024-10-18 20:19 | ||
|
||
from django.contrib.postgres.operations import AddIndexConcurrently | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
atomic = False | ||
|
||
dependencies = [ | ||
("alerts", "0011_add_schedule_alert_hit_content_type"), | ||
("contenttypes", "0002_remove_content_type_name"), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
AddIndexConcurrently( | ||
model_name="scheduledalerthit", | ||
index=models.Index( | ||
fields=["content_type", "object_id"], | ||
name="alerts_sche_content_c5e627_idx", | ||
), | ||
), | ||
] |
4 changes: 4 additions & 0 deletions
4
cl/alerts/migrations/0012_add_schedule_alert_hit_content_type_index.sql
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,4 @@ | ||
-- | ||
-- Concurrently create index alerts_sche_content_c5e627_idx on field(s) content_type, object_id of model scheduledalerthit | ||
-- | ||
CREATE INDEX CONCURRENTLY "alerts_sche_content_c5e627_idx" ON "alerts_scheduledalerthit" ("content_type_id", "object_id"); |
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.