Skip to content

Commit

Permalink
Clean up workers a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
lemonmade committed Apr 13, 2024
1 parent 7bfdc88 commit b70cf3e
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 89 deletions.
3 changes: 1 addition & 2 deletions functions/clips-upload/configuration/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ name = "watch-internal-upload-clips"
main = "../build/output/clips-upload.js"

account_id = "9bfdb755def60e50760e33036c6f1624"
compatibility_date = "2022-06-04"
compatibility_date = "2024-04-05"

logpush = true
usage_model = "unbound"
workers_dev = false

# Needs secrets:
Expand Down
2 changes: 1 addition & 1 deletion functions/clips-upload/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"deploy": "wrangler deploy --config ./configuration/wrangler.toml"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20221111.1",
"@cloudflare/workers-types": "^4.20240405.0",
"@quilted/request-router": "^0.2.0",
"@tsndr/cloudflare-worker-jwt": "^2.1.0"
}
Expand Down
3 changes: 1 addition & 2 deletions functions/email/configuration/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ name = "watch-email"
main = "../build/output/index.js"

account_id = "9bfdb755def60e50760e33036c6f1624"
compatibility_date = "2022-06-04"
compatibility_date = "2024-04-05"

logpush = true
usage_model = "unbound"
workers_dev = false

# Needs the following environment variables:
Expand Down
2 changes: 1 addition & 1 deletion functions/email/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"deploy": "wrangler deploy --config ./configuration/wrangler.toml"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20221111.1",
"@cloudflare/workers-types": "^4.20240405.0",
"@quilted/react-email": "^0.3.1",
"@quilted/request-router": "^0.2.0",
"@tsndr/cloudflare-worker-jwt": "^2.1.0",
Expand Down
3 changes: 1 addition & 2 deletions functions/images/configuration/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ name = "watch-images"
main = "../build/output/images.js"

account_id = "9bfdb755def60e50760e33036c6f1624"
compatibility_date = "2023-02-06"
compatibility_date = "2024-04-05"

logpush = true
usage_model = "unbound"
workers_dev = false
2 changes: 1 addition & 1 deletion functions/images/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"deploy": "wrangler deploy --config ./configuration/wrangler.toml"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20221111.1"
"@cloudflare/workers-types": "^4.20240405.0"
}
}
3 changes: 1 addition & 2 deletions functions/metrics/configuration/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ name = "watch-metrics"
main = "../build/output/metrics.js"

account_id = "9bfdb755def60e50760e33036c6f1624"
compatibility_date = "2022-06-04"
compatibility_date = "2024-04-05"

logpush = true
usage_model = "unbound"
workers_dev = false

[[kv_namespaces]]
Expand Down
2 changes: 1 addition & 1 deletion functions/metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"deploy": "wrangler deploy --config ./configuration/wrangler.toml"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20221111.1",
"@cloudflare/workers-types": "^4.20240405.0",
"@quilted/request-router": "^0.2.0"
}
}
3 changes: 1 addition & 2 deletions functions/router/configuration/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ name = "watch-router"
main = "../build/output/router.js"

account_id = "9bfdb755def60e50760e33036c6f1624"
compatibility_date = "2022-06-04"
compatibility_date = "2024-04-05"

logpush = true
usage_model = "unbound"
workers_dev = false

[[services]]
Expand Down
2 changes: 1 addition & 1 deletion functions/router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"deploy": "wrangler deploy --config ./configuration/wrangler.toml"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20221111.1",
"@cloudflare/workers-types": "^4.20240405.0",
"@quilted/request-router": "^0.2.0",
"globby": "^14.0.0"
}
Expand Down
6 changes: 1 addition & 5 deletions functions/stripe-hooks/configuration/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ name = "watch-stripe"
main = "../build/output/stripe.js"

account_id = "9bfdb755def60e50760e33036c6f1624"
compatibility_date = "2024-03-29"
compatibility_flags = ["nodejs_compat"]
compatibility_date = "2024-04-05"

logpush = true
workers_dev = false

[limits]
cpu_ms = 500

[[services]]
binding = "EMAIL_SERVICE"
service = "watch-email"
Expand Down
2 changes: 1 addition & 1 deletion functions/stripe-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"deploy": "wrangler deploy --config ./configuration/wrangler.toml"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20221111.1",
"@cloudflare/workers-types": "^4.20240405.0",
"@quilted/request-router": "^0.2.0",
"@tsndr/cloudflare-worker-jwt": "^2.1.0",
"stripe": "^14.24.0"
Expand Down
2 changes: 2 additions & 0 deletions functions/tmdb-refresher/handlers/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {updateSeries} from '~/global/tmdb.ts';
import {createPrisma, type Environment} from './shared.ts';

export async function handleFetch(request: Request, env: Environment) {
console.log(`Handling fetch request: ${request.url}`);

if (request.method !== 'POST') {
// response with method not allowed status
return new Response(
Expand Down
61 changes: 32 additions & 29 deletions functions/tmdb-refresher/handlers/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,41 @@ export async function handleQueue(
batch: MessageBatch<Message>,
env: Environment,
) {
console.log('Handling updates to returning series:');
console.log(
batch.messages
.map(({body}) => `${body.name} (tmdbId: ${body.tmdbId})`)
.join('\n'),
);

const prisma = await createPrisma(env.DATABASE_URL);

try {
await Promise.all(
batch.messages.map(async ({body: {id, name, tmdbId}}) => {
const {results} = await updateSeries({
id,
name,
tmdbId,
prisma,
accessToken: env.TMDB_ACCESS_TOKEN,
});
await Promise.all(
batch.messages.map(async ({body: {id, name, tmdbId}}) => {
const {results} = await updateSeries({
id,
name,
tmdbId,
prisma,
accessToken: env.TMDB_ACCESS_TOKEN,
});

const result = results.join('\n\n');
console.log(result);
console.log('Update results:');
console.log(results);

const fetchResult = await fetch(
'https://discordapp.com/api/webhooks/656640833063223325/1ofugrkDFpqaSAWvD6mLlg5EN3UDOfBdib4WKNE17Q5YxUoz8wpwuLoKCeaZJqCHyfeC',
{
method: 'POST',
body: JSON.stringify({
content: result,
}),
headers: {'Content-Type': 'application/json'},
},
);
const fetchResult = await fetch(
'https://discordapp.com/api/webhooks/656640833063223325/1ofugrkDFpqaSAWvD6mLlg5EN3UDOfBdib4WKNE17Q5YxUoz8wpwuLoKCeaZJqCHyfeC',
{
method: 'POST',
body: JSON.stringify({
content: results.join('\n\n'),
}),
headers: {'Content-Type': 'application/json'},
},
);

console.log(fetchResult);
}),
);
} catch (error) {
console.log((error as any)?.stack);
throw error;
}
console.log('Discord fetch result:');
console.log(fetchResult);
}),
);
}
39 changes: 20 additions & 19 deletions functions/tmdb-refresher/handlers/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@ import type {ScheduledEvent} from '@cloudflare/workers-types';
import {createPrisma, type Environment} from './shared';

export async function handleScheduled(event: ScheduledEvent, env: Environment) {
console.log('Scheduled event:');
console.log(JSON.stringify(event, null, 2));

try {
const prisma = await createPrisma(env.DATABASE_URL);
const prisma = await createPrisma(env.DATABASE_URL);

const series = await prisma.series.findMany({
where: {status: 'RETURNING'},
});
const series = await prisma.series.findMany({
where: {status: 'RETURNING'},
});

console.log(series);
console.log('Queuing updates to returning series:');
console.log(
series
.map((series) => `${series.name} (tmdbId: ${series.tmdbId})`)
.join('\n'),
);

await Promise.all(
series.map(async (series) => {
await env.TMDB_REFRESHER_QUEUE.send({
id: series.id,
name: series.name,
tmdbId: series.tmdbId,
});
}),
);
} catch (error) {
console.error(error);
throw error;
}
await env.TMDB_REFRESHER_QUEUE.sendBatch(
series.map((series) => ({
body: {
id: series.id,
name: series.name,
tmdbId: series.tmdbId,
},
})),
);
}
2 changes: 1 addition & 1 deletion functions/tmdb-refresher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"deploy": "wrangler deploy --config ./wrangler.toml"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20221111.1",
"@cloudflare/workers-types": "^4.20240405.0",
"buffer-polyfill": "npm:buffer@^6.0.0"
}
}
2 changes: 1 addition & 1 deletion functions/tmdb-refresher/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "watch-tmdb-refresher"
main = "./build/output/tmdb-refresher.js"

account_id = "9bfdb755def60e50760e33036c6f1624"
compatibility_date = "2024-03-29"
compatibility_date = "2024-04-05"

logpush = true
workers_dev = false
Expand Down
36 changes: 18 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b70cf3e

Please sign in to comment.