···1212 DeleteResponse,
1313 EmbedDataType, LooseObj, Post
1414} from "../types.d";
1515-import { makePost } from "../utils/bskyApi";
1615import {
1716 createPost, createRepost,
1817 deletePost, getPostById,
1918 getPostByIdWithReposts,
2019 updatePostForUser
2120} from "../utils/dbQuery";
2222-import { enqueuePost, shouldPostNowQueue } from "../utils/queuePublisher";
2321import { deleteFromR2, uploadFileR2 } from "../utils/r2Query";
2222+import { handlePostNowTask } from "../utils/scheduler";
2423import { FileDeleteSchema } from "../validation/mediaSchema";
2524import { EditSchema } from "../validation/postSchema";
2625···6564 // Handling posting right now.
6665 const postInfo: Post|null = await getPostById(c, response.postId);
6766 if (!isEmpty(postInfo)) {
6868- if (shouldPostNowQueue(c.env)) {
6969- try {
7070- await enqueuePost(c, postInfo!);
7171- } catch(err) {
7272- console.error(err);
7373- return c.json({message: 'Failed to post content, will retry again soon'}, 406);
7474- }
7575- } else {
7676- if (!await makePost(c, postInfo))
7777- return c.json({message: `Failed to post content, will try again soon.\n\n
7878- If it doesn't post, send a message with this code:\n${postInfo!.postid}`}, 406);
7979- }
6767+ if (await handlePostNowTask(c, postInfo!) === false)
6868+ return c.json({message: "Unable to post now, will try again during next nearest hour"}, 406);
8069 return c.json({message: "Created Post!", id: response.postId});
8170 } else {
8271 return c.json({message: "Unable to get post content, post may have been lost"}, 401);
+9-6
src/index.tsx
···1616import ResetPassword from "./pages/reset";
1717import Signup from "./pages/signup";
1818import TermsOfService from "./pages/tos";
1919-import { Bindings, QueueTaskData, QueueTaskType, ScheduledContext } from "./types.d";
1919+import { Bindings, QueueTaskData, ScheduledContext, TaskType } from "./types.d";
2020+import { AgentMap } from "./utils/bskyAgents";
2021import { makeConstScript } from "./utils/constScriptGen";
2122import { getAllAbandonedMedia } from "./utils/db/file";
2223import { runMaintenanceUpdates } from "./utils/db/maintain";
···159160 async queue(batch: MessageBatch<QueueTaskData>, env: Bindings, ctx: ExecutionContext) {
160161 const runtimeWrapper = new ScheduledContext(env, ctx);
161162 const delay: number = env.QUEUE_SETTINGS.delay_val;
163163+ const agency = new AgentMap(env.TASK_SETTINGS);
162164 let wasSuccess: boolean = false;
163165 for (const message of batch.messages) {
166166+ const agent = await agency.getOrAddAgentFromObj(runtimeWrapper, message.body.post || message.body.repost, message.body.type);
164167 switch (message.body.type) {
165165- case QueueTaskType.Post:
166166- wasSuccess = await handlePostTask(runtimeWrapper, message.body.post!, null);
168168+ case TaskType.Post:
169169+ wasSuccess = await handlePostTask(runtimeWrapper, message.body.post!, agent);
167170 break;
168168- case QueueTaskType.Repost:
169169- wasSuccess = await handleRepostTask(runtimeWrapper, message.body.repost!, null);
171171+ case TaskType.Repost:
172172+ wasSuccess = await handleRepostTask(runtimeWrapper, message.body.repost!, agent);
170173 break;
171174 default:
172172- case QueueTaskType.None:
175175+ case TaskType.None:
173176 console.error("Got a message queue task type that was invalid");
174177 message.ack();
175178 return;
···104104# if we should be removing abandoned files from R2 storage
105105R2_SETTINGS={auto_prune=true, prune_days=3}
106106107107-# various site settings
108108-SITE_SETTINGS={use_agent_map=false}
107107+# settings about tasks
108108+TASK_SETTINGS={use_posts=true, use_reposts=true}
109109110110# set this to true in your .dev.vars to turn off turnstile
111111IN_DEV=false
···120120QUEUE_SETTINGS = {enabled=false, repostsEnabled=false, postNowEnabled=false, threadEnabled=true, delay_val=100, post_queues=["POST_QUEUE"], repost_queues=[]}
121121REDIRECTS = {contact="https://bsky.app/profile/skyscheduler.work", tip="https://ko-fi.com/socksthewolf/tip"}
122122R2_SETTINGS={auto_prune=false, prune_days=3}
123123-SITE_SETTINGS={use_agent_map=false}
123123+TASK_SETTINGS={use_posts=true, use_reposts=true}
124124IN_DEV=true
125125126126[[env.staging.d1_databases]]