-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (53 loc) · 1.73 KB
/
index.js
File metadata and controls
63 lines (53 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const { updateAndScrapeReplies, updateLatestReplies , scrapeNewReplies} = require('./src/scraping_replies.js');
const { scrapeTopics: importTopics } = require('./src/scraping_topics.js')
const cron = require('node-cron');
// npm start
// npm run deploy:
async function start() {
try {
console.log(`start ${new Date()}`)
await importTopics();
await updateAndScrapeReplies();
console.log(`___end`)
} catch (error) {
console.error('Error in start function:', error);
// Wait for 30 seconds before retrying
await new Promise(resolve => setTimeout(resolve, 30000));
start(); // Retry the operation
}
}
async function getUpToDate(){
try {
console.log(`getUpToDate ${new Date()}`)
await importTopics();
await scrapeNewReplies(50, 2)
console.log(`___end`)
} catch (error) {
console.error('Error in getUpToDate function:', error);
// Wait for 30 seconds before retrying
await new Promise(resolve => setTimeout(resolve, 30000));
getUpToDate(); // Retry the operation
}
}
exports.scrapeReplies = async () => {
updateAndScrapeReplies();
}
exports.scrapeTopics = async () => {
importTopics()
}
exports.example = async (message, context) => {
const data = Buffer.from(message.data, 'base64').toString();
console.log(`Received message: ${data}`);
}
function startCron() {
console.log('Initializing cron schedule...');
getUpToDate();
// Schedule the job to run every 5 minutes
cron.schedule('*/5 * * * *', () => {
console.log('Cron job triggered at:', new Date());
start();
});
console.log('Cron schedule initialized');
}
// Initialize the cron schedule
startCron();