Accessing context from the node-cron function
See original GitHub issueHello!
I have difficulties with accessing telegram context from the node-cron function. What I want to achieve:
var cron = require('node-cron');
cron.schedule('* * * * *', () => {
ctx.session.variable = 'something';
ctx.telegram.sendMessage(chatID, message);
<..>
});
You got a general idea. Is it possible or I should look in another direction? The main goal is to periodically execute something. Right now it looks like this:
bot.on('text', (ctx) => {
if ((ctx.message.date - ctx.session.variableWithTimestamp) > 3600) {
ctx.session.variableWithTimestamp += 3600;
//do something
}
})
and I understand that there should be much better way to perform it
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Passing context info in onTick function · Issue #47 - GitHub
We need to pass context info in onTick function the way this is implemented in setInterval, any support for this.
Read more >Task scheduling with node-cron - ITNEXT
The node-cron module is a tiny task scheduler in pure JavaScript for Node.js based on GNU crontab. We are going to build a...
Read more >How to manage Cron Jobs in Node.js - Stack Overflow
You can use cron module to do this. Install cron using npm i cron . As an example, var CronJob = require('cron').CronJob; new...
Read more >How To Use node-cron to Run Scheduled Jobs in Node.js
Use Node.js and the node-cron library to schedule jobs to manage logs, back up databases, and send emails.
Read more >cron - npm
node -cron ... Cron is a tool that allows you to execute something on a schedule. This is typically done using the cron...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Raingerlina context is a short-lived and valid only during update processing.
For sending messages from any kind of a queues/schedulers use
Telegram
instance. And you can access to session directly, without context.As far as I understand you still need to clarify the session key manually in order to access it outside the context. Because otherwise how would the redis itself know where to retrieve and put the information