mirror of
https://github.com/whekin/household-bot.git
synced 2026-03-31 18:54:03 +00:00
fix: address CI and PR review feedback
Co-authored-by: claw <stanislavkalishin+claw@gmail.com>
This commit is contained in:
@@ -141,7 +141,7 @@ export async function createBotRuntimeApp(): Promise<BotRuntimeApp> {
|
||||
: null
|
||||
const scheduledDispatchScheduler =
|
||||
runtime.scheduledDispatch &&
|
||||
(runtime.scheduledDispatch.provider === 'self-hosted' || runtime.schedulerSharedSecret)
|
||||
(runtime.scheduledDispatch.provider === 'aws-eventbridge' || runtime.schedulerSharedSecret)
|
||||
? runtime.scheduledDispatch.provider === 'gcp-cloud-tasks'
|
||||
? createGcpScheduledDispatchScheduler({
|
||||
projectId: runtime.scheduledDispatch.projectId,
|
||||
|
||||
@@ -248,8 +248,14 @@ export function getBotRuntimeConfig(env: NodeJS.ProcessEnv = process.env): BotRu
|
||||
runtime.schedulerSharedSecret = schedulerSharedSecret
|
||||
}
|
||||
if (scheduledDispatch !== undefined) {
|
||||
if (scheduledDispatch.provider === 'self-hosted' && schedulerSharedSecret === undefined) {
|
||||
throw new Error('Self-hosted scheduled dispatch requires SCHEDULER_SHARED_SECRET')
|
||||
if (
|
||||
(scheduledDispatch.provider === 'self-hosted' ||
|
||||
scheduledDispatch.provider === 'gcp-cloud-tasks') &&
|
||||
schedulerSharedSecret === undefined
|
||||
) {
|
||||
throw new Error(
|
||||
`${scheduledDispatch.provider} scheduled dispatch requires SCHEDULER_SHARED_SECRET`
|
||||
)
|
||||
}
|
||||
|
||||
runtime.scheduledDispatch = scheduledDispatch
|
||||
|
||||
@@ -20,15 +20,15 @@ function parsePositiveInteger(name: string, fallback: number): number {
|
||||
return parsed
|
||||
}
|
||||
|
||||
async function runOnce() {
|
||||
const baseUrl = requireEnv('BOT_INTERNAL_BASE_URL').replace(/\/$/, '')
|
||||
const schedulerSecret = requireEnv('SCHEDULER_SHARED_SECRET')
|
||||
const dueScanLimit = parsePositiveInteger('SCHEDULER_DUE_SCAN_LIMIT', 25)
|
||||
|
||||
const response = await fetch(`${baseUrl}/jobs/dispatch-due?limit=${dueScanLimit}`, {
|
||||
async function runOnce(input: {
|
||||
baseUrl: string
|
||||
schedulerSecret: string
|
||||
dueScanLimit: number
|
||||
}) {
|
||||
const response = await fetch(`${input.baseUrl}/jobs/dispatch-due?limit=${input.dueScanLimit}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-household-scheduler-secret': schedulerSecret
|
||||
'x-household-scheduler-secret': input.schedulerSecret
|
||||
}
|
||||
})
|
||||
|
||||
@@ -51,6 +51,11 @@ async function runOnce() {
|
||||
|
||||
async function main() {
|
||||
const intervalMs = parsePositiveInteger('SCHEDULER_POLL_INTERVAL_MS', 60_000)
|
||||
const runConfig = {
|
||||
baseUrl: requireEnv('BOT_INTERNAL_BASE_URL').replace(/\/$/, ''),
|
||||
schedulerSecret: requireEnv('SCHEDULER_SHARED_SECRET'),
|
||||
dueScanLimit: parsePositiveInteger('SCHEDULER_DUE_SCAN_LIMIT', 25)
|
||||
}
|
||||
let stopping = false
|
||||
|
||||
const stop = () => {
|
||||
@@ -62,7 +67,7 @@ async function main() {
|
||||
|
||||
while (!stopping) {
|
||||
try {
|
||||
await runOnce()
|
||||
await runOnce(runConfig)
|
||||
} catch (error) {
|
||||
console.error(
|
||||
JSON.stringify({
|
||||
|
||||
Reference in New Issue
Block a user