Skip to content

Commit

Permalink
Merge pull request #125 from cfpb/fix/clean-no-crawls
Browse files Browse the repository at this point in the history
Fix manage_crawls clean command with no crawls
  • Loading branch information
chosak authored Dec 10, 2024
2 parents 1e33ed8 + 0ad3b15 commit 7084407
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
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

0 comments on commit 7084407

Please sign in to comment.