Skip to content

Commit

Permalink
chore: cron and pinpin rewire
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Oct 14, 2021
1 parent 36ac294 commit e758250
Show file tree
Hide file tree
Showing 23 changed files with 1,066 additions and 218 deletions.
53 changes: 15 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
},
"engines": {
"node": "16.x",
"npm": "7.x"
"npm": ">=7.x"
}
}
36 changes: 14 additions & 22 deletions packages/cron/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,22 @@ To run this locally you will need the following in your `packages/cron/.env` fil

```ini
ENV=dev
DATABASE=postgres

# PostgREST API URL
DEV_PG_REST_URL=http://localhost:3000
# PostgREST API token, for role "postgres", using secret value PGRST_JWT_SECRET from './postgres/docker/docker-compose.yml'
# https://postgrest.org/en/v8.0/tutorials/tut1.html#step-3-sign-a-token
DEV_PG_REST_JWT=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoicG9zdGdyZXMifQ.oM0SXF31Vs1nfwCaDxjlczE237KcNKhTpKEYxMX-jEU

# Connection string for locally running postgres used in tests
DEV_PG_CONNECTION=postgres://postgres:[email protected]:5432/postgres

# Cluster
CLUSTER_API_URL=http://127.0.0.1:9094/
CLUSTER_IPFS_PROXY_API_URL=http://127.0.0.1:9095/api/v0/

# Fauna
DEV_FAUNA_KEY="<your key here>"
```

Expand All @@ -31,25 +45,3 @@ Run the job:
```sh
npm run start:pins
```

### pinata

Fetch the oldest 600 PinRequests from the DB and pin them on Piñata

To run this locally you will need the following in your `packages/cron/.env` file:

```ini
ENV=dev
DEV_FAUNA_KEY="<your key here>"
PINATA_JWT="<your jwt here>"
```

You also need to have:

- a dev account and db set up on FaunaDB with the latest schema imported as per [../db/README.md](../db/README.md)

Run the job:

```sh
npm run start:pinata
```
3 changes: 2 additions & 1 deletion packages/cron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"start": "run-s start:*",
"start:metrics": "node src/bin/metrics.js",
"start:pins": "node src/bin/pins.js",
"start:pinata": "node src/bin/pinata.js"
"start:dagcargo:views": "NODE_TLS_REJECT_UNAUTHORIZED=0 node src/bin/dagcargo-views.js"
},
"author": "Alan Shaw",
"license": "(Apache-2.0 AND MIT)",
Expand All @@ -20,6 +20,7 @@
"debug": "^4.3.1",
"dotenv": "^9.0.2",
"limiter": "2.0.1",
"pg": "^8.7.1",
"node-fetch": "^2.6.1",
"p-retry": "^4.6.1",
"piggybacker": "^2.0.0"
Expand Down
19 changes: 19 additions & 0 deletions packages/cron/src/bin/dagcargo-views.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env node

import dotenv from 'dotenv'
import { refreshMaterializedViews } from '../jobs/dagcargo.js'
import { getPg } from '../lib/utils.js'

async function main () {
const pg = getPg(process.env)
await pg.connect()

try {
await refreshMaterializedViews({ pg })
} finally {
await pg.end()
}
}

dotenv.config()
main()
26 changes: 26 additions & 0 deletions packages/cron/src/jobs/dagcargo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import debug from 'debug'

/**
* Refreshes the materialized views.
*
* @param {{ pg: import('pg').Client }} config
*/
export async function refreshMaterializedViews ({ pg }) {
const log = debug('dagcargo:refreshMaterializedViews')
if (!log.enabled) {
console.log(
'ℹ️ Enable logging by setting DEBUG=dagcargo:refreshMaterializedViews'
)
}

log('🔁 REFRESH MATERIALIZED VIEW public.deal;')
await pg.query('REFRESH MATERIALIZED VIEW public.deal;')

log('🔁 REFRESH MATERIALIZED VIEW public.aggregate;')
await pg.query('REFRESH MATERIALIZED VIEW public.aggregate;')

log('🔁 REFRESH MATERIALIZED VIEW public.aggregate_entry;')
await pg.query('REFRESH MATERIALIZED VIEW public.aggregate_entry;')

log('✅ Done')
}
Loading

0 comments on commit e758250

Please sign in to comment.