aboutsummaryrefslogtreecommitdiffstats
path: root/sql
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2021-09-30 16:49:47 -0700
committerBryan Newbold <bnewbold@archive.org>2021-09-30 16:49:47 -0700
commitf6125848f627ae9bfd3a36d807d2349e1c66bfe3 (patch)
tree8419947e17dd27621a5b17098eacaedf1a0227a5 /sql
parent24edc1c754d35df1020907a9c8941f16eaf71440 (diff)
downloadsandcrawler-f6125848f627ae9bfd3a36d807d2349e1c66bfe3.tar.gz
sandcrawler-f6125848f627ae9bfd3a36d807d2349e1c66bfe3.zip
refactor reingest scripts
Diffstat (limited to 'sql')
-rw-r--r--sql/dump_reingest_quarterly.sql81
-rw-r--r--sql/dump_reingest_spn.sql25
-rw-r--r--sql/dump_reingest_weekly.sql81
-rwxr-xr-xsql/reingest_quarterly.sh17
-rwxr-xr-xsql/reingest_spn.sh19
-rwxr-xr-xsql/reingest_weekly.sh17
6 files changed, 90 insertions, 150 deletions
diff --git a/sql/dump_reingest_quarterly.sql b/sql/dump_reingest_quarterly.sql
index 972e9fe..917d88b 100644
--- a/sql/dump_reingest_quarterly.sql
+++ b/sql/dump_reingest_quarterly.sql
@@ -3,11 +3,19 @@ COPY (
SELECT row_to_json(ingest_request.*) FROM ingest_request
LEFT JOIN ingest_file_result ON ingest_file_result.base_url = ingest_request.base_url
WHERE ingest_request.ingest_type = 'pdf'
- AND ingest_file_result.ingest_type = 'pdf'
+ AND ingest_file_result.hit = false
AND ingest_request.created < NOW() - '8 hour'::INTERVAL
AND ingest_request.created > NOW() - '91 day'::INTERVAL
- AND ingest_file_result.hit = false
- AND ingest_file_result.status like 'spn2-%'
+ AND (ingest_request.ingest_request_source = 'fatcat-changelog'
+ OR ingest_request.ingest_request_source = 'fatcat-ingest')
+ AND (
+ ingest_file_result.status like 'spn2-%'
+ OR ingest_file_result.status like 'cdx-error'
+ OR ingest_file_result.status like 'wayback-error'
+ OR ingest_file_result.status like 'wayback-content-error'
+ OR ingest_file_result.status like 'petabox-error'
+ OR ingest_file_result.status like 'gateway-timeout'
+ )
AND ingest_file_result.status != 'spn2-error:invalid-url-syntax'
AND ingest_file_result.status != 'spn2-error:filesize-limit'
AND ingest_file_result.status != 'spn2-error:not-found'
@@ -15,68 +23,9 @@ COPY (
AND ingest_file_result.status != 'spn2-error:too-many-redirects'
AND ingest_file_result.status != 'spn2-error:network-authentication-required'
AND ingest_file_result.status != 'spn2-error:unknown'
-) TO '/srv/sandcrawler/tasks/reingest_quarterly_spn2-error_current.rows.json';
+) TO '/srv/sandcrawler/tasks/reingest_weekly_current.rows.json';
-COPY (
- SELECT row_to_json(ingest_request.*) FROM ingest_request
- LEFT JOIN ingest_file_result ON ingest_file_result.base_url = ingest_request.base_url
- WHERE ingest_request.ingest_type = 'pdf'
- AND ingest_file_result.ingest_type = 'pdf'
- AND ingest_file_result.hit = false
- AND ingest_file_result.status like 'cdx-error'
- AND ingest_request.created < NOW() - '8 hour'::INTERVAL
- AND ingest_request.created > NOW() - '91 day'::INTERVAL
- AND (ingest_request.ingest_request_source = 'fatcat-changelog'
- OR ingest_request.ingest_request_source = 'fatcat-ingest')
-) TO '/srv/sandcrawler/tasks/reingest_quarterly_cdx-error_current.rows.json';
-
-COPY (
- SELECT row_to_json(ingest_request.*) FROM ingest_request
- LEFT JOIN ingest_file_result ON ingest_file_result.base_url = ingest_request.base_url
- WHERE ingest_request.ingest_type = 'pdf'
- AND ingest_file_result.ingest_type = 'pdf'
- AND ingest_file_result.hit = false
- AND ingest_file_result.status like 'cdx-error'
- AND ingest_request.created < NOW() - '8 hour'::INTERVAL
- AND ingest_request.created > NOW() - '91 day'::INTERVAL
- AND (ingest_request.ingest_request_source != 'fatcat-changelog'
- AND ingest_request.ingest_request_source != 'fatcat-ingest')
-) TO '/srv/sandcrawler/tasks/reingest_quarterly_cdx-error_bulk_current.rows.json';
-
-COPY (
- SELECT row_to_json(ingest_request.*) FROM ingest_request
- LEFT JOIN ingest_file_result ON ingest_file_result.base_url = ingest_request.base_url
- WHERE ingest_request.ingest_type = 'pdf'
- AND ingest_file_result.ingest_type = 'pdf'
- AND ingest_file_result.hit = false
- AND ingest_file_result.status like 'wayback-error'
- AND ingest_request.created < NOW() - '8 hour'::INTERVAL
- AND ingest_request.created > NOW() - '91 day'::INTERVAL
-) TO '/srv/sandcrawler/tasks/reingest_quarterly_wayback-error_current.rows.json';
-
-COPY (
- SELECT row_to_json(ingest_request.*) FROM ingest_request
- LEFT JOIN ingest_file_result ON ingest_file_result.base_url = ingest_request.base_url
- WHERE ingest_request.ingest_type = 'pdf'
- AND ingest_file_result.ingest_type = 'pdf'
- AND ingest_file_result.hit = false
- AND ingest_file_result.status like 'gateway-timeout'
- AND ingest_request.created < NOW() - '8 hour'::INTERVAL
- AND ingest_request.created > NOW() - '91 day'::INTERVAL
- AND (ingest_request.ingest_request_source = 'fatcat-changelog'
- OR ingest_request.ingest_request_source = 'fatcat-ingest')
-) TO '/srv/sandcrawler/tasks/reingest_quarterly_gateway-timeout.rows.json';
-
-COPY (
- SELECT row_to_json(ingest_request.*) FROM ingest_request
- LEFT JOIN ingest_file_result ON ingest_file_result.base_url = ingest_request.base_url
- WHERE ingest_request.ingest_type = 'pdf'
- AND ingest_file_result.ingest_type = 'pdf'
- AND ingest_file_result.hit = false
- AND ingest_file_result.status like 'petabox-error'
- AND ingest_request.created < NOW() - '8 hour'::INTERVAL
- AND ingest_request.created > NOW() - '91 day'::INTERVAL
- AND (ingest_request.ingest_request_source = 'fatcat-changelog'
- OR ingest_request.ingest_request_source = 'fatcat-ingest')
-) TO '/srv/sandcrawler/tasks/reingest_quarterly_petabox-error_current.rows.json';
+-- bulk re-tries would be:
+-- AND (ingest_request.ingest_request_source != 'fatcat-changelog'
+-- AND ingest_request.ingest_request_source != 'fatcat-ingest')
diff --git a/sql/dump_reingest_spn.sql b/sql/dump_reingest_spn.sql
new file mode 100644
index 0000000..a8ed72f
--- /dev/null
+++ b/sql/dump_reingest_spn.sql
@@ -0,0 +1,25 @@
+
+COPY (
+ SELECT row_to_json(ingest_request.*) FROM ingest_request
+ LEFT JOIN ingest_file_result ON ingest_file_result.base_url = ingest_request.base_url
+ WHERE ingest_request.ingest_type = 'pdf'
+ AND ingest_file_result.hit = false
+ AND ingest_request.created < NOW() - '2 hour'::INTERVAL
+ AND ingest_request.created > NOW() - '31 day'::INTERVAL
+ AND ingest_request.ingest_request_source = 'savepapernow-web'
+ AND (
+ ingest_file_result.status like 'spn2-%'
+ -- OR ingest_file_result.status like 'cdx-error'
+ -- OR ingest_file_result.status like 'wayback-error'
+ -- OR ingest_file_result.status like 'wayback-content-error'
+ OR ingest_file_result.status like 'petabox-error'
+ -- OR ingest_file_result.status like 'gateway-timeout'
+ )
+ AND ingest_file_result.status != 'spn2-error:invalid-url-syntax'
+ AND ingest_file_result.status != 'spn2-error:filesize-limit'
+ AND ingest_file_result.status != 'spn2-error:not-found'
+ AND ingest_file_result.status != 'spn2-error:blocked-url'
+ AND ingest_file_result.status != 'spn2-error:too-many-redirects'
+ AND ingest_file_result.status != 'spn2-error:network-authentication-required'
+ AND ingest_file_result.status != 'spn2-error:unknown'
+) TO '/srv/sandcrawler/tasks/reingest_spn.rows.json';
diff --git a/sql/dump_reingest_weekly.sql b/sql/dump_reingest_weekly.sql
index e7cd553..65800eb 100644
--- a/sql/dump_reingest_weekly.sql
+++ b/sql/dump_reingest_weekly.sql
@@ -3,11 +3,19 @@ COPY (
SELECT row_to_json(ingest_request.*) FROM ingest_request
LEFT JOIN ingest_file_result ON ingest_file_result.base_url = ingest_request.base_url
WHERE ingest_request.ingest_type = 'pdf'
- AND ingest_file_result.ingest_type = 'pdf'
+ AND ingest_file_result.hit = false
AND ingest_request.created < NOW() - '8 hour'::INTERVAL
AND ingest_request.created > NOW() - '8 day'::INTERVAL
- AND ingest_file_result.hit = false
- AND ingest_file_result.status like 'spn2-%'
+ AND (ingest_request.ingest_request_source = 'fatcat-changelog'
+ OR ingest_request.ingest_request_source = 'fatcat-ingest')
+ AND (
+ ingest_file_result.status like 'spn2-%'
+ -- OR ingest_file_result.status like 'cdx-error'
+ -- OR ingest_file_result.status like 'wayback-error'
+ -- OR ingest_file_result.status like 'wayback-content-error'
+ OR ingest_file_result.status like 'petabox-error'
+ -- OR ingest_file_result.status like 'gateway-timeout'
+ )
AND ingest_file_result.status != 'spn2-error:invalid-url-syntax'
AND ingest_file_result.status != 'spn2-error:filesize-limit'
AND ingest_file_result.status != 'spn2-error:not-found'
@@ -15,68 +23,9 @@ COPY (
AND ingest_file_result.status != 'spn2-error:too-many-redirects'
AND ingest_file_result.status != 'spn2-error:network-authentication-required'
AND ingest_file_result.status != 'spn2-error:unknown'
-) TO '/srv/sandcrawler/tasks/reingest_weekly_spn2-error_current.rows.json';
+) TO '/srv/sandcrawler/tasks/reingest_weekly_current.rows.json';
-COPY (
- SELECT row_to_json(ingest_request.*) FROM ingest_request
- LEFT JOIN ingest_file_result ON ingest_file_result.base_url = ingest_request.base_url
- WHERE ingest_request.ingest_type = 'pdf'
- AND ingest_file_result.ingest_type = 'pdf'
- AND ingest_file_result.hit = false
- AND ingest_file_result.status like 'cdx-error'
- AND ingest_request.created < NOW() - '8 hour'::INTERVAL
- AND ingest_request.created > NOW() - '8 day'::INTERVAL
- AND (ingest_request.ingest_request_source = 'fatcat-changelog'
- OR ingest_request.ingest_request_source = 'fatcat-ingest')
-) TO '/srv/sandcrawler/tasks/reingest_weekly_cdx-error_current.rows.json';
-
-COPY (
- SELECT row_to_json(ingest_request.*) FROM ingest_request
- LEFT JOIN ingest_file_result ON ingest_file_result.base_url = ingest_request.base_url
- WHERE ingest_request.ingest_type = 'pdf'
- AND ingest_file_result.ingest_type = 'pdf'
- AND ingest_file_result.hit = false
- AND ingest_file_result.status like 'cdx-error'
- AND ingest_request.created < NOW() - '8 hour'::INTERVAL
- AND ingest_request.created > NOW() - '8 day'::INTERVAL
- AND (ingest_request.ingest_request_source != 'fatcat-changelog'
- AND ingest_request.ingest_request_source != 'fatcat-ingest')
-) TO '/srv/sandcrawler/tasks/reingest_weekly_cdx-error_bulk_current.rows.json';
-
-COPY (
- SELECT row_to_json(ingest_request.*) FROM ingest_request
- LEFT JOIN ingest_file_result ON ingest_file_result.base_url = ingest_request.base_url
- WHERE ingest_request.ingest_type = 'pdf'
- AND ingest_file_result.ingest_type = 'pdf'
- AND ingest_file_result.hit = false
- AND ingest_file_result.status like 'wayback-error'
- AND ingest_request.created < NOW() - '8 hour'::INTERVAL
- AND ingest_request.created > NOW() - '8 day'::INTERVAL
-) TO '/srv/sandcrawler/tasks/reingest_weekly_wayback-error_current.rows.json';
-
-COPY (
- SELECT row_to_json(ingest_request.*) FROM ingest_request
- LEFT JOIN ingest_file_result ON ingest_file_result.base_url = ingest_request.base_url
- WHERE ingest_request.ingest_type = 'pdf'
- AND ingest_file_result.ingest_type = 'pdf'
- AND ingest_file_result.hit = false
- AND ingest_file_result.status like 'gateway-timeout'
- AND ingest_request.created < NOW() - '8 hour'::INTERVAL
- AND ingest_request.created > NOW() - '8 day'::INTERVAL
- AND (ingest_request.ingest_request_source = 'fatcat-changelog'
- OR ingest_request.ingest_request_source = 'fatcat-ingest')
-) TO '/srv/sandcrawler/tasks/reingest_weekly_gateway-timeout.rows.json';
-
-COPY (
- SELECT row_to_json(ingest_request.*) FROM ingest_request
- LEFT JOIN ingest_file_result ON ingest_file_result.base_url = ingest_request.base_url
- WHERE ingest_request.ingest_type = 'pdf'
- AND ingest_file_result.ingest_type = 'pdf'
- AND ingest_file_result.hit = false
- AND ingest_file_result.status like 'petabox-error'
- AND ingest_request.created < NOW() - '8 hour'::INTERVAL
- AND ingest_request.created > NOW() - '8 day'::INTERVAL
- AND (ingest_request.ingest_request_source = 'fatcat-changelog'
- OR ingest_request.ingest_request_source = 'fatcat-ingest')
-) TO '/srv/sandcrawler/tasks/reingest_weekly_petabox-error_current.rows.json';
+-- bulk re-tries would be:
+-- AND (ingest_request.ingest_request_source != 'fatcat-changelog'
+-- AND ingest_request.ingest_request_source != 'fatcat-ingest')
diff --git a/sql/reingest_quarterly.sh b/sql/reingest_quarterly.sh
index 2e19f5e..20fd82b 100755
--- a/sql/reingest_quarterly.sh
+++ b/sql/reingest_quarterly.sh
@@ -7,14 +7,13 @@ set -o pipefail # fail if part of a '|' command fails
sudo -u postgres psql sandcrawler < dump_reingest_quarterly.sql
cd ../python
-sudo -u sandcrawler pipenv run ./scripts/ingestrequest_row2json.py /srv/sandcrawler/tasks/reingest_quarterly_spn2-error_current.rows.json | shuf > /srv/sandcrawler/tasks/reingest_quarterly_spn2-error_current.json
-sudo -u sandcrawler pipenv run ./scripts/ingestrequest_row2json.py /srv/sandcrawler/tasks/reingest_quarterly_cdx-error_current.rows.json | shuf > /srv/sandcrawler/tasks/reingest_quarterly_cdx-error_current.json
-#sudo -u sandcrawler pipenv run ./scripts/ingestrequest_row2json.py /srv/sandcrawler/tasks/reingest_quarterly_cdx-error_bulk_current.rows.json | shuf > /srv/sandcrawler/tasks/reingest_quarterly_cdx-error_bulk_current.json
-sudo -u sandcrawler pipenv run ./scripts/ingestrequest_row2json.py /srv/sandcrawler/tasks/reingest_quarterly_wayback-error_current.rows.json | shuf > /srv/sandcrawler/tasks/reingest_quarterly_wayback-error_current.json
-sudo -u sandcrawler pipenv run ./scripts/ingestrequest_row2json.py /srv/sandcrawler/tasks/reingest_quarterly_gateway-timeout.rows.json | shuf > /srv/sandcrawler/tasks/reingest_quarterly_gateway-timeout.json
-sudo -u sandcrawler pipenv run ./scripts/ingestrequest_row2json.py /srv/sandcrawler/tasks/reingest_quarterly_petabox-error_current.rows.json | shuf > /srv/sandcrawler/tasks/reingest_quarterly_petabox-error_current.json
+sudo -u sandcrawler pipenv run \
+ ./scripts/ingestrequest_row2json.py /srv/sandcrawler/tasks/reingest_quarterly_current.rows.json \
+ > /srv/sandcrawler/tasks/reingest_quarterly_current.json
-cat /srv/sandcrawler/tasks/reingest_quarterly_spn2-error_current.json /srv/sandcrawler/tasks/reingest_quarterly_cdx-error_current.json /srv/sandcrawler/tasks/reingest_quarterly_wayback-error_current.json /srv/sandcrawler/tasks/reingest_quarterly_petabox-error_current.json /srv/sandcrawler/tasks/reingest_quarterly_gateway-timeout.json | shuf | head -n250000 | jq . -c | kafkacat -P -b wbgrp-svc263.us.archive.org -t sandcrawler-prod.ingest-file-requests-daily -p -1
-
-#cat /srv/sandcrawler/tasks/reingest_quarterly_cdx-error_bulk.json | shuf | jq . -c | kafkacat -P -b wbgrp-svc263.us.archive.org -t sandcrawler-prod.ingest-file-requests-bulk -p -1
+cat /srv/sandcrawler/tasks/reingest_quarterly_current.json \
+ | shuf \
+ | head -n120000 \
+ | jq . -c \
+ | kafkacat -P -b wbgrp-svc263.us.archive.org -t sandcrawler-prod.ingest-file-requests-daily -p -1
diff --git a/sql/reingest_spn.sh b/sql/reingest_spn.sh
new file mode 100755
index 0000000..6fb1e4b
--- /dev/null
+++ b/sql/reingest_spn.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+set -e # fail on error
+set -u # fail if variable not set in substitution
+set -o pipefail # fail if part of a '|' command fails
+
+sudo -u postgres psql sandcrawler < dump_reingest_spn.sql
+
+cd ../python
+sudo -u sandcrawler pipenv run \
+ ./scripts/ingestrequest_row2json.py /srv/sandcrawler/tasks/reingest_spn.rows.json \
+ > /srv/sandcrawler/tasks/reingest_spn.json
+
+cat /srv/sandcrawler/tasks/reingest_spn.json \
+ | shuf \
+ | head -n60000 \
+ | jq . -c \
+ | kafkacat -P -b wbgrp-svc263.us.archive.org -t sandcrawler-prod.ingest-file-requests-priority -p -1
+
diff --git a/sql/reingest_weekly.sh b/sql/reingest_weekly.sh
index 67ecabd..04ce39d 100755
--- a/sql/reingest_weekly.sh
+++ b/sql/reingest_weekly.sh
@@ -7,14 +7,13 @@ set -o pipefail # fail if part of a '|' command fails
sudo -u postgres psql sandcrawler < dump_reingest_weekly.sql
cd ../python
-sudo -u sandcrawler pipenv run ./scripts/ingestrequest_row2json.py /srv/sandcrawler/tasks/reingest_weekly_spn2-error_current.rows.json | shuf > /srv/sandcrawler/tasks/reingest_weekly_spn2-error_current.json
-sudo -u sandcrawler pipenv run ./scripts/ingestrequest_row2json.py /srv/sandcrawler/tasks/reingest_weekly_cdx-error_current.rows.json | shuf > /srv/sandcrawler/tasks/reingest_weekly_cdx-error_current.json
-#sudo -u sandcrawler pipenv run ./scripts/ingestrequest_row2json.py /srv/sandcrawler/tasks/reingest_weekly_cdx-error_bulk_current.rows.json | shuf > /srv/sandcrawler/tasks/reingest_weekly_cdx-error_bulk_current.json
-sudo -u sandcrawler pipenv run ./scripts/ingestrequest_row2json.py /srv/sandcrawler/tasks/reingest_weekly_wayback-error_current.rows.json | shuf > /srv/sandcrawler/tasks/reingest_weekly_wayback-error_current.json
-sudo -u sandcrawler pipenv run ./scripts/ingestrequest_row2json.py /srv/sandcrawler/tasks/reingest_weekly_gateway-timeout.rows.json | shuf > /srv/sandcrawler/tasks/reingest_weekly_gateway-timeout.json
-sudo -u sandcrawler pipenv run ./scripts/ingestrequest_row2json.py /srv/sandcrawler/tasks/reingest_weekly_petabox-error_current.rows.json | shuf > /srv/sandcrawler/tasks/reingest_weekly_petabox-error_current.json
+sudo -u sandcrawler pipenv run \
+ ./scripts/ingestrequest_row2json.py /srv/sandcrawler/tasks/reingest_weekly_current.rows.json \
+ > /srv/sandcrawler/tasks/reingest_weekly_current.json
-cat /srv/sandcrawler/tasks/reingest_weekly_spn2-error_current.json /srv/sandcrawler/tasks/reingest_weekly_cdx-error_current.json /srv/sandcrawler/tasks/reingest_weekly_wayback-error_current.json /srv/sandcrawler/tasks/reingest_weekly_petabox-error_current.json /srv/sandcrawler/tasks/reingest_weekly_gateway-timeout.json | shuf | head -n60000 | jq . -c | kafkacat -P -b wbgrp-svc263.us.archive.org -t sandcrawler-prod.ingest-file-requests-daily -p -1
-
-#cat /srv/sandcrawler/tasks/reingest_weekly_cdx-error_bulk.json | shuf | jq . -c | kafkacat -P -b wbgrp-svc263.us.archive.org -t sandcrawler-prod.ingest-file-requests-bulk -p -1
+cat /srv/sandcrawler/tasks/reingest_weekly_current.json \
+ | shuf \
+ | head -n60000 \
+ | jq . -c \
+ | kafkacat -P -b wbgrp-svc263.us.archive.org -t sandcrawler-prod.ingest-file-requests-daily -p -1