I created a very simple task and don’t know what is the best way to debugg.
Someone know if lack nay code to run the task?
Code:
config/cron-carta.js
module.exports = ({ env }) => ({ jobSendCarta: { task: async ({ strapi }) => { console.log("Started!!!"); strapi.log.info("Teste"); }, options: { rule: "*/10 * * * * *", }, }, });
config/server.js
`
const jobSendCarta = require(“./cron-carta”);
module.exports = ({ env }) => ({
host: env(“HOST”, “0.0.0.0”),
port: env.int(“PORT”, 1337),
cron: {
enabled: env.bool(“CRON_ENABLED”, true),
tasks: jobSendCarta,
},
app: {
keys: env.array(“APP_KEYS”),
},
});
`
This topic has been created from a Discord post (1222902055803424879) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord
I found the bug, If I remove the ({ env }) it works.
Fixed removing ({ env })
and replaced to process.env.X
<@&812004048591913010> Is this a bug using env as a variable on params?
Read <#811989167357689917> and tell me what you did wrong
Sorry, I was wondering if I need to create an issue on GitHub.
Please tell me what you did wrong and I’ll consider this a warning.
Then I’ll answer your question
Is it wrong to put ({ env })
in module.exports
? Maybe I’m importing twice because the server.js uses ({ env }) too?
No I’m saying you shouldn’t ping mods lol
I read the rule, I shouldn’t have used it, sorry.
Your problem is probably the cron timer itself, your trying to run those cron in the milliseconds
That first * is the second and your dividing that by 10
The error doesn’t with cron timer, I just removed the ({ env }) and it works.
Ahhh interesting, probably because it’s not one of our normal config files <:ThinkEyes:642567846597230614>
If you do need the env helper you can use the const { env } = require('@strapi/utils')
The options
should be cron string
And remove the attribute rule