diff --git a/indexer-js-queue-handler/latest-post-metrics-writer.js b/indexer-js-queue-handler/latest-post-metrics-writer.js new file mode 100644 index 000000000..0bece2657 --- /dev/null +++ b/indexer-js-queue-handler/latest-post-metrics-writer.js @@ -0,0 +1,24 @@ +import fetch from "node-fetch"; +import AWS from "aws-sdk"; + +import Metrics from "./metrics"; + +export const handler = async () => { + const metrics = new Metrics("QueryAPI"); + + const response = await fetch("https://api.near.social/index", { + method: "POST", + body: JSON.stringify({ + action: "post", + key: "main", + options: { + limit: 1, + order: "desc", + }, + }), + }); + + const [{ blockHeight }] = await response.json(); + + await metrics.putBlockHeight("social.near", "posts", blockHeight); +}; diff --git a/indexer-js-queue-handler/serverless.yml b/indexer-js-queue-handler/serverless.yml index 62f09cede..c89b29d5c 100644 --- a/indexer-js-queue-handler/serverless.yml +++ b/indexer-js-queue-handler/serverless.yml @@ -39,6 +39,10 @@ constructs: timeout: 15 # 1.5 minutes as lift multiplies this value by 6 (https://github.com/getlift/lift/blob/master/docs/queue.md#retry-delay) functions: + latestPostMetricsWriter: + handler: latest-post-metrics-writer.handler + events: + - schedule: rate(1 minute) plugins: - serverless-lift