BWinchell
Enthusiast
Enthusiast

Bulk Delete Schedule Tasks in Orchestrator

Jump to solution

Hello,

I have a bunch of workflows that schedule tasks for certain times (not recurring on a regular schedule, so manual initiation).

Each time a task is schedule, an entry goes into "Scheduler" tab in VCO.  Once the task has been run, you get your nice green check mark.

Is there any way to bulk delete the past tasks (there are about 700+) that have run or have them clear out after X days automatically?

Thanks

B

1 Solution

Accepted Solutions
schepp
Leadership
Leadership

Ah, now I see what you mean Smiley Happy

Well, just right click on the left side (don't select a scheduled run) and select "delete all finished tasks":

delfin.jpg

View solution in original post

0 Kudos
19 Replies
schepp
Leadership
Leadership

Hi,

you can right click the Workflow and click "delete all finished workflow runs".

Or do you want to keep the latest?

Tim

0 Kudos
BWinchell
Enthusiast
Enthusiast

Hi Tim,

These are not the workflow results but the actual tasks that get scheduled in the Scheduler "Run view > Scheduler".

So I have workflows that schedule a task (the output creates a scheduled tasks).  These are what I am trying to get rid of.

Thanks

B

0 Kudos
schepp
Leadership
Leadership

Ah, now I see what you mean Smiley Happy

Well, just right click on the left side (don't select a scheduled run) and select "delete all finished tasks":

delfin.jpg

View solution in original post

0 Kudos
BWinchell
Enthusiast
Enthusiast

Hi Tim,

I see what you get but for some reason, I do not get that option on that screen.  I only get the options for individual tasks (resume, delete, edit, etc..)

What version of VRO are you running?  Are you logged in as the local admin or external user?

That is what I want, just need to figure out how to get there.

Thanks

B

0 Kudos
schepp
Leadership
Leadership

Hi,

I run the following version:

6.0.1.2510741 (6.0.1.2490144)

And I'm logged in with an active Directory user that is a member of the vRO admin group.

Tim

0 Kudos
BWinchell
Enthusiast
Enthusiast

Hi,

I am running:

Vendor:               VMware Inc.

Appliance Name:             VMware vRealize Orchestrator Appliance

Appliance Version:         6.0.3.0 Build 3000579

I am also logged in via AD account that is part of the VRO admins.

Thanks

B

0 Kudos
BWinchell
Enthusiast
Enthusiast

I double checked the permissions in AD and in VCO (VRO now Smiley Wink).

Untitled.png

I tried right-clicking everywhere on the left side with none of the options in your screen.  I do not have the option to sort and the only place I can find the Schedule task/as in on the right side icon.

Maybe a bug or removed in 6.0.3?

Thanks

B

0 Kudos
schepp
Leadership
Leadership

Can you scroll down and right click on a free space below the last task?

In your screenshot you get the context menu of a single selected task.

0 Kudos
BWinchell
Enthusiast
Enthusiast

no free space after the last task.  There is sliver of space the VRO does not register a right-click.  Only if I click on an object. Smiley Sad

0 Kudos
BWinchell
Enthusiast
Enthusiast

So you are correct.

There is a bug in the system.  If the Scheduler window fills up, it does not show any free space below the last task.  So you cannot right-click to get options.

Once I deleted enough tasks to get them to fit in one window, I can click in the free space and get the option.  I will have to open a case with support.

Thanks

B

0 Kudos
Burke-
VMware Employee
VMware Employee

Try going to the very bottom of your list and right-click in the white-space after the last entry. Right clicking anywhere that a line-item is present results in options for that line item. I just tested on my 6.0.3 server and see the option to Delete All finished tasks. That appears to be the only way to access that feature Smiley Sad I did a bit of poking around in code and api explorer. I can get all the tasks and find all that have finished, but there does not appear to be a delete method in the scripting api for the Task object. Maybe I'm missing something and someone from Engineering can reply here...

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
0 Kudos
iiliev
VMware Employee
VMware Employee

There is a method cancel() that deletes a Task object. Here is some sample code that would delete all tasks

var tasks = Server.findAllForType('Task');

for each (var task in tasks) {

    task.cancel();

}

BWinchell
Enthusiast
Enthusiast

So I wanted to tweak and make this (more complicated than it has to be but...) more flexible.

The issue I am having is my logic to be meet does not work correctly.  The task state should be one of the "taskStateRemove" & "executionDate < cut-off date" & "task.name == regexp".

//Tasks states that qualify to be removed

  var taskStateRemove = ("failed","completed","killed","finished");

//Get date from VCO

  var date = new Date();

  //var date = System.getDate("now");

  var pastDate = new Date(date.getTime() - (days * 24 * 60 * 60 * 1000));

  //var pastDate = System.getDate("10 days ago");

  var gmtPast = pastDate.toGMTString(pastDate);

  System.log("===========================LOG-BEGIN=======================");

  System.log("Today's date: " + date);

  System.log("Past date: " + pastDate);

  System.log("Past date in GMT: " + gmtPast);

  System.log("===========================LOG-END=========================");

//Find all the sheduled tasks on the VCO

  var tasks = Server.findAllForType('Task');

//Delete each task that meets the criteria

  for each (var task in tasks) {

  var executeDate = task.executionDate.toGMTString(task.executionDate);

  var taskState = task.state;

  var taskName = task.name;

  System.log("Task name: " + taskName);

  System.log("STATE: " + taskState + " Execute date: " + executeDate);

  if (taskState.indexOf(taskStateRemove) > -1 &&

  executeDate < gmtPast &&

  taskName.search(regexp,regexpMod) > -1) {

// task.cancel();

  System.log("ACTION: Task " + taskName + " has been removed from the scheduler.");

  } else {

  System.log("Task " + taskName + "'s records will be kept, for now");

  }

  }

0 Kudos
iiliev
VMware Employee
VMware Employee

I see a couple of issues:

You want taskStateRemove variable to be an array of strings, right? Then it should be defined this way (with square brackets)

var taskStateRemove = ["failed","completed","killed","finished"];

The second issue is with indexOf(). You are using it as searchElement.indexOf(array) but it should be array.indexOf(searchElement). In your code, it should be

if (taskStateRemove.indexOf(task.state) > -1 && ...

0 Kudos
BWinchell
Enthusiast
Enthusiast

Thanks for both of those points.  I knew something was not correct but was looking at it too long.

I have 2 questions that you might be able to shed light on.

  1. In the api, the Task.state refers to "task-state".  Task-state has the following possible values:
    1. starting
    2. running
    3. failed
    4. completed
    5. killed
      1. There is no state of finished but, the state of the scheduled task is "finished".  How/why?
  2. Date comparison logic.  I was under the impression when comparing dates in javascript that:
    1. dateInThePast < currentDate

      1. basically meant "if the dateInThePast happened before your currentDate then, TRUE
    2. But I had to modify the code to be this:
    3. dateInThePast > currentDate

      1. to get the result I actually wanted.

This still does not work they way expected.  Pointed out below as my date comparison is actually comparing a string and not a date.

Thanks for the help.

B

0 Kudos
iiliev
VMware Employee
VMware Employee

task-state values in API Explorer are generated automatically. I have to check in the source code where these values come from.

For date comparison logic, your initial impression is the correct one. The problem is that the following statement on line 23

executeDate > gmtPast

compares not two dates, but their string representation. The correct way to compare these two dates is to replace the above statement with the following one:

task.executionDate > pastDate

For example let's say the task execution date is Nov 6th, 2015, and the past date is Nov 5th, 2015. The dates represented as GMT strings could look like the following

"Fri, 06 Nov 2015 20:56:10 GMT"     // executeDate

"Thu, 05 Nov 2015 13:29:38 GMT"    // gmtPast

So, taken as dates, execution date is after past date (Nov 6th is after Nov 5th), but taken as strings, lexicographic-ally the first string is before the second ('F' is before 'T')

0 Kudos
BWinchell
Enthusiast
Enthusiast

I have to say, I am really starting to dislike Dates in code.  I wish the source code always used the same date format. :smileyconfused:

So herein the issue.  When I change the date comparison to below (actually had this in the past) the issue comes with the date format:

new Date() = Thu Nov 05 2015 19:57:10 GMT-0500 (EST)

task.exectionDate = 2015-11-02 22:45:00.0

These are never less-than or greater than in the results.

(task.executionDate < pastDate):

[2015-11-08 19:57:10.311] [I] ===========================LOG-BEGIN=======================

[2015-11-08 19:57:10.311] [I] Today's date: Sun Nov 08 2015 19:57:10 GMT-0500 (EST)

[2015-11-08 19:57:10.311] [I] Past date: Thu Nov 05 2015 19:57:10 GMT-0500 (EST)

[2015-11-08 19:57:10.311] [I] Past date in GMT: Fri, 06 Nov 2015 00:57:10 GMT

[2015-11-08 19:57:10.311] [I] ===========================LOG-END=========================

[2015-11-08 19:57:10.379] [I] Task name: TNG_createSnapshot

[2015-11-08 19:57:10.379] [I] STATE: finished Execute date: 2015-11-02 22:45:00.0

[2015-11-08 19:57:10.379] [I] Task TNG_createSnapshot's records will be kept, for now

[2015-11-08 19:57:10.379] [I] Task name: TNG_RemoveSnapshotByName

[2015-11-08 19:57:10.379] [I] STATE: finished Execute date: 2015-11-05 22:45:00.0

[2015-11-08 19:57:10.379] [I] Task TNG_RemoveSnapshotByName's records will be kept, for now

(task.executionDate > pastDate):

2015-11-08 20:05:12.895] [I] ===========================LOG-BEGIN=======================

[2015-11-08 20:05:12.895] [I] Today's date: Sun Nov 08 2015 20:05:12 GMT-0500 (EST)

[2015-11-08 20:05:12.895] [I] Past date: Thu Nov 05 2015 20:05:12 GMT-0500 (EST)

[2015-11-08 20:05:12.895] [I] Past date in GMT: Fri, 06 Nov 2015 01:05:12 GMT

[2015-11-08 20:05:12.896] [I] ===========================LOG-END=========================

[2015-11-08 20:05:12.969] [I] Task name: TNG_createSnapshot

[2015-11-08 20:05:12.969] [I] STATE: finished Execute date: 2015-11-02 22:45:00.0

[2015-11-08 20:05:12.969] [I] Task TNG_createSnapshot's records will be kept, for now

[2015-11-08 20:05:12.969] [I] Task name: TNG_RemoveSnapshotByName

[2015-11-08 20:05:12.969] [I] STATE: finished Execute date: 2015-11-05 22:45:00.0

[2015-11-08 20:05:12.970] [I] Task TNG_RemoveSnapshotByName's records will be kept, for now

One of these should be marked for deletion.  So my guess/assumption is the system cannot compare these dates as they are in different formats (why I converted them to GMT but did not pay attention they also get converted to a string).

So the next thing I tried was to Date.parse (which should return a date) the dates to get them into something common.

The pastDate (Date.parse(pastDate) = Past date: 1446772615000

When I do something similar to task.executionDate (Date.parse(task.executionDate)) = Execute date: NaN  [Not-a-number].

I also tried (Date.UTC(task.executionDate)) = Execute date: NaN

My (uneducated) guess is the return of task.executionDate is not actually a date or am I just missing something obvious?

Thanks

B

0 Kudos
BWinchell
Enthusiast
Enthusiast

Ok.  I think I got this sorted now (always the simple ones that take the longest).

There was an issue with the comparison of different date formats (task.executionDate does = 'Date' object).

So I basically converted all the dates into a specific date format "yyyy.MM.dd-HH:mm:ss.S".  This now allows the code to compare the dates correctly.

So I cleaned up the code and added a test feature that will report the task but not remove them unless you disable test mode.

Thanks for all the help.

B

0 Kudos
BWinchell
Enthusiast
Enthusiast

Hello,

There was a typo in the last version 2.0.0 that prevented the task from actually being removed.  That is rectified in version 2.0.1.

Thanks

B

0 Kudos