Skip to content

Commit

Permalink
Migrate from Cloudflare Cron Triggers to Deno Cron (#56)
Browse files Browse the repository at this point in the history
* wip

* Update deno.jsonc

* rt: replace custom router

* delete deps.ts, add discord_app

* fix lint errors

TODO: Fix failing tests.

* Update cron.ts

* add unregister subcommand

* add lc daily question number to embed title

* add cron jobs

* Update check.yaml

* Update check.yaml

* Update deno.jsonc

https://docs.deno.com/runtime/manual/basics/env_variables/
  • Loading branch information
EthanThatOneKid authored Aug 4, 2024
1 parent 77a207a commit 107952f
Show file tree
Hide file tree
Showing 42 changed files with 696 additions and 1,429 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PORT=8080
WEBHOOK_TOKEN=""
DISCORD_APPLICATION_ID=""
DISCORD_TOKEN=""
DISCORD_PUBLIC_KEY=""
DISCORD_WEBHOOK_URL=""
DISCORD_CHANNEL_ID=""
KV_URL=""
28 changes: 0 additions & 28 deletions .github/workflows/cf.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ jobs:
- name: Lint
run: deno lint && git diff-index --quiet HEAD

- name: Test
run: deno task test
# - name: Test
# run: deno task test
24 changes: 1 addition & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,7 @@ The server is automatically deployed on push to the `main` branch via

### Daily webhook invocation

The daily webhook is invoked by making a POST request to the `/webhook/:token`
endpoint.

Set up a cron job to make the request at the desired time. Supabase supports
cron jobs via the
[pg_cron](https://supabase.com/docs/guides/database/extensions/pg_cron)
extension.

```sql
select cron.unschedule('lc-daily');

select
cron.schedule(
'lc-daily',
'0 0 * * *', -- https://crontab.guru/#0_0_*_*_*
$$
select
net.http_post(
url:='...',
) as request_id;
$$
);
```
The daily webhook is invoked by a daily Deno Cron job.

---

Expand Down
16 changes: 8 additions & 8 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"lock": "./deno.lock",
"tasks": {
"udd": "deno run -r --allow-read=. --allow-write=. --allow-net https://deno.land/x/udd/main.ts deps.ts && deno task lock",
"lock": "deno cache --lock-write deps.ts",
"all": "deno task udd && deno lint && deno fmt",
"test": "deno test --unstable",
"start": "deno run -A --unstable main.ts",
"test": "deno test --unstable-kv",
"start": "deno run -A --env --unstable-kv main.ts",
"ngrok": "ngrok http 8080",
"cf:push": "deno run -A tasks/cf/dailies/push/main.ts",
"cf:serve": "deno run -A tasks/cf/dailies/serve/main.ts",
"dnt": "deno run -A tasks/dnt/main.ts"
},
"imports": {
"@discord-applications/app": "jsr:@discord-applications/app@^0.0.4",
"@fartlabs/rt": "jsr:@fartlabs/rt@^0.0.3",
"@std/assert": "jsr:@std/assert@^0.225.3",
"@std/datetime": "jsr:@std/datetime@^0.224.0",
"@std/ulid": "jsr:@std/ulid@^0.224.0",
"discord-api-types": "npm:discord-api-types@^0.37.93",
"lc-dailies/": "./"
},
"fmt": {
Expand Down
366 changes: 255 additions & 111 deletions deno.lock

Large diffs are not rendered by default.

27 changes: 0 additions & 27 deletions deps.ts

This file was deleted.

45 changes: 0 additions & 45 deletions env.ts

This file was deleted.

Loading

0 comments on commit 107952f

Please sign in to comment.