-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added role vars + groovy script to manage scheduled tasks
- Loading branch information
Showing
6 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
- include: call_script.yml | ||
vars: | ||
script_name: create_task | ||
args: "{{ item }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import groovy.json.JsonSlurper | ||
import org.sonatype.nexus.scheduling.TaskConfiguration | ||
import org.sonatype.nexus.scheduling.TaskInfo | ||
import org.sonatype.nexus.scheduling.TaskScheduler | ||
import org.sonatype.nexus.scheduling.schedule.Schedule | ||
|
||
parsed_args = new JsonSlurper().parseText(args) | ||
|
||
TaskScheduler taskScheduler = container.lookup(TaskScheduler.class.getName()) | ||
|
||
TaskInfo existingTask = taskScheduler.listsTasks().find { TaskInfo taskInfo -> | ||
taskInfo.name == parsed_args.name | ||
} | ||
|
||
if (existingTask && !existingTask.remove()) { | ||
throw new RuntimeException("Could not remove currently running task : " + parsed_args.name) | ||
} | ||
|
||
TaskConfiguration taskConfiguration = taskScheduler.createTaskConfigurationInstance(parsed_args.typeId) | ||
taskConfiguration.setName(parsed_args.name) | ||
|
||
parsed_args.taskProperties.each { key, value -> taskConfiguration.setString(key, value) } | ||
|
||
Schedule schedule = taskScheduler.scheduleFactory.cron(new Date(), parsed_args.cron) | ||
|
||
taskScheduler.scheduleTask(taskConfiguration, schedule) |