Skip to content

Commit 9907472

Browse files
committed
chore: extract cron changes
cron changes now in #2339 License: MIT Signed-off-by: Oli Evans <oli@protocol.ai>
1 parent 721b2e8 commit 9907472

6 files changed

Lines changed: 8 additions & 60 deletions

File tree

.github/workflows/cron-pins-failed.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ jobs:
1717
strategy:
1818
matrix:
1919
env: ['production']
20-
include:
21-
- env: production
22-
pickup_url: http://pickup.dag.haus
2320
steps:
2421
- uses: actions/checkout@v2
2522
with:
@@ -44,7 +41,5 @@ jobs:
4441
CLUSTER2_BASIC_AUTH_TOKEN: ${{ secrets.CLUSTER2_BASIC_AUTH_TOKEN }}
4542
CLUSTER3_API_URL: ${{ secrets.CLUSTER3_API_URL }}
4643
CLUSTER3_BASIC_AUTH_TOKEN: ${{ secrets.CLUSTER3_BASIC_AUTH_TOKEN }}
47-
PICKUP_URL: ${{ matrix.pickup_url }}
48-
PICKUP_BASIC_AUTH_TOKEN: ${{ secrets.PICKUP_BASIC_AUTH_TOKEN }}
4944
AFTER: ${{ github.event.inputs.after }}
5045
run: yarn --cwd packages/cron start:pins-failed

.github/workflows/cron-pins.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ jobs:
1212
strategy:
1313
matrix:
1414
env: ['staging', 'production']
15-
include:
16-
- env: production
17-
pickup_url: http://pickup.dag.haus
18-
- env: staging
19-
pickup_url: http://staging.pickup.dag.haus
2015
timeout-minutes: 60
2116
steps:
2217
- uses: actions/checkout@v2
@@ -42,8 +37,6 @@ jobs:
4237
CLUSTER2_BASIC_AUTH_TOKEN: ${{ secrets.CLUSTER2_BASIC_AUTH_TOKEN }}
4338
CLUSTER3_API_URL: ${{ secrets.CLUSTER3_API_URL }}
4439
CLUSTER3_BASIC_AUTH_TOKEN: ${{ secrets.CLUSTER3_BASIC_AUTH_TOKEN }}
45-
PICKUP_URL: ${{ matrix.pickup_url }}
46-
PICKUP_BASIC_AUTH_TOKEN: ${{ secrets.PICKUP_BASIC_AUTH_TOKEN }}
4740
run: yarn --cwd packages/cron start:pins
4841
- name: Heartbeat
4942
if: ${{ success() }}

packages/cron/src/bin/pins-failed.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@ import { fileURLToPath } from 'url'
55
import dotenv from 'dotenv'
66
import fetch from '@web-std/fetch'
77
import { checkFailedPinStatuses } from '../jobs/pins.js'
8-
import {
9-
getPg,
10-
getCluster1,
11-
getCluster2,
12-
getCluster3,
13-
getPickup,
14-
} from '../lib/utils.js'
8+
import { getPg, getCluster1, getCluster2, getCluster3 } from '../lib/utils.js'
159

1610
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1711
global.fetch = fetch
@@ -27,19 +21,11 @@ async function main() {
2721
const cluster1 = getCluster1(process.env)
2822
const cluster2 = getCluster2(process.env)
2923
const cluster3 = getCluster3(process.env)
30-
const pickup = getPickup(process.env)
3124
const after = process.env.AFTER
3225
? new Date(process.env.AFTER)
3326
: oneMonthAgo()
3427

35-
await checkFailedPinStatuses({
36-
pg,
37-
cluster1,
38-
cluster2,
39-
cluster3,
40-
pickup,
41-
after,
42-
})
28+
await checkFailedPinStatuses({ pg, cluster1, cluster2, cluster3, after })
4329
} finally {
4430
await pg.end()
4531
}

packages/cron/src/bin/pins.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@ import { fileURLToPath } from 'url'
55
import dotenv from 'dotenv'
66
import fetch from '@web-std/fetch'
77
import { updatePendingPinStatuses } from '../jobs/pins.js'
8-
import {
9-
getPg,
10-
getCluster1,
11-
getCluster2,
12-
getCluster3,
13-
getPickup,
14-
} from '../lib/utils.js'
8+
import { getPg, getCluster1, getCluster2, getCluster3 } from '../lib/utils.js'
159

1610
const __dirname = path.dirname(fileURLToPath(import.meta.url))
1711
global.fetch = fetch
@@ -24,9 +18,8 @@ async function main() {
2418
const cluster1 = getCluster1(process.env)
2519
const cluster2 = getCluster2(process.env)
2620
const cluster3 = getCluster3(process.env)
27-
const pickup = getPickup(process.env)
2821

29-
await updatePendingPinStatuses({ pg, cluster1, cluster2, cluster3, pickup })
22+
await updatePendingPinStatuses({ pg, cluster1, cluster2, cluster3 })
3023
} finally {
3124
await pg.end()
3225
}

packages/cron/src/jobs/pins.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ const CONCURRENCY = 5
88
* http://nginx.org/en/docs/http/ngx_http_core_module.html#large_client_header_buffers
99
*/
1010
const MAX_CLUSTER_STATUS_CIDS = 120
11-
/**
12-
* @typedef {import('../../../api/src/utils/db-types').definitions} definitions
13-
* @type Array<definitions["pin"]["service"]>
14-
**/
15-
const CLUSTERS = ['IpfsCluster', 'IpfsCluster2', 'IpfsCluster3', 'ElasticIpfs']
11+
const CLUSTERS = ['IpfsCluster', 'IpfsCluster2', 'IpfsCluster3']
1612

1713
/**
1814
* @typedef {import('pg').Client} Client
@@ -21,8 +17,8 @@ const CLUSTERS = ['IpfsCluster', 'IpfsCluster2', 'IpfsCluster3', 'ElasticIpfs']
2117
* cluster1: import('@nftstorage/ipfs-cluster').Cluster
2218
* cluster2: import('@nftstorage/ipfs-cluster').Cluster
2319
* cluster3: import('@nftstorage/ipfs-cluster').Cluster
24-
* pickup: import('@nftstorage/ipfs-cluster').Cluster
2520
* }} Config
21+
* @typedef {import('../../../api/src/utils/db-types').definitions} definitions
2622
* @typedef {Pick<definitions['pin'], 'id'|'status'|'service'|'inserted_at'|'updated_at'> & { source_cid: string }} Pin
2723
* @typedef {import('@supabase/postgrest-js').PostgrestQueryBuilder<Pin>} PinQuery
2824
*/
@@ -149,7 +145,7 @@ UPDATE pin AS p
149145
* }} config
150146
*/
151147
async function updatePinStatuses(config) {
152-
const { countPins, fetchPins, pg, pickup } = config
148+
const { countPins, fetchPins, pg, cluster3 } = config
153149
if (!log.enabled) {
154150
console.log('ℹ️ Enable logging by setting DEBUG=pins:updatePinStatuses')
155151
}
@@ -186,7 +182,7 @@ async function updatePinStatuses(config) {
186182
/** @type {Pin[]} */
187183
const updatedPins = []
188184
const cids = pins.map((p) => p.source_cid)
189-
const statuses = await pickup.statusAll({ cids })
185+
const statuses = await cluster3.statusAll({ cids })
190186
const statusByCid = Object.fromEntries(statuses.map((s) => [s.cid, s]))
191187

192188
for (const pin of pins) {

packages/cron/src/lib/utils.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,6 @@ export function getCluster3(env) {
4444
})
4545
}
4646

47-
/**
48-
* Create a new IPFS Cluster instance from the passed environment variables.
49-
* @param {Record<string, string|undefined>} env
50-
*/
51-
export function getPickup(env) {
52-
const pickupUrl = env.PICKUP_URL
53-
if (!pickupUrl) throw new Error('PICKUP_URL must be set in env')
54-
const basicAuthToken = env.PICKUP_BASIC_AUTH_TOKEN
55-
if (!basicAuthToken)
56-
throw new Error('PICKUP_BASIC_AUTH_TOKEN must be set in env')
57-
return new Cluster(pickupUrl, {
58-
headers: { authorization: `Basic ${basicAuthToken}` },
59-
})
60-
}
61-
6247
/**
6348
* Create a new DBClient instance from the passed environment variables.
6449
* @param {Record<string, string|undefined>} env

0 commit comments

Comments
 (0)