Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix manage_crawls clean command with no crawls #125

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crawler/management/commands/manage_crawls.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def delete(crawl_id, dry_run):
@click.option("--dry-run", is_flag=True)
@transaction.atomic
def clean(keep, dry_run):
# If there are no crawls, there's nothing to do.
if not Crawl.objects.exists():
return

# Delete any in-progress crawls that aren't the most recent.
started_delete = Crawl.objects.filter(status=Crawl.Status.STARTED).exclude(
pk=Crawl.objects.latest("started").pk
Expand Down
5 changes: 5 additions & 0 deletions crawler/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ def test_delete_dry_run(self):
self.assertEqual(stdout, f"Deleting {c1}\nDry run, skipping deletion\n")
self.assertEqual(Crawl.objects.count(), 2)

def test_clean_no_crawls(self):
self.assertFalse(Crawl.objects.exists())
self.invoke("clean")
self.assertFalse(Crawl.objects.exists())

def test_clean(self):
c1 = Crawl.objects.create(config={}, status=Crawl.Status.STARTED)
c2 = Crawl.objects.create(config={}, status=Crawl.Status.STARTED)
Expand Down
Loading