-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add scheduled event handler for running cron jobs (#6)
* add scheduled event handler for running cron jobs * schedule cron jobs to run every 4 hours * add strict type checking
- Loading branch information
1 parent
7fe81f5
commit 5005347
Showing
4 changed files
with
35 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { env } from '../types/global.types'; | ||
|
||
export const handleConfig = (env: env) => { | ||
let baseUrl: string; | ||
if (env.CURRENT_ENVIRONMENT) { | ||
if (env.CURRENT_ENVIRONMENT.toLowerCase() === 'production') { | ||
baseUrl = 'https://api.realdevsquad.com'; | ||
} else { | ||
baseUrl = 'https://staging-api.realdevsquad.com'; | ||
} | ||
} else { | ||
baseUrl = 'https://staging-api.realdevsquad.com'; | ||
} | ||
return { baseUrl }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { handleConfig } from '../config/config'; | ||
import { env } from '../types/global.types'; | ||
|
||
export async function ping(env: env) { | ||
const url = handleConfig(env); | ||
const response = await fetch(`${url.baseUrl}/healthcheck`); | ||
return response; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
import { ping } from './handlers/scheduledEventHandler'; | ||
import { env } from './types/global.types'; | ||
|
||
export default { | ||
// ToDo: remove the eslint disabled after proper implementation | ||
// We need to keep all 3 parameters in this format even if they are not used as as cloudflare workers need them to be present So we are disabling eslint rule of no-unused-vars | ||
// for more details read here: https://community.cloudflare.com/t/waituntil-is-not-a-function-when-using-workers-with-modules/375781/4 | ||
// eslint-disable-next-line no-unused-vars | ||
async fetch(request: Request, env: env, ctx: ExecutionContext): Promise<Response> { | ||
async scheduled(req: Request, env: env, ctx: ExecutionContext) { | ||
ctx.waitUntil(ping(env)); | ||
}, | ||
// We need to keep all 3 parameters in this format even if they are not used as as cloudflare workers need them to be present So we are disabling eslint rule of no-unused-vars | ||
// for more details read here: https://community.cloudflare.com/t/waituntil-is-not-a-function-when-using-workers-with-modules/375781/4 | ||
// eslint-disable-next-line no-unused-vars | ||
async fetch(req: Request, env: env, ctx: ExecutionContext): Promise<Response> { | ||
return new Response('Hello World!'); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters