Skip to content

Commit

Permalink
bin/s3/upload-pending: handle missing pgrowlocks extension (#1325)
Browse files Browse the repository at this point in the history
Closes #812
  • Loading branch information
alxndrsn authored Dec 6, 2024
1 parent fbcdf07 commit 50ac888
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/task/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,26 @@ const assertEnabled = s3 => {
}
};

const isMissingRowlocks = err => err.code === '42883' && err.message === 'function pgrowlocks(unknown) does not exist';

const getUploadCount = async (Blobs, limit) => {
try {
const pendingCount = await Blobs.s3CountByStatus('pending');
return limit ? Math.min(pendingCount, limit) : pendingCount;
} catch (err) {
if (isMissingRowlocks(err)) return limit;
else throw err;
}
};

const getCount = withContainer(({ s3, Blobs }) => async status => {
assertEnabled(s3);
try {
const count = await Blobs.s3CountByStatus(status);
console.log(count);
return count; // just for testing
} catch (err) {
if (err.code === '42883' && err.message === 'function pgrowlocks(unknown) does not exist') {
if (isMissingRowlocks(err)) {
console.error(`
Error: cannot count blobs by status due to missing PostgreSQL extension: PGROWLOCKS.
Expand All @@ -49,8 +61,7 @@ const setFailedToPending = withContainer(({ s3, Blobs }) => async () => {
const uploadPending = withContainer(({ s3, Blobs }) => async (limit) => {
assertEnabled(s3);

const pendingCount = await Blobs.s3CountByStatus('pending');
const count = limit ? Math.min(pendingCount, limit) : pendingCount;
const count = await getUploadCount(Blobs, limit);

const signals = ['SIGINT', 'SIGTERM'];

Expand All @@ -61,7 +72,7 @@ const uploadPending = withContainer(({ s3, Blobs }) => async (limit) => {
signals.forEach(s => process.once(s, shutdownListener));

try {
console.log(`Uploading ${count} blobs...`);
console.log(`Uploading ${count ?? 'all'} blobs...`);
await Blobs.s3UploadPending(limit);
console.log(`[${new Date().toISOString()}]`, 'Upload completed.');
} finally {
Expand Down

0 comments on commit 50ac888

Please sign in to comment.