This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

remove cron

+21 -19
+21 -19
src/index.ts
··· 1 1 import { BskyAgent } from "@atproto/api"; 2 2 import * as dotenv from "dotenv"; // Import dotenv for loading environment variables 3 - import { CronJob } from "cron"; // Import CronJob for scheduling tasks 4 3 import * as process from "process"; // Import process for accessing environment variables 5 4 import { generateWolfNoiseString } from "./wolf-noise-generator"; 6 5 ··· 23 22 ); 24 23 return; 25 24 } 25 + 26 + console.log("Environment variables loaded successfully."); 26 27 27 28 try { 28 29 // Login to Bluesky ··· 47 48 }); 48 49 console.log("Just posted:", randomNoise.trim()); // Log the posted string 49 50 } else { 50 - console.log("Failed to generate a valid wolf noise string after multiple attempts."); 51 + console.log( 52 + "Failed to generate a valid wolf noise string after multiple attempts." 53 + ); 51 54 } 52 55 } catch (error) { 53 56 console.error("Error during posting:", error); ··· 72 75 return randomDelay; 73 76 } 74 77 75 - // Schedule a cron job to run the main function periodically 76 - const scheduleExpression = "0 * * * *"; // Every hour (used as a base for randomisation) 78 + // Function to run the main function in a loop with random delays 79 + async function runLoop() { 80 + while (true) { 81 + await main(); 77 82 78 - const job = new CronJob(scheduleExpression, async () => { 79 - console.log("Cron job triggered."); 80 - // Calculate a random delay before running the main function 81 - const delay = getRandomDelay(); 82 - console.log(`Next post scheduled in approximately ${(delay / 3600).toFixed(2)} hours.`); 83 - 84 - // Wait for the random delay 85 - await new Promise((resolve) => setTimeout(resolve, delay * 1000)); 86 - 87 - // Run the main function 88 - await main(); // Ensure to await the main function 89 - }); 83 + // Calculate a random delay before the next iteration 84 + const delay = getRandomDelay(); 85 + console.log( 86 + `Next post scheduled in approximately ${(delay / 3600).toFixed(2)} hours.` 87 + ); 90 88 91 - // Start the cron job 92 - console.log("Starting the cron job."); 93 - job.start(); 89 + // Wait for the random delay 90 + await new Promise((resolve) => setTimeout(resolve, delay * 1000)); 91 + } 92 + } 93 + 94 + // Start the loop 95 + runLoop().catch((error) => console.error("Error in run loop:", error));