-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update proposition-tag-scorer lambda to new setup (#653)
* Convert proposition-tag-scorer to new lambda setup Signed-off-by: Carl Gieringer <[email protected]> * Bump version proposition-tag-scorer: 1.1.0 Signed-off-by: Carl Gieringer <[email protected]> * Standardize pg version Signed-off-by: Carl Gieringer <[email protected]> * Bump version proposition-tag-scorer: 1.2.0 Signed-off-by: Carl Gieringer <[email protected]> * Add issues to TODOs Signed-off-by: Carl Gieringer <[email protected]> * Fix test todo command Signed-off-by: Carl Gieringer <[email protected]> * Update readme steps Signed-off-by: Carl Gieringer <[email protected]> --------- Signed-off-by: Carl Gieringer <[email protected]>
- Loading branch information
1 parent
7e5c04e
commit c90f6ef
Showing
35 changed files
with
184 additions
and
229 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Context } from "aws-lambda"; | ||
|
||
export const configureHandlerContext = (context: Context) => { | ||
// Otherwise the pg.Pool timeout keeps us alive | ||
context.callbackWaitsForEmptyEventLoop = false; | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,8 @@ | |
"lint": "eslint --ignore-path=.gitignore .", | ||
"release": "../bin/release.sh ../../howdju-text-fragments/dist/rangeToFragment.js", | ||
"test": "jest", | ||
"test-inspect": "node --inspect-brk ../../node_modules/.bin/jest --runInBand --watch" | ||
"test-inspect": "node --inspect-brk ../../node_modules/.bin/jest --runInBand --watch", | ||
"typecheck": "tsc" | ||
}, | ||
"author": "Carl Gieringer <[email protected]>", | ||
"license": "AGPL-3.0-or-later", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
overrides: [ | ||
{ | ||
files: ["**/*.{js,ts}"], | ||
excludedFiles: ["node_modules/**"], | ||
extends: ["howdju/node"], | ||
}, | ||
], | ||
parserOptions: { | ||
project: ["./tsconfig.json"], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/dist/ | ||
/coverage/ |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# howdju-message-handler | ||
|
||
This lambda scores proposition tag votes. It should be run on a schedule. | ||
|
||
## Releasing | ||
|
||
```sh | ||
aws-vault exec username@howdju -- yarn run release | ||
``` | ||
|
||
(See the section in Development.md about setting up aws-vault.) | ||
|
||
Then: | ||
|
||
- Update the Lambda's code in the AWS console by copy/pasting the new ZIP file's S3 location. | ||
- Publish a new version of the Lambda | ||
- Update the `prod` alias to point to the new version. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import baseConfig from "../../jest.config.base"; | ||
export default baseConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "proposition-tag-scorer", | ||
"version": "1.2.0", | ||
"description": "Scores tags for propositions", | ||
"main": "index.ts", | ||
"repository": "[email protected]:howdju/howdju.git", | ||
"author": "Carl Gieringer <[email protected]>", | ||
"license": "AGPL-3.0-or-later", | ||
"scripts": { | ||
"build": "node ../../premiser-api/bin/esbuild.js --entryPoint=src/handler.ts --outfile=dist/index.js", | ||
"check-format": "yarn run prettier --check --ignore-path .gitignore .", | ||
"clean": "rm -rf dist", | ||
"fix-format": "yarn run lint --fix && yarn run prettier --write --ignore-path .gitignore .", | ||
"lint": "eslint --ignore-path=.gitignore .", | ||
"release": "../bin/release.sh ../../howdju-text-fragments/dist/rangeToFragment.js", | ||
"test": "echo 'TODO(#654) add tests'", | ||
"test-inspect": "echo 'TODO(#654) add tests'", | ||
"typecheck": "tsc" | ||
}, | ||
"dependencies": { | ||
"pg": "^8.6.0" | ||
}, | ||
"devDependencies": { | ||
"esbuild": "^0.18.17", | ||
"eslint": "^8.27.0", | ||
"eslint-config-howdju": "workspace:eslint-config-howdju", | ||
"jest": "^29.3.1", | ||
"prettier": "2.7.1", | ||
"typescript": "4.9.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Context, ScheduledEvent } from "aws-lambda"; | ||
|
||
import { configureHandlerContext } from "howdju-service-common"; | ||
|
||
import { propositionTagScoresService, logger } from "./initialization"; | ||
|
||
export async function handler(event: ScheduledEvent, context: Context) { | ||
configureHandlerContext(context); | ||
|
||
logger.silly({ gatewayContext: context, event }); | ||
|
||
logger.info("Scoring propositions…"); | ||
await propositionTagScoresService.updatePropositionTagScoresUsingUnscoredVotes(); | ||
logger.info("Scoring proposition tags succeeded."); | ||
} |
File renamed without changes.
32 changes: 32 additions & 0 deletions
32
lambdas/proposition-tag-scorer/src/initialization/databaseInitialization.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pg from "pg"; | ||
import { toNumber } from "lodash"; | ||
|
||
import { | ||
Database, | ||
makeTimestampToUtcMomentParser, | ||
PgTypeOids, | ||
} from "howdju-service-common"; | ||
|
||
import { logger } from "./loggerInitialization"; | ||
|
||
pg.types.setTypeParser( | ||
PgTypeOids.TIMESTAMP, | ||
makeTimestampToUtcMomentParser(logger) | ||
); | ||
|
||
const config = { | ||
user: process.env["DB_USER"], | ||
database: process.env["DB_NAME"], | ||
password: process.env["DB_PASSWORD"], | ||
host: process.env["DB_HOST"], | ||
port: toNumber(process.env["DB_PORT"]) || 5432, | ||
max: toNumber(process.env["DB_POOL_MAX_CLIENTS"]) || 10, | ||
idleTimeoutMillis: toNumber(process.env["DB_CLIENT_IDLE_TIMEOUT"]) || 10000, | ||
connectionTimeoutMillis: | ||
toNumber(process.env["DB_CLIENT_CONNECT_TIMEOUT"]) || 5000, | ||
}; | ||
|
||
export const pool = new pg.Pool(config); | ||
pool.on("error", (err) => logger.error("database pool error", { err })); | ||
|
||
export const database = new Database(logger, pool); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./initialization"; |
2 changes: 2 additions & 0 deletions
2
lambdas/proposition-tag-scorer/src/initialization/initialization.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./loggerInitialization"; | ||
export * from "./servicesInitialization"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
.../initialization/servicesInitialization.js → .../initialization/servicesInitialization.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"paths": { | ||
// Support project-relative imports | ||
"@/*": ["./lib/*"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
"author": "Carl Gieringer <[email protected]>", | ||
"license": "AGPL-3.0-or-later", | ||
"dependencies": { | ||
"pg": "^7.2.0" | ||
"pg": "^8.6.0" | ||
}, | ||
"scripts": { | ||
"check-format": "yarn run prettier --check --ignore-path .gitignore .", | ||
|
4 changes: 2 additions & 2 deletions
4
premiser-processing/lambda-functions/justification-scorer/src/handling.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
premiser-processing/lambda-functions/proposition-tag-scorer/lambdarc.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.