Schedule posts to Bluesky with Cloudflare workers. skyscheduler.work
cf tool bsky-tool cloudflare bluesky schedule bsky service social-media cloudflare-workers

fix bugs

this should have been translated when the arguments were being updated, but I missed it.

+15 -17
+3 -5
src/endpoints/post.tsx
··· 65 65 // Handling posting right now. 66 66 const postInfo: Post|null = await getPostById(c, response.postId); 67 67 if (!isEmpty(postInfo)) { 68 - const env: Bindings = c.env; 69 - if (shouldPostNowQueue(env)) { 70 - try 71 - { 72 - await enqueuePost(env, postInfo!); 68 + if (shouldPostNowQueue(c.env)) { 69 + try { 70 + await enqueuePost(c, postInfo!); 73 71 } catch(err) { 74 72 console.error(err); 75 73 return c.json({message: 'Failed to post content, will retry again soon'}, 406);
+8 -8
src/utils/queuePublisher.ts
··· 1 1 import isEmpty from 'just-is-empty'; 2 2 import random from 'just-random'; 3 3 import get from 'just-safe-get'; 4 - import { Bindings, Post, QueueTaskData, QueueTaskType, Repost } from "../types.d"; 4 + import { AllContext, Bindings, Post, QueueTaskData, QueueTaskType, Repost } from "../types.d"; 5 5 6 6 const queueContentType = 'v8'; 7 7 ··· 23 23 export const shouldPostNowQueue = (env: Bindings) => env.QUEUE_SETTINGS.postNowEnabled && isQueueEnabled(env); 24 24 export const shouldPostThreadQueue = (env: Bindings) => env.QUEUE_SETTINGS.threadEnabled && (hasPostQueue(env) || isQueueEnabled(env)); 25 25 26 - export async function enqueuePost(env: Bindings, post: Post) { 26 + export async function enqueuePost(c: AllContext, post: Post) { 27 27 if (post.isThreadRoot) { 28 - if (!shouldPostThreadQueue(env)) 28 + if (!shouldPostThreadQueue(c.env)) 29 29 return; 30 - } else if (!isQueueEnabled(env)) 30 + } else if (!isQueueEnabled(c.env)) 31 31 return; 32 32 33 33 // Pick a random consumer to handle this post 34 - const queueConsumer: Queue|null = getRandomQueue(env, "post_queues"); 34 + const queueConsumer: Queue|null = getRandomQueue(c.env, "post_queues"); 35 35 36 36 if (queueConsumer !== null) { 37 37 await queueConsumer.send({type: QueueTaskType.Post, post: post} as QueueTaskData, { contentType: queueContentType }); 38 38 } 39 39 } 40 40 41 - export async function enqueueRepost(env: Bindings, post: Repost) { 42 - if (!isRepostQueueEnabled(env)) 41 + export async function enqueueRepost(c: AllContext, post: Repost) { 42 + if (!isRepostQueueEnabled(c.env)) 43 43 return; 44 44 45 45 // Pick a random consumer to handle this repost 46 - const queueConsumer: Queue|null = getRandomQueue(env, "repost_queues"); 46 + const queueConsumer: Queue|null = getRandomQueue(c.env, "repost_queues"); 47 47 if (queueConsumer !== null) 48 48 await queueConsumer.send({type: QueueTaskType.Repost, repost: post} as QueueTaskData, { contentType: queueContentType }); 49 49 }
+4 -4
src/utils/scheduler.ts
··· 43 43 // TODO: bunching as a part of queues, literally just throw an agent at a queue with instructions and go. 44 44 // this requires queueing to be working properly. 45 45 const AgentList = new Map(); 46 - const usesAgentMap: boolean = (c.env.SITE_SETTINGS.use_agent_map) || false; 46 + const usesAgentMap: boolean = c.env.SITE_SETTINGS.use_agent_map; 47 47 48 48 // Push any posts 49 49 if (!isEmpty(scheduledPosts)) { ··· 58 58 if (usesAgentMap) 59 59 AgentList.set(post.user, agent); 60 60 } 61 - c.ctx.waitUntil(handlePostTask(c, post, agent)); 61 + c.executionCtx.waitUntil(handlePostTask(c, post, agent)); 62 62 } 63 63 } 64 64 } else { ··· 76 76 if (usesAgentMap) 77 77 AgentList.set(repost.userId, agent); 78 78 } 79 - c.ctx.waitUntil(handleRepostTask(c, repost, agent)); 79 + c.executionCtx.waitUntil(handleRepostTask(c, repost, agent)); 80 80 } else { 81 81 await enqueueRepost(c, repost); 82 82 } 83 83 }; 84 - c.ctx.waitUntil(deleteAllRepostsBeforeCurrentTime(c)); 84 + c.executionCtx.waitUntil(deleteAllRepostsBeforeCurrentTime(c)); 85 85 } else { 86 86 console.log("no reposts scheduled for this time"); 87 87 }