def nutch_crawl(crawl_model, rest_crawl, url_trails):

    while crawl_model.rounds_left:
        if rest_crawl.currentJob is None:
            rest_crawl.currentJob = rest_crawl.jobClient.create('GENERATE')

        active_job = rest_crawl.progress(nextRound=False)
        while active_job:
            crawl_model = Crawl.objects.get(id=crawl_model.id)
            sys.stderr.write("Crawler Status: {}".format(crawl_model.status))
            if crawl_model.status == 'STOPPING':
                crawl_model.status = 'STOPPED'
                crawl_model.save()
                return
            time.sleep(STREAM_UPDATE_PERIOD)
            old_job = active_job
            active_job = rest_crawl.progress(nextRound=False)
            if url_trails:
                url_trails.handle_messages()
            if active_job and active_job != old_job:
                crawl_model.status = active_job.info()['type']
                crawl_model.save()
        crawl_model.rounds_left -= 1
        try:
            stats = rest_crawl.jobClient.stats()
        except nutch_rest_api.NutchException as err:
            sys.stderr.write(str(err))
        else:
            for ignore, data in stats['status'].items():
                if data['statusValue'] == 'db_fetched':
                    crawl_model.pages_crawled = data['count']
                    break
            else:
                sys.stderr.write("Warning: Nutch has responded but has not crawled anything yet")
        crawl_model.save()
    crawl_model.status = 'SUCCESS'
    crawl_model.save()
Run a Nutch crawl until self.rounds_left is 0 or self.crawl.status is externally set to "STOPPING"
dataset/ETHPy150Open memex-explorer/memex-explorer/source/task_manager/crawl_tasks.py/nutch_crawl