Skip to content

Commit

Permalink
Run adapter by name
Browse files Browse the repository at this point in the history
  • Loading branch information
vrtnd committed Sep 28, 2024
1 parent 6f96e63 commit 8e3974a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ functions:
memorySize: 1024
events:
- schedule: cron(1 * * * ? *)
runAdapterByName:
handler: src/handlers/runAdapterByName.default
timeout: 900
memorySize: 1024
dailyAggregateAllAdapters:
handler: src/handlers/dailyAggregateAllAdapters.default
timeout: 900
Expand Down
40 changes: 40 additions & 0 deletions src/handlers/runAdapterByName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { wrapScheduledLambda } from "../utils/wrap";

Check failure on line 1 in src/handlers/runAdapterByName.ts

View workflow job for this annotation

GitHub Actions / deploy

Argument of type 'RowList<Row[]>' is not assignable to parameter of type 'Record<string, RecordedBlocks> | undefined'.
import bridgeNetworks from "../data/bridgeNetworkData";
import { runAdapterToCurrentBlock } from "../utils/adapter";
import { sql } from "../utils/db";
import { BridgeNetwork } from "../data/types";

const handler = async (event: { bridgeName: string }) => {
try {
const { bridgeName } = event;

if (!bridgeName) {
throw new Error("Bridge name is required");
}

const bridge = bridgeNetworks.find((b: BridgeNetwork) => b.bridgeDbName === bridgeName);

if (!bridge) {
throw new Error(`Bridge ${bridgeName} not found`);
}

const lastRecordedBlocks = await sql`SELECT jsonb_object_agg(bridge_id::text, subresult) as result
FROM (
SELECT bridge_id, jsonb_build_object('startBlock', MIN(tx_block), 'endBlock', MAX(tx_block)) as subresult
FROM bridges.transactions
GROUP BY bridge_id
) subquery;
`;

console.log(`Running adapter for ${bridgeName}`);
await runAdapterToCurrentBlock(bridge, true, "ignore", lastRecordedBlocks);
console.log(`Adapter for ${bridgeName} ran successfully`);
} catch (e) {
console.error(`Adapter ${event.bridgeName} failed: ${JSON.stringify(e)}`);
throw e;
} finally {
await sql.end();
}
};

export default wrapScheduledLambda(handler);

0 comments on commit 8e3974a

Please sign in to comment.