generated from aboutcode-org/skeleton
-
Notifications
You must be signed in to change notification settings - Fork 23
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 #271 from nexB/244-watch-model
Watch for packages (model and implementation) #244
- Loading branch information
Showing
16 changed files
with
905 additions
and
37 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# | ||
# Copyright (c) nexB Inc. and others. All rights reserved. | ||
# PurlDB is a trademark of nexB Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text. | ||
# See https://github.com/nexB/purldb for support or download. | ||
# See https://aboutcode.org for more information about nexB OSS projects. | ||
# | ||
|
||
from django_rq.management.commands import rqscheduler | ||
from packagedb.models import PackageWatch | ||
from packagedb.schedules import clear_zombie_watch_schedules | ||
from packagedb.schedules import scheduled_job_exists | ||
|
||
|
||
def init_watch_scheduled(): | ||
"""Initialize scheduled jobs for active PackageWatch.""" | ||
active_watch_qs = PackageWatch.objects.filter(is_active=True) | ||
for watch in active_watch_qs: | ||
if scheduled_job_exists(watch.schedule_work_id): | ||
continue | ||
new_id = watch.create_new_job() | ||
watch.schedule_work_id = new_id | ||
watch.save(update_fields=["schedule_work_id"]) | ||
|
||
|
||
class Command(rqscheduler.Command): | ||
def handle(self, *args, **kwargs): | ||
clear_zombie_watch_schedules() | ||
init_watch_scheduled() | ||
super(Command, self).handle(*args, **kwargs) |
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,133 @@ | ||
# Generated by Django 4.2.6 on 2024-01-18 13:14 | ||
|
||
import django.core.validators | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("packagedb", "0081_apiuser"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="PackageWatch", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"package_url", | ||
models.CharField( | ||
db_index=True, | ||
help_text="Package-URL to watch. If the PURL has a version, qualifiers or subpath, they are stripped and ignored.", | ||
max_length=2048, | ||
unique=True, | ||
), | ||
), | ||
( | ||
"type", | ||
models.CharField( | ||
blank=True, | ||
db_index=True, | ||
help_text="A short code to identify the type of this package.", | ||
max_length=16, | ||
null=True, | ||
), | ||
), | ||
( | ||
"namespace", | ||
models.CharField( | ||
blank=True, | ||
db_index=True, | ||
help_text="Package name prefix, such as Maven groupid, Docker image owner, GitHub user or organization, etc.", | ||
max_length=255, | ||
null=True, | ||
), | ||
), | ||
( | ||
"name", | ||
models.CharField( | ||
blank=True, | ||
db_index=True, | ||
help_text="Name of the package.", | ||
max_length=100, | ||
null=True, | ||
), | ||
), | ||
( | ||
"is_active", | ||
models.BooleanField( | ||
db_index=True, | ||
default=True, | ||
help_text="When set to True (Yes), this Package Watch is active. When set to False (No), this watch is inactive and not processed.", | ||
null=True, | ||
), | ||
), | ||
( | ||
"depth", | ||
models.PositiveSmallIntegerField( | ||
choices=[(1, "Version"), (2, "Metadata"), (3, "Scan")], | ||
default=3, | ||
help_text="Depth of data collection from listing versions up to a full scan.", | ||
), | ||
), | ||
( | ||
"watch_interval", | ||
models.PositiveSmallIntegerField( | ||
default=7, | ||
help_text="Number of days to wait between watches of this package.", | ||
validators=[ | ||
django.core.validators.MinValueValidator( | ||
1, message="Interval must be at least 1 day." | ||
), | ||
django.core.validators.MaxValueValidator( | ||
365, message="Interval must be at most 365 days." | ||
), | ||
], | ||
), | ||
), | ||
( | ||
"creation_date", | ||
models.DateTimeField( | ||
auto_now_add=True, | ||
help_text="Timestamp indicating when this watch object was created.", | ||
), | ||
), | ||
( | ||
"last_watch_date", | ||
models.DateTimeField( | ||
blank=True, | ||
db_index=True, | ||
help_text="Timestamp indicating when this PURL was last watched.", | ||
null=True, | ||
), | ||
), | ||
( | ||
"watch_error", | ||
models.TextField( | ||
blank=True, | ||
help_text="Watch error messages of the last watch, if any. When present this means the watch failed. This is reset on each new watch.", | ||
null=True, | ||
), | ||
), | ||
( | ||
"schedule_work_id", | ||
models.CharField( | ||
blank=True, | ||
db_index=True, | ||
help_text="Identifier used to manage the periodic watch job.", | ||
max_length=255, | ||
null=True, | ||
unique=True, | ||
), | ||
), | ||
], | ||
), | ||
] |
Oops, something went wrong.