简体   繁体   中英

Running phantomjs script every x minute

I just started to use phantom js ... I want to do some tasks on specific time interval, like capturing screens of my website every 5 min .

I understand lots of phantom js scripts require some sort of task scheduling tool .. like cronjob ... so I thought I'll get tons of options by searching google but I got nothing useful.

I've seen some run it by using simple setInterval on a nodejs server (phantomjs-node lib) but according to this answer

https://stackoverflow.com/a/15746154/590589 its not very reliable

So it's either very obvious and easy solution so no one is writing about it! or there are not many options.

Either way I'll be thankful for any suggestion

Just add to cron a task like this

*/5 * * * * /usr/bin/phantomjs /path/to/script.js

Of course, your location of PhantomJS may be different. Check with

which phantomjs

For task scheduling, have a look at Agenda . You can do something like this

    agenda.define('capture screen', function(job, done) {
      // Do something
    });

    agenda.processEvery('5 minutes');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM