Skip to content

Commit

Permalink
Merge pull request #3423 from rebeccacremona/tweak-logging
Browse files Browse the repository at this point in the history
Tweak logging
  • Loading branch information
rebeccacremona authored Oct 31, 2023
2 parents 097b472 + 97269b6 commit 4552731
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
7 changes: 1 addition & 6 deletions perma_web/perma/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class ScoopJobIDFilter(InputFilter):
def queryset(self, request, queryset):
value = self.value()
if value:
return queryset.filter(scoop_logs__id_capture=value)
return queryset.filter(scoop_job_id=value)


class TagFilter(InputFilter):
Expand Down Expand Up @@ -668,11 +668,6 @@ def link_creation_timestamp(self, obj):
return obj.link.creation_timestamp
return None

def scoop_job_id(self, obj):
if obj.scoop_logs:
return obj.scoop_logs['id_capture']
return None

# def link_taglist(self, obj):
# if obj.link:
# return ", ".join(o.name for o in obj.link.tags.all())
Expand Down
8 changes: 6 additions & 2 deletions perma_web/perma/celery_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,10 @@ def capture_with_scoop(capture_job):
valid_if=lambda code, data: code == 200 and all(key in data for key in {"status", "id_capture"}) and data["status"] in ["pending", "started"],
)

# Save the Scoop job id for our records
capture_job.scoop_job_id = request_data['id_capture']
capture_job.save(update_fields=['scoop_job_id'])

# Poll until done
poll_network_errors = 0
while True:
Expand All @@ -1041,7 +1045,7 @@ def capture_with_scoop(capture_job):
try:
_, poll_data = send_to_scoop(
method='get',
path=f"capture/{request_data['id_capture']}",
path=f"capture/{capture_job.scoop_job_id}",
json={
"url": target_url
},
Expand All @@ -1060,7 +1064,7 @@ def capture_with_scoop(capture_job):

# Show progress to user. Assumes Scoop won't take much longer than ~60s, worst case scenario
wait_time = time.time() - scoop_start_time
inc_progress(capture_job, min(wait_time/60, 0.99), "Waiting for Scoop to finish")
inc_progress(capture_job, min(wait_time/60, 0.99), f"Waiting for Scoop job {capture_job.scoop_job_id} to finish: {poll_data['status']}")

capture_job.scoop_logs = poll_data
if poll_data.get('scoop_capture_summary'):
Expand Down
18 changes: 18 additions & 0 deletions perma_web/perma/migrations/0029_capturejob_scoop_job_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.22 on 2023-10-31 14:44

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('perma', '0028_auto_20230905_1813'),
]

operations = [
migrations.AddField(
model_name='capturejob',
name='scoop_job_id',
field=models.CharField(blank=True, db_index=True, max_length=255, null=True),
),
]
1 change: 1 addition & 0 deletions perma_web/perma/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2041,6 +2041,7 @@ class CaptureJob(models.Model):
scoop_start_time = models.DateTimeField(blank=True, null=True)
scoop_end_time = models.DateTimeField(blank=True, null=True)
scoop_logs = JSONField(blank=True, null=True)
scoop_job_id = models.CharField(max_length=255, blank=True, null=True, db_index=True)
scoop_state = models.CharField(max_length=255, blank=True, null=True, db_index=True)

superseded = models.BooleanField(default=False, help_text='A user upload has made this CaptureJob irrelevant to the playback of its related Link')
Expand Down

0 comments on commit 4552731

Please sign in to comment.