Skip to content

Commit

Permalink
feat(scripts): main function stub
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOrz committed May 13, 2024
1 parent 0179daa commit 8aa0a79
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,31 @@ $ node_modules/.bin/babel-node src/scripts/fetchStatsFromGA.js

### Pulling administrative commands from Google Pub/Sub

#### Setup

Please use the following command to set up the Pub/Sub topic and subscription, with a Google cloud account with sufficient permissions:

```
# Setup ADMIN_PUBSUB_TOPIC
# You can change topic to your need.
export ADMIN_PUBSUB_TOPIC=rumors-api-commands
# Create a Pub/Sub topic
gcloud pubsub topics create $ADMIN_PUBSUB_TOPIC --schema=${}
# Create a Pub/Sub subscription
gcloud pubsub subscriptions create ${ADMIN_PUBSUB_TOPIC}-subscription --topic=${ADMIN_PUBSUB_TOPIC}
```

Remember to update `ADMIN_PUBSUB_TOPIC` in `.env` and in runtime environment.

#### Runtime config

When API server starts up, it will link to Google Pub/Sub topic if and only if env var `ADMIN_PUBSUB_TOPIC` is set, using [Application Default Credentials](https://cloud.google.com/docs/authentication/application-default-credentials).

The service account behind the key in previous step should have the following [minimum roles](https://cloud.google.com/pubsub/docs/access-control#iam_roles):
- `Pub/Sub Subscriber` on the GCP project

### Removing article-reply from database
- To set an article-reply to deleted state on production, run:
```
Expand Down
15 changes: 13 additions & 2 deletions src/commandListener.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
type T = { foo: number };
async function main() {
if (!process.env.ADMIN_PUBSUB_TOPIC) {
console.info(
'[command-listener] `ADMIN_PUBSUB_TOPIC` is not set, exiting...'
);
process.exit(0);
}

console.log('commandServer.ts');
/**
* Subscribe to specified topics
*/
}

main().catch(err => console.error('[command-listener]', err));
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"target": "ESNext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true
Expand Down

0 comments on commit 8aa0a79

Please sign in to comment.