W
Wasp3mo ago
ayo

tigger a scheuled job

I'm unable to tigger a scheduled job. Submitting the job works fine. I've set cron down to one minute for testing
schedule: {
cron: "* * * * *",
executorOptions: {
pgBoss: {=json { "retryLimit": 2 } json=}
}
},
schedule: {
cron: "* * * * *",
executorOptions: {
pgBoss: {=json { "retryLimit": 2 } json=}
}
},
9 Replies
kapa.ai
kapa.ai3mo ago
Hi @ayo. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- If submitting the job manually works but your scheduled job (with cron set to every minute) is not triggering, here are some things to check based on the Wasp documentation: 1. Job Declaration
Your schedule block looks correct for running every minute:
schedule: {
cron: "* * * * *",
executorOptions: {
pgBoss: {=json { "retryLimit": 2 } json=}
}
}

schedule: {
cron: "* * * * *",
executorOptions: {
pgBoss: {=json { "retryLimit": 2 } json=}
}
}

Make sure the rest of your job declaration is also correct, including the executor and perform fields, and that the function you import is valid and async. Example:
job mySpecialJob {
executor: PgBoss,
perform: {
fn: import { foo } from "@src/workers/bar"
},
schedule: {
cron: "* * * * *",
executorOptions: {
pgBoss: {=json { "retryLimit": 2 } json=}
}
}
}

job mySpecialJob {
executor: PgBoss,
perform: {
fn: import { foo } from "@src/workers/bar"
},
schedule: {
cron: "* * * * *",
executorOptions: {
pgBoss: {=json { "retryLimit": 2 } json=}
}
}
}

See docs example 2. PgBoss Runs Alongside Server
Wasp starts pg-boss alongside your web server. If your server is running, pg-boss should be running too. If the server is not running, scheduled jobs will not trigger. Also, jobs share CPU with your server, so avoid CPU-heavy tasks in jobs.
See pg-boss considerations 3. Database Connection
Pg-boss requires a working connection to your PostgreSQL database. If pg-boss cannot connect, scheduled jobs will not run. Check your logs for any database connection errors.
See Discord troubleshooting 4. Changing Job Names or Schedules
If you recently changed the job name or removed a schedule, old scheduled jobs may become stale and not trigger. You may need to manually remove the relevant row from the schedule table in the pgboss schema of your database.
See docs for details 5. Heroku Deployment
If you are deploying to Heroku, you must set the PG_BOSS_NEW_OPTIONS environment variable to ensure SSL is used for the database connection.
See Heroku deployment notes 6. Logs and Debugging
Check your server logs for any errors related to pg-boss or job scheduling. If possible, enable more verbose logging to see if the cron schedule is being registered and if jobs are being enqueued. If all of the above are correct and it still doesn't work, there may be a platform-specific issue (e.g., Mac M1/M2 chips have been reported to cause issues in some cases). In such cases, sharing logs from your server and database startup can help diagnose the problem further. If you need to manually trigger a scheduled job for testing, you can always use .submit() to invoke it immediately, but for the cron schedule to work, the above conditions must be met. If you have checked all of these and the issue persists, please provide any relevant logs or error messages for further troubleshooting. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @ayo, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
ayo
ayoOP3mo ago
Here is the rest of the declaration
job someJob {
executor: PgBoss,
perform: {
fn: import { someJob } from "@src/payment/workers/someJobs",
executorOptions: {
pgBoss: {=json { "retryLimit": 2 } json=}
}
},
schedule: {
cron: "* * * * *",
executorOptions: {
pgBoss: {=json { "retryLimit": 2 } json=}
}
},
entities: [User, Purchase, Art, Address],
}
job someJob {
executor: PgBoss,
perform: {
fn: import { someJob } from "@src/payment/workers/someJobs",
executorOptions: {
pgBoss: {=json { "retryLimit": 2 } json=}
}
},
schedule: {
cron: "* * * * *",
executorOptions: {
pgBoss: {=json { "retryLimit": 2 } json=}
}
},
entities: [User, Purchase, Art, Address],
}
@kapa.ai
kapa.ai
kapa.ai3mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Your job declaration looks correct according to the Wasp documentation for scheduled jobs with pg-boss. The cron expression "* * * * " should trigger the job every minute, and your use of executorOptions is valid. Here’s a reference example from the docs: ```wasp job mySpecialJob {
executor: PgBoss,
perform: {
fn: import { foo } from "@src/workers/bar",
executorOptions: {
pgBoss: {=json { "retryLimit": 1 } json=}
}
},
schedule: {
cron: "
/5 * * * *",
args: {=json { "foo": "bar" } json=},
executorOptions: {
pgBoss: {=json { "retryLimit": 0 } json=}
}
},
entities: [Task],
} `` [See docs example](<https://wasp-lang.dev/docs/advanced/jobs#declaring-jobs>) **Troubleshooting Steps:** - Make sure your server is running, as pg-boss runs alongside it and is responsible for triggering scheduled jobs. - If you have recently changed the job name or removed a schedule, you may need to manually clean up the schedule table in the pgboss schema of your database, as stale schedules can prevent jobs from triggering properly. See the docs for details on this cleanup process [here](<https://wasp-lang.dev/docs/advanced/jobs#pg-boss-considerations>). - Check your logs for any errors related to pg-boss or database connectivity. Issues with the database connection (especially on Mac M1/M2 or after restarts) have been reported to cause scheduled jobs not to trigger, even if manual submission works. If you see errors like pg-boss failed to start! Error: connect ECONNREFUSED ::1:5432, this points to a database connection issue, not a problem with your job declaration itself [Discord troubleshooting](<https://discord.com/channels/686873244791210014/1179895919471247490>). - If you are deploying to Heroku, ensure you have set the PG_BOSS_NEW_OPTIONS` environment variable as described in the docs, or scheduled jobs may not work due to SSL requirements Heroku deployment notes. If all of the above are correct and you still cannot trigger scheduled jobs, please provide any relevant logs or error messages for further troubleshooting. The knowledge sources do not mention any additional required configuration for your use case. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @ayo, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
toticozeni
toticozeni3mo ago
Hey @ayo. So submitting a job works (the execution of the function is fine then) but the scheduling part doesn't? I assume you are using a Postgres database instead of SQLite. This sounds like there are some database issues, maybe schema issues, which stop it from working. @miho any idea?
miho
miho3mo ago
Maybe if you could share your job code? Are there any errors in the server logs? 😄 Maybe try running wasp clean and restarting the app? Sometimes there are issues with some JS files not being compiled correctly e.g. if you named it one thing and then renamed it, stuff like that.
ayo
ayoOP3mo ago
@miho here's what the job looks like
job payoutArtistJob {
executor: PgBoss,
perform: {
fn: import { payoutArtistJob } from "@src/payment/workers/payout",
executorOptions: {
pgBoss: {=json { "retryLimit": 2 } json=}
}
},
schedule: {
cron: "* * * * *",
executorOptions: {
pgBoss: {=json { "retryLimit": 2 } json=}
}
},
entities: [User, Purchase, Art, Address],
}
job payoutArtistJob {
executor: PgBoss,
perform: {
fn: import { payoutArtistJob } from "@src/payment/workers/payout",
executorOptions: {
pgBoss: {=json { "retryLimit": 2 } json=}
}
},
schedule: {
cron: "* * * * *",
executorOptions: {
pgBoss: {=json { "retryLimit": 2 } json=}
}
},
entities: [User, Purchase, Art, Address],
}
export const payoutArtistJob: PayoutArtistJob<
{},
{ success: boolean }
> = async ({}, context) => {
console.log('Payout artist job started for purchaseId:');
const fifteenDaysAgo = new Date(Date.now() - 15 * 24 * 60 * 60 * 1000);
export const payoutArtistJob: PayoutArtistJob<
{},
{ success: boolean }
> = async ({}, context) => {
console.log('Payout artist job started for purchaseId:');
const fifteenDaysAgo = new Date(Date.now() - 15 * 24 * 60 * 60 * 1000);
At this point I should be getting console.log('Payout artist job started for purchaseId:');
miho
miho3mo ago
It's scheduled to run every minute, so you are no seeing the logs after you wait some time? Can you try doing the same with a simple new app wasp new test and just a console log job there?
ayo
ayoOP3mo ago
@miho sorry for responding late. I'e just tried that, an every minute job to console log but nothing is printing still
miho
miho3mo ago
Do you see any errors in the server or the Postgres container when you try running the app?

Did you find this page helpful?