Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit efe4835

Browse files
authored
Remove pulls trigger (#450)
* remove pulls trigger * add test * put cleanup method into cron job * fix migration conflict * remove the changes to should_write_to_storage * make repository non-required for ArchiveService, add bulk delete to ArchiveService, remove default value from paths
1 parent 9a61a94 commit efe4835

File tree

13 files changed

+63
-55
lines changed

13 files changed

+63
-55
lines changed

shared/api_archive/archive.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ArchiveService(object):
4848
In s3 terms, this would be the name of the bucket
4949
"""
5050

51-
storage_hash: str
51+
storage_hash: str | None
5252
"""
5353
A hash key of the repo for internal storage
5454
"""
@@ -64,7 +64,10 @@ def __init__(self, repository, ttl=None):
6464
self.ttl = ttl or int(get_config("services", "minio", "ttl", default=self.ttl))
6565

6666
self.storage = StorageService()
67-
self.storage_hash = self.get_archive_hash(repository)
67+
if repository:
68+
self.storage_hash = self.get_archive_hash(repository)
69+
else:
70+
self.storage_hash = None
6871

6972
@classmethod
7073
def get_archive_hash(cls, repository) -> str:
@@ -98,6 +101,8 @@ def write_json_data_to_storage(
98101
*,
99102
encoder=ReportEncoder,
100103
):
104+
if not self.storage_hash:
105+
raise ValueError("No hash key provided")
101106
if commit_id is None:
102107
# Some classes don't have a commit associated with them
103108
# For example Pull belongs to multiple commits.
@@ -147,20 +152,29 @@ def read_file(self, path: str) -> str:
147152
return contents.decode()
148153

149154
@sentry_sdk.trace
150-
def delete_file(self, path):
155+
def delete_file(self, path: str) -> None:
151156
"""
152157
Generic method to delete a file from the archive.
153158
"""
154159
self.storage.delete_file(self.root, path)
155160

161+
@sentry_sdk.trace
162+
def delete_files(self, paths: list[str]) -> None:
163+
"""
164+
Generic method to delete files from the archive.
165+
"""
166+
self.storage.delete_files(bucket_name=self.root, paths=paths)
167+
156168
def read_chunks(self, commit_sha: str) -> str:
157169
"""
158170
Convenience method to read a chunks file from the archive.
159171
"""
172+
if not self.storage_hash:
173+
raise ValueError("No hash key provided")
160174
path = MinioEndpoints.chunks.get_path(
161175
version="v4", repo_hash=self.storage_hash, commitid=commit_sha
162176
)
163177
return self.read_file(path)
164178

165-
def create_presigned_put(self, path):
179+
def create_presigned_put(self, path: str) -> str:
166180
return self.storage.create_presigned_put(self.root, path, self.ttl)

shared/celery_config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
brolly_stats_rollup_task_name = (
114114
f"app.cron.{TaskConfigGroup.daily.value}.BrollyStatsRollupTask"
115115
)
116+
flare_cleanup_task_name = f"app.cron.{TaskConfigGroup.daily.value}.FlareCleanupTask"
116117

117118

118119
def get_task_group(task_name: str) -> Optional[str]:
@@ -169,7 +170,7 @@ class BaseCeleryConfig(object):
169170
worker_prefetch_multiplier = int(
170171
get_config("setup", "tasks", "celery", "prefetch", default=1)
171172
)
172-
# !!! NEVER 0 !!! 0 == infinate
173+
# !!! NEVER 0 !!! 0 == infinite
173174

174175
# http://celery.readthedocs.org/en/latest/configuration.html#celeryd-task-soft-time-limit
175176
task_soft_time_limit = int(

shared/django_apps/core/models.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,11 @@ def external_id(self):
418418
return self.pullid
419419

420420
def should_write_to_storage(self) -> bool:
421+
"""
422+
This only applies to the flare field.
423+
Flare is used to draw static graphs (see GraphHandler view in api) and can be large.
424+
Flare cleanup is handled by FlareCleanupTask in worker.
425+
"""
421426
if self.repository is None or self.repository.author is None:
422427
return False
423428
is_codecov_repo = self.repository.author.username == "codecov"
@@ -430,7 +435,8 @@ def should_write_to_storage(self) -> bool:
430435
_flare = models.JSONField(db_column="flare", null=True)
431436
_flare_storage_path = models.URLField(db_column="flare_storage_path", null=True)
432437
flare = ArchiveField(
433-
should_write_to_storage_fn=should_write_to_storage, default_value_class=dict
438+
should_write_to_storage_fn=should_write_to_storage,
439+
default_value_class=dict,
434440
)
435441

436442
def save(self, *args, **kwargs):
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Generated by Django 4.2.16 on 2024-12-06 00:15
2+
3+
from django.db import migrations
4+
5+
from shared.django_apps.migration_utils import RiskyRunSQL
6+
7+
8+
class Migration(migrations.Migration):
9+
dependencies = [
10+
("legacy_migrations", "0007_delete_repo_trigger_stats"),
11+
]
12+
13+
operations = [
14+
RiskyRunSQL(
15+
"""
16+
DROP TRIGGER IF EXISTS pulls_before_update_drop_flare ON pulls;
17+
DROP FUNCTION IF EXISTS pulls_drop_flare();
18+
""",
19+
reverse_sql=migrations.RunSQL.noop,
20+
)
21+
]
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
from .commits import run_sql as commits_run_sql
22
from .owners import run_sql as owners_run_sql
3-
from .pulls import run_sql as pulls_run_sql
43
from .repos import run_sql as repos_run_sql
54

65

76
def run_sql(schema_editor):
87
commits_run_sql(schema_editor)
98
owners_run_sql(schema_editor)
109
repos_run_sql(schema_editor)
11-
pulls_run_sql(schema_editor)

shared/django_apps/legacy_migrations/migrations/legacy_sql/main/triggers/pulls.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

shared/django_apps/legacy_migrations/migrations/legacy_sql/upgrades/v440.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,6 @@ def run_sql(schema_editor):
5757
)
5858
execute procedure owner_yaml_updated();
5959
60-
61-
drop trigger pulls_before_insert on pulls;
62-
drop function pulls_insert();
63-
drop trigger pulls_before_update on pulls;
64-
drop function pulls_update();
65-
66-
create or replace function pulls_drop_flare() returns trigger as $$
67-
begin
68-
new.flare = null;
69-
return new;
70-
end;
71-
$$ language plpgsql;
72-
73-
create trigger pulls_before_update_drop_flare before update on pulls
74-
for each row
75-
when (new.state != 'open'::pull_state)
76-
execute procedure pulls_drop_flare();
77-
7860
---- Function Changes -----
7961
drop function if exists get_new_repos(int);
8062
drop function if exists get_pull(int, int);

shared/django_apps/utils/model_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def get_commitid(self) -> Optional[str]:
3838

3939
class ArchiveField:
4040
"""This is a helper class that transparently handles models' fields that are saved in storage.
41-
Classes that use the ArchiveField MUST implement ArchiveFieldInterface. It ill throw an error otherwise.
41+
Classes that use the ArchiveField MUST implement ArchiveFieldInterface. It will throw an error otherwise.
4242
It uses the Descriptor pattern: https://docs.python.org/3/howto/descriptor.html
4343
4444
Arguments:
@@ -58,7 +58,7 @@ class ArchiveField:
5858
rehydrate_fn=rehidrate_data,
5959
default_value='default'
6060
)
61-
For a full example check utils/tests/unit/test_model_utils.py
61+
For a full example check utils/tests/unit/test_model_utils.py in worker
6262
"""
6363

6464
def __init__(

shared/storage/aws.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def delete_file(self, bucket_name, path):
147147
except ClientError:
148148
raise
149149

150-
def delete_files(self, bucket_name, paths=[]):
150+
def delete_files(self, bucket_name: str, paths: list[str]) -> list[bool]:
151151
"""Batch deletes a list of files from a given bucket
152152
153153
Note:

shared/storage/fallback.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def delete_file(self, bucket_name, path):
8989
second_deletion = self.fallback_service.delete_file(bucket_name, path)
9090
return first_deletion and second_deletion
9191

92-
def delete_files(self, bucket_name, paths=[]):
92+
def delete_files(self, bucket_name: str, paths: list[str]) -> list[bool]:
9393
"""Batch deletes a list of files from a given bucket
9494
(what happens to the files that don't exist?)
9595

0 commit comments

Comments
 (0)