Actor

petr_cermak/crawler-restart

  • Builds
  • latest 0.0.8 / 2017-10-23
  • Created 2017-08-16
  • Last modified 2017-10-23
  • grade 1

Description

Act for restarting a SUCCEEDED crawler. Can be used from a crawler finish webhook to auto-restart itself. No other configuration is necessary.


API

To run the actor, send a HTTP POST request to:

https://api.apify.com/v2/acts/petr_cermak~crawler-restart/runs?token=<YOUR_API_TOKEN>

The POST payload will be passed as input for the actor. For more information, read the docs.


Example input

Content type: application/json

{ "hello": 123 }

Source code

Based on the apify/actor-node-basic Docker image (see docs).

const sql = require('mysql');
const Apify = require('apify');
const Promise = require('bluebird');

Apify.main(async () => {
    Apify.setPromisesDependency(Promise);
    
    const input = await Apify.getValue('INPUT');
    if(!input._id){
        return console.log('missing "_id" attribute in INPUT');
    }
    if(!input.actId){
        return console.log('missing "actId" attribute in INPUT');
    }

    const details = await Apify.client.crawlers.getExecutionDetails({executionId: input._id});
    const settings = await Apify.client.crawlers.getCrawlerSettings({crawlerId: input.actId, executionId: input._id});
    console.dir(settings);
    
    if(details.status === 'SUCCEEDED'){
        await Apify.client.crawlers.startExecution({
            crawlerId: input.actId, 
            settings: {
                customData: settings.customData
            }
        });
    }
    
});