Norconex / collector-core

Collector-related code shared between different collector implementations
http://www.norconex.com/collectors/collector-core/
Apache License 2.0
7 stars 15 forks source link

[JEF Events] suiteSopped is never called #7

Closed sylvainroussy closed 7 years ago

sylvainroussy commented 7 years ago

Hi!

I have registered my own ISuiteLifeCycleListener to catch the moment where the entire execution of my collector is finished.

I can catch suiteStopping but no event after (triggered by a stop on the collector).

Do you have an idea of why ?

Best regards, Sylvain

essiembre commented 7 years ago

Exactly how do you do you stop it? From the command line? Because the suiteStopped should definitely be invoked (I can't reproduce your issue). If you are not stopping it yourself and just want to know when it ends, you can rely on suiteCompleted instead in the suite listener.

There could also be ways to get notified when the collector ends that are more collector-specific. If you have only a single crawler define in your collector, you could use a ICrawlerEventListener and listen for the CRAWLER_FINISHED event. If you have more than one crawler, you could simply count how many got terminated to make sure they are all terminated before you do what you need to do.

sylvainroussy commented 7 years ago

After many tests, I confirm that suiteStopped() is never called on collector.stop() (version 1.6.0 of collector-core) and CRAWLER_FINISHED too. The call is triggered by java on collector.stop () method.

CRAWLER_FINISHED and suiteCompleted() are correctly triggered when the crawler is over after doing all its job. I have one crawler by collector. I'm going to see more precisely what is the cause of that. Maybe it's my own code, but I don't understand why I can catch suiteStopping and not suiteStopped.

sylvainroussy commented 7 years ago

I think this is possible to skip suiteStopped if the job take more three seconds to stop, I saw it in StopRequestMonitor.stopJob () :

private void stopJob(final IJob job, final IJobStatus status) {
        ((MutableJobStatus) status).setStopRequested(true);
        job.stop(status, suite);
        while (status.getState() == JobState.RUNNING) {
            Sleeper.sleepSeconds(STOP_WAIT_DELAY);
        }
        if (status.getState() == JobState.STOPPED) {
            for (IJobLifeCycleListener l : 
                    suite.getJobLifeCycleListeners()) {
                l.jobStopped(status);
            }
            if (job.getId().equals(suite.getRootJob().getId())) {
                for (ISuiteLifeCycleListener l : 
                        suite.getSuiteLifeCycleListeners()) {
                    l.suiteStopped(suite);
                }
            }
        }
    }

My job state is not stopped after three seconds and no event is sent to the suiteLifeCycleListener.

sylvainroussy commented 7 years ago

Ok, using IJobLifeCycleListener instead of ISuiteLifeCycleListener works exactly as I want.

Closing.

essiembre commented 7 years ago

After more testing on my end, I could finally reproduce and provided a fix in the JEF API (snapshot available). suiteStopped is now invoked as it should. I updated the Collector Core project to use the updated JEF API. A new snapshot release was made.

I know you changed to another approach, but would you mind confirming this fix works for you? I'll re-open the ticket pending your confirmation.

For future issues specific to the JEF API, please use the JEF API Github project: https://github.com/norconex/jef/issues

sylvainroussy commented 7 years ago

Fixed! Thanks.