0

I have written a cleanup script for a nexus repository, that verifies if a component is used by calling a rest interface of a third party system. Long story short: This script has a significant runtime due to the amount of components and network traffic. So it needs to be cancelable, and with this requirement my problems are rising.

this script was written in groovy and executed manually using the task interface of nexus. Created a new Task using the "Execute script" skeleton. When trying to stop the task it only states in the log:

admin org.sonatype.nexus.quartz.internal.task.QuartzTaskJob - Task not cancelable: 'TEST' [script]

Unfortunately the example scripts of nexus are all short n handy and no one is using the cancel feature itself.

So in looked up the source of the suggested QuartzTaskJob and i saw that this is a Wrapper of a Nexus Task and it should be automaticaly used by the QuartzSchedulerSPI.

Therefore i've implemented a dummy version of it to test it with the implemented Tasks (e.g. RestoreMetadataTask) as examples. First by having sleep() in it and the second try was the for loop you see in the code quote below. Both tries had the same sad end.

import org.sonatype.nexus.scheduling.Cancelable;
import org.sonatype.nexus.scheduling.TaskSupport;

public class CancelableTask
extends TaskSupport
implements Cancelable

{
    @Override
    public String getMessage(){
        return null
    }

    @Override
    protected Void execute() throws  Exception{
        log.info("Start TimeTestCancel")
        for(int i = 0; i < 1000000000000; i++){
            for(int j = 0; j < 1000000000000; j++) {
                if (isCanceled()) {
                    log.info(i)
                    break;
                }
            }
        }
        log.info("Finished TimeTestCancel")
    }
}

Sleep and the loops: When testing on Nexus 3.7.1-02 it just changed the status to "Blocked", showing the "Stop" button but stating "Task not cancelable" again when pressing it. Not able to delete them or change them. Just the loops: When testing on Nexus 3.21.1-01 it just executes so fast i cannot try to cancel it.

So i basically ask myself what am i missing? Is there a way to have cancelable Jobs as groovy script at all? Or do i have to implement a nexus plugin to archive my goal?

Thomas
  • 689
  • 3
  • 8
  • 14

1 Answers1

0

Not all tasks are cancellable. You could file an issue in issues.sonatype.com to ask for this, however, the scripting interface has a security issue and is no longer enabled in newer versions of NXRM3. I suspect ultimately it will be replaced by the REST API.

joedragons
  • 2,505
  • 21
  • 21
  • have not found any hint that the scripting task should be shut down in any of the docker images currently released. where do you have your info from? – Thomas May 11 '20 at 12:57
  • @Thomas see https://help.sonatype.com/display/NXRM3/2020+Release+Notes#id-2020ReleaseNotes-RepositoryManager3.21.2 – joedragons May 11 '20 at 14:39