switch to docker based runners starting with nostr

This commit is contained in:
Travis Shears 2025-05-22 12:23:39 +02:00
parent 3ffbfd9cd4
commit a1c3231081
8 changed files with 367 additions and 573 deletions

View file

@ -1,17 +1,22 @@
import pino from "pino";
import WebSocket from "ws";
import { lambdaRequestTracker, pinoLambdaDestination } from "pino-lambda";
import { MicroBlogBackend } from "./pocketbase";
// custom destination formatter
const destination = pinoLambdaDestination();
const logger = pino({}, destination);
const withRequest = lambdaRequestTracker();
const logger = pino();
const pb = new MicroBlogBackend(logger);
const fetcherNpub = process.env.NOSTR_FETCHER_NPUB!;
const myNpub = process.env.NOSTR_ID!;
const fetcherNpub = process.env.NOSTR_FETCHER_NPUB;
const myNpub = process.env.NOSTR_ID;
if (!fetcherNpub) {
logger.error("NOSTR_FETCHER_NPUB is not set");
throw new Error("NOSTR_FETCHER_NPUB is not set");
}
if (!myNpub) {
logger.error("NOSTR_ID is not set");
throw new Error("NOSTR_ID is not set");
}
type NostrTag = ["t" | "r" | "imeta", string];
type NostrEvent = [
@ -28,8 +33,8 @@ type NostrEvent = [
},
];
exports.run = async (event: any, context: any) => {
withRequest(event, context);
(async () => {
logger.info("Starting Nostr Fetcher");
const events: NostrEvent[] = [];
// figure out when the last post of wasved
@ -48,7 +53,7 @@ exports.run = async (event: any, context: any) => {
ws.on("error", logger.error);
ws.on("message", function message(data: Buffer) {
const decodedData = JSON.parse(
Buffer.from(data).toString("utf8")
Buffer.from(data).toString("utf8"),
) as NostrEvent;
logger.info({ decodedData }, "recived a message from nostr relay");
if (decodedData[0] === "EVENT") {
@ -62,7 +67,7 @@ exports.run = async (event: any, context: any) => {
"REQ",
fetcherNpub,
{ kinds: [1], authors: [myNpub], ...(since ? { since } : {}) },
])
]),
);
});
await new Promise((resolve) => setTimeout(resolve, 30000));
@ -89,9 +94,9 @@ exports.run = async (event: any, context: any) => {
{
remoteURL: url,
},
post.id
post.id,
);
}
}
}
};
})();