Order of execution of the clone cleanup scripts?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2016 09:25 AM
Anyone know what order the clone cleanups script are executed? We created a script and it has to run last.
I looked at System Clone - ServiceNow Wiki and don't see any order.
- Disable emails: Disables email on the target instance. A default data preserver maintains other email settings from the target instance.
- Regenerate text indexes: Rebuilds text indexes on the target instance after a clone. Text indexes are not cloned from the source to the target instance.
- Clear scheduled job node association: Resets any scheduled jobs that were active on the source instance to the Ready state. This script also clears the value of the System ID and Claimed by fields on all scheduled jobs.
- Install deactivated plugin: Enables the Domain Separation plugin for instances that use this feature.
- Drop backup tables: Schedules the deletion of the data contained in the target instance database prior to the clone. This original data is preserved for 24 hours following a clone to allow you to roll back an instance to the pre-clone state. If the target instance is downgraded as part of the clone, backup data is not available.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2016 02:34 PM
They don't run in any particular order. I checked the underlying code base and it is basically this:
var actions = new GlideRecord("clone_cleanup_script");
actions.query();
while (actions.next()) {
var name = actions.getValue("name");
var script = actions.getValue("script");
//run the script
}
If you really need to have the scripts execute in a defined order, you could do away with having multiple scripts and just have one big script; giving you much more control over the order. You just need to copy/paste the script from each individual clone script into a single one. You can leave the old ones in there and just have them be blank.
Adding an "order" field to the Cleanup Scripts table would be a nice enhancement to the product, I'll open an enhancement request.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2016 09:09 AM
Hi Linda,
Did you still have any unanswered questions?
Regards, Matthew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2016 09:17 AM
I did submit a request to HI support to see what options are available. thanks for your help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2016 04:41 PM
Hi Linda,
I'm actually a senior member of the support team on HI . I've wracked my brain and looked through all the source code. There is no way to have multiple clone cleanup scripts that execute in a specific order. The only way to really control the execution order is to merge the multiple scripts into a single script. The way it works is this:
- In the [immutable] Java code, the clone queries all the Clone Cleanup Script records in the system without ordering the results
- Next, the clone loops through the results and Inserts a scheduled job for each of the Cleanup Scripts into the target instance
- Each scheduled job contains the script from a Clone Cleanup Script
- The scripts gets executed on the target instance as scheduled jobs
- Even if you could control the order that the scheduled jobs were being created, you wouldn't be able to control the order that they were picked up and executed. The order of execution of the scheduled jobs is based on the "Next action" field. The value of that field will have precision down to the second but they will undoubtedly be created within a couple milliseconds of each other and therefore they will all have the same "Next action" value. The order of execution will be arbitrary.
I think merging the scripts into a single script is the best correct answer. It is a simple solution to your very real and important need.
That being said, I'd recommend that the Clone Cleanup Scripts are written in a way that they don't require any specific order to be followed. The less dependencies between them the better. If they truly have dependencies then they probably ought to be a single script anyway.