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?