get and store last run time in ssm
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'websocket-polyfill'
|
||||
import { SSMClient, GetParameterCommand, PutParameterCommand } from '@aws-sdk/client-ssm'
|
||||
import { extract } from '@extractus/feed-extractor'
|
||||
import NDK, { NDKEvent, NDKPrivateKeySigner } from '@nostr-dev-kit/ndk'
|
||||
import bech32 from 'bech32-buffer'
|
||||
@@ -17,7 +18,30 @@ export const handler = async (event) => {
|
||||
const region = process.env.AWS_REGION || "us-east-1"
|
||||
const feed = event.feedUrl
|
||||
const privkey = toHexString(event.nostrNsec)
|
||||
const since = event.since
|
||||
const lastRunTimeParam = event.lastRunTimeParam
|
||||
|
||||
let response = {
|
||||
totalItems: 0,
|
||||
successes: 0,
|
||||
errors: []
|
||||
}
|
||||
|
||||
const ssmClient = new SSMClient({ region })
|
||||
const params = {
|
||||
Name: lastRunTimeParam
|
||||
}
|
||||
const ssmGetCommand = new GetParameterCommand(params);
|
||||
|
||||
let since = ""
|
||||
ssmClient.send(ssmGetCommand)
|
||||
.then(data => {
|
||||
since = data.Parameter.Value
|
||||
}).catch(err => {
|
||||
console.error(err)
|
||||
response.errors.push(err)
|
||||
return response
|
||||
})
|
||||
|
||||
|
||||
if (feed === "") {
|
||||
console.error("feedUrl was not set.")
|
||||
@@ -26,13 +50,7 @@ export const handler = async (event) => {
|
||||
body: "feedUrl must be provided in payload."
|
||||
}
|
||||
}
|
||||
|
||||
let response = {
|
||||
totalItems: 0,
|
||||
successes: 0,
|
||||
errors: []
|
||||
}
|
||||
|
||||
|
||||
const ndk = new NDK({
|
||||
signer: new NDKPrivateKeySigner(privkey),
|
||||
explicitRelayUrls: [
|
||||
@@ -80,6 +98,19 @@ export const handler = async (event) => {
|
||||
}
|
||||
}
|
||||
|
||||
params.Name = lastRunTimeParam
|
||||
params.Value = new Date().toISOString()
|
||||
params.Type = "String"
|
||||
params.Overwrite = true
|
||||
|
||||
const ssmPutCommand = new PutParameterCommand(params)
|
||||
ssmClient.send(ssmPutCommand)
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
response.errors.push(err)
|
||||
return response
|
||||
})
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user