I need to run a puppeteer script from a cron job. The problem is that puppeteer is javascript, and the cron job doesn't execute the javascript. What would be the best way to execute my puppeteer script from my cron job?
Or a workaround?
Here is part of my code in my cron job:
<?php
//connect to database and retrieve information
echo '<script type="text/javascript">',
'myPuppeteerFunction();', //this leads to my puppeteer script, which is saved in javascriptFunctions.js
'</script>';
?>
Related
I have a job with Nodejs that I want to do it each 30 minutes to scan the Database and Update Products Data in An Ecommerce API with my Nodejs Program, note that the Nodejs Program is serving an REST API (Backend) for a react js web application
So I searched for that and I found that I can do that with Nodejs Cron Library like "node-schedule" but I know that will be more interesting to do it with Linux Cron
var j = schedule.scheduleJob('42 * * * *', function(){
console.log('The answer to life, the universe, and everything!');
});
Is there any library that can let me add Cron jobs to Linux using Nodejs Or would I do it with "fs" only? so I will open the cron job file and add my command?
The command crontab which is part of Vixie Cron allows you to create, edit and delete per-user cron entries.
Or if you are running as the root user, which you should not be doing, you can drop cron files into /etc/cron.d
This is not always supported, and if you're running in a Docker type container environment it is doubtful that you have any cron at all. In that environment you'd want your running Nodejs to handle scheduled jobs for you. Or use some other kind of distributed scheduled work system.
You can put your cron job to a nodejs script. Then adding to the crontab can be done with cronbee module, via API:
import { cronbee } from 'cronbee'
await cronbee.ensure({
taskName: 'do smth',
taskRun: `node my-script`,
cron: '42 * * * *'
})
or you can ensure the cron job via CLI, if the module is installed globally or from npm scripts:
$ cronbee ensure mytasks.json
On a giltab ci job I am running a node.js script where I evaluate some conditions, and where I might want to force the job to fail.
The script is written in es6 and is ran with yarn and babel-node yarn babel-node ./script-in-es6.js.
When the condition fails I would like the job to fail. I have tried the following:
throw new Error('job failed')
process.exit(1)
require('shelljs').exit(1)
But none of these commands are enough to fail the job, it always succeeds. Is there a proper way to successfully fail a job in gitlab from node.js?
If your script really does return exit code 1, try this:
script:
- <run your script> || export RES="$?"
- exit $RES
I am trying to schedule spark job using crontab, yes oozie is there made for this purpose but for certain challenge not able to use it.
I have put the script as sh file and executing that in the cron.
Cron:
/bin/sh /home/user/job.sh
job.sh
source /etc/hadoop/conf/hadoop.sh
source /hadoop/spark/conf/spark.sh
./sparksubmit .py file
Getting below Error:
An error occurred while calling None.org.apache.spark.api.java.JavaSparkContext.
I currently have an api test script using supertest + mocha + grunt.
I would like to run this script every 1 minute. How is it possible
You can use linux cron job or node module schedular
https://github.com/node-schedule/node-schedule
TO run your script once in a minute.
I need to run my nodejs script for every second ,Similar to PHP cron jobs. I have tried some nodejs cron libraries like https://github.com/ncb000gt/node-cron but the issue was first run should be manual i:e I have to run the file with cron script for first time manually.
But in php cron jobs, they run by the server so if the apache server running script will automatically start and even if the script return an error for a cycle then script will run again from the beginning from the next cycle
So is there any way to achieve this in nodejs ?
You have two options:
using Node as a daemon, with something like Supervisord to run your node-cron script. This alternative is wasteful on resources such as RAM because Node and Supervisord are running all the time.
using the system's crontab, you can run your script like calling Node on the command line, such as * * * * node /path/to/your/script.js. This alternative is highly efficient but lacks some control, like being able to log the output in case of an error, although you could just pipe the output to a file: node script.js > logfile