Terminate running task

242 views
Skip to first unread message

Mariska

unread,
Jun 3, 2021, 10:59:21 AM6/3/21
to Nexus Users
Is there a way to terminate a running task directly without restarting NXRM3 ? I've  a long running task and already tried to stop it via the "Stop" button, but the execution is not interrupted. 

Thanks,
Mariska.

Michael Prescott

unread,
Jun 3, 2021, 11:04:23 AM6/3/21
to Mariska, Nexus Users
That should do it. Which task is it? Can you see log entries still accumulating for the task-specific log file?


--
You received this message because you are subscribed to the Google Groups "Nexus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nexus-users...@glists.sonatype.com.
To view this discussion on the web visit https://groups.google.com/a/glists.sonatype.com/d/msgid/nexus-users/1ad47361-dadd-4713-8b66-bac90e7a1317n%40glists.sonatype.com.


--
Sonatype
Michael Prescott
Director, Product Management


Mariska

unread,
Jun 3, 2021, 11:28:35 AM6/3/21
to Nexus Users, mpre...@sonatype.com, Nexus Users, Mariska
Hi,
It's a custom groovy task and I can still see it running and logging to the specific logfile.
The task searches through a specific hosted maven repository for assets, and checks the number of versions of the assets component and last downloaded time, but as there are so many assets, it's running for hours and it won't stop. I've to optimise it, but it would be nice if it listens to the stop button. It starts a database transaction.
Thanks,
Mariska

Matthew Piggott

unread,
Jun 3, 2021, 12:12:38 PM6/3/21
to Nexus Users, Mariska, Michael Prescott, Nexus Users
Task cancellation is a request, normally the task's code periodically checks to see whether it has been cancelled. That said, I don't think the cancellation status was exposed to scripts directly,  possibly you could include code in your task to query the TaskManager / TaskScheduler.

Mariska

unread,
Jun 4, 2021, 2:25:29 AM6/4/21
to Nexus Users, Matthew Piggott, Mariska, mpre...@sonatype.com, Nexus Users
Including code to query the TaskManager might be a good idea. I will look into it. Thanks for the suggestion.

Mariska

unread,
Jun 4, 2021, 8:09:07 AM6/4/21
to Nexus Users, Matthew Piggott, Mariska, mpre...@sonatype.com, Nexus Users
One more question (hope you won't mind). I've been trying to find the state of the current task (probably not the best way to do this):
```
import org.sonatype.nexus.scheduling.TaskState
import org.sonatype.nexus.scheduling.Task
import org.sonatype.nexus.scheduling.TaskInfo
import org.sonatype.nexus.scheduling.CurrentState
TaskScheduler taskScheduler = container.lookup(TaskScheduler.class.getName())

TaskInfo existingTask = taskScheduler.listsTasks().find { TaskInfo taskInfo ->
    taskInfo.name == "0-test"
}
sleep(10000)
if (existingTask) {
log.debug("currentState: ${existingTask.getCurrentState()}")
}
```
When I run this task (which I named "0-test"), I would expect it to log "RUNNING_CANCELED", if I click the "Stop" button to stop the task within 10 seconds of starting the task, but it always gives me:
021-06-04 13:58:24,704+0200 DEBUG [quartz-10-thread-9]  *SYSTEM org.sonatype.nexus.internal.script.ScriptTask - currentState: CurrentStateImpl{state=RUNNING, nextRun=null, future=org.sonatype.nexus.quartz.internal.task.QuartzT
askFuture@28ebb670}

Question: how would I get the RUNNING_CANCELED state or have the custom script listen to the Stop button? When I click on the Stop button, I do get a message that the task is stopped.

Thanks,
Mariska.

On Thursday, June 3, 2021 at 6:12:38 PM UTC+2 Matthew Piggott wrote:
Reply all
Reply to author
Forward
0 new messages