Skip to content

Instantly share code, notes, and snippets.

@wtachau
Created July 7, 2023 20:52
Show Gist options
  • Select an option

  • Save wtachau/fb0ad5688a8b324d850deb0c191185d7 to your computer and use it in GitHub Desktop.

Select an option

Save wtachau/fb0ad5688a8b324d850deb0c191185d7 to your computer and use it in GitHub Desktop.
api/cron endpoint
import { noopQuery } from '$lib/server/neo4j';
import { success } from '$lib/server/response';
import { isProd } from '@common/environment';
import type { RequestHandler } from './$types';
export const GET: RequestHandler = async ({ locals: { ctx } }) => {
ctx.log('[CRON JOB RUNNING]');
await noopQuery(ctx);
// Vercel doesn't run cron jobs in Preview, so manually ping the /api/cron endpoint when
// the prod cronjob runs
if (isProd) {
ctx.log('[Triggering Preview Cron]');
await fetch('https://preview.whynemo.com/api/cron');
}
return success({});
};
@wtachau
Copy link
Copy Markdown
Author

wtachau commented Jul 7, 2023

/* noopQuery */

// This method is just used to "kick" AuraDB once a day in order to keep it running
export const noopQuery = async (ctx: RunContext) => {
  const session = neo4jDriver().session();
  await session.executeRead((tx) => tx.run(`MATCH (n) RETURN n`, {}));
  ctx.log('No-op query finished');
  await session.close();
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment