Skip to content

Commit

Permalink
fix: add missing status UnexpectedlyUnpinned (#1105)
Browse files Browse the repository at this point in the history
Pins cron is currently failing with:

```
Error: unknown tracker status: unexpectedly_unpinned
    at toPinStatusEnum (file:///home/runner/work/web3.storage/web3.storage/packages/api/src/utils/pin.js:52:11)
    at file:///home/runner/work/web3.storage/web3.storage/packages/cron/src/jobs/pins.js:67:20
    at Array.map (<anonymous>)
    at updatePinStatuses (file:///home/runner/work/web3.storage/web3.storage/packages/cron/src/jobs/pins.js:52:49)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async main (file:///home/runner/work/web3.storage/web3.storage/packages/cron/src/bin/pins.js:16:3)
```

https://github.com/web3-storage/web3.storage/runs/5509298651?check_suite_focus=true

...this is because we do not model this new status in our API code or in our DB schema yet.

resolves #912
  • Loading branch information
Alan Shaw authored Mar 11, 2022
1 parent d525324 commit 118ceb0
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 6 deletions.
6 changes: 4 additions & 2 deletions packages/api/src/utils/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
* | 'Remote'
* | 'PinQueued'
* | 'UnpinQueued'
* | 'Sharded'} PinStatus
* | 'Sharded'
* | 'UnexpectedlyUnpinned' } PinStatus
*/

/** @type {Record<TrackerStatus, PinStatus>} */
Expand All @@ -27,7 +28,8 @@ const PinStatusMap = {
remote: 'Remote',
pin_queued: 'PinQueued',
unpin_queued: 'UnpinQueued',
sharded: 'Sharded'
sharded: 'Sharded',
unexpectedly_unpinned: 'UnexpectedlyUnpinned'
}

// Duration between status check polls in ms.
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/utils/psa.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const psaStatusesToDBStatusesMap = {
queued: ['PinQueued'],
pinning: ['Pinning'],
failed: [
'UnexpectedlyUnpinned',
'ClusterError',
'PinError'
]
Expand Down
4 changes: 2 additions & 2 deletions packages/db/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ Start a docker compose with a Postgres Database and Postgrest.
npm start
```

### 2. Populate Database
### 2. Load schema

```bash
node scripts/cli.js db-sql --cargo --testing
npm run load-schema
```

### 3. Ready to go
Expand Down
1 change: 1 addition & 0 deletions packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"type": "module",
"scripts": {
"start": "node scripts/cli.js db --start --project web3-storage",
"load-schema": "node scripts/cli.js db-sql --cargo --testing",
"stop": "node scripts/cli.js db --stop --project web3-storage",
"stop:clean": "node scripts/cli.js db --stop --clean --project web3-storage",
"pg-rest-api-types": "./scripts/cli.js pg-rest-api-types",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TYPE pin_status_type ADD VALUE 'UnexpectedlyUnpinned';
3 changes: 2 additions & 1 deletion packages/db/postgres/pg-rest-api-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2089,7 +2089,8 @@ export interface definitions {
| "Remote"
| "PinQueued"
| "UnpinQueued"
| "Sharded";
| "Sharded"
| "UnexpectedlyUnpinned";
/**
* Format: text
* @description Note:
Expand Down
4 changes: 3 additions & 1 deletion packages/db/postgres/tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ BEGIN
'UnpinQueued',
-- The IPFS daemon is not pinning the item through this CID but it is tracked
-- in a cluster dag
'Sharded'
'Sharded',
-- The item should be pinned, but it is not pinned and not queued/pinning.
'UnexpectedlyUnpinned'
);
END IF;
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'upload_type') THEN
Expand Down
4 changes: 4 additions & 0 deletions packages/db/scripts/cmds/pg-rest-api-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import { dbSqlCmd } from './db-sql.js'

export async function dbTypesCmd () {
const project = `web3-storage-pg-rest-api-types-${Date.now()}`
console.log('Starting DB...')
await dbCmd({ start: true, project })
await delay(2000)

try {
console.log('Loading schema...')
await dbSqlCmd({ cargo: true, testing: true })
await delay(2000) // it takes a moment for postgrest to update
console.log('Generating types...')
const url = `${process.env.PG_REST_URL}/?apikey=${process.env.PG_REST_JWT}`
await execa(
'openapi-typescript',
Expand Down

0 comments on commit 118ceb0

Please sign in to comment.