Re: Help need to batch delete runs from 2+ years ago (1107 Views)
Reply
Occasional Contributor
FREDVB
Posts: 11
Registered: ‎03-31-2011
Message 1 of 7 (1,126 Views)
Accepted Solution

Help need to batch delete runs from 2+ years ago

Am trying to programatically purge RUNs from 2+ years ago.   I keep running into walls and the closest I've gotten is show below however it gives me the error "Can not delete run from global RunFactory":

 

Anybody have a working sample as the API docs are less than helpful :-(

 

                Set oRunFactory = oConn.RunFactory
                Set oRuns = oRunFactory.NewList("")
                
                iRuns = oRuns.Count
                For x = 1 To iRuns
                        Set oRun = oRuns.Item(x)
                        If oRun.Field("RN_EXECUTION_DATE") <= #9/10/2009# Then
                           '' Set oTSTests = oTSTestFactory.NewList(oRun.TestInstanceID)
                           '' If oTSTests.Count = 1 Then
                           ''     Set oTSTest = oTSTests.Item(1)
                           ''         Debug.Print oTSTest.Name
                           ''    Set oTSTest = Nothing
                           '' End If
                            iKey = oRun.id
                            If iKey = 2309 Then
                                oRunFactory.RemoveItem iKey        '' gets the error above....
                            End If
                        End If
                       
 

Please use plain text.
Esteemed Contributor
William Schmitt
Posts: 337
Registered: ‎04-02-2008
Message 2 of 7 (1,122 Views)

Re: Help need to batch delete runs from 2+ years ago

Why don't you just use the Purge Runs function in the TestLab module? You can select all test sets and a date range of "Runs older than 2 years".
Please use plain text.
Occasional Contributor
FREDVB
Posts: 11
Registered: ‎03-31-2011
Message 3 of 7 (1,117 Views)

Re: Help need to batch delete runs from 2+ years ago

Our group supports over 100+ projects within our organization.  With that many we  need to be able to do a number of housekeeping tasks via a batch projcess.....

Please use plain text.
Esteemed Contributor
William Schmitt
Posts: 337
Registered: ‎04-02-2008
Message 4 of 7 (1,115 Views)

Re: Help need to batch delete runs from 2+ years ago

Look at the API ref for the PurgeRuns method of the TD connection object. It has a filter for date. You would then just need to iterate through all of your projects' TDConnections and call that method.
Please use plain text.
Occasional Contributor
FREDVB
Posts: 11
Registered: ‎03-31-2011
Message 5 of 7 (1,107 Views)

Re: Help need to batch delete runs from 2+ years ago

[ Edited ]

William - THANKS for the lead as I didn't even think about it being at the Connection level... (kinda counterintuitive)...

 

Here is a sample of the code to delete runs (excluding the last) from the prior 2 years....

 

 

                iKeep = 1                   ' keep last run ONLY
                iUnit = 4                   ' year
                iUnitCount = 2              ' 2 years
               
                dCutoff = DateAdd("yyyy", (-1 * iUnitCount), Date)
               
                Set oTSTestFactory = oConn.TSTestFactory
                Set oRunFactory = oConn.RunFactory
                Set oRuns = oRunFactory.NewList("")
                iRuns = oRuns.Count
                For x = 1 To iRuns
                        Set oRun = oRuns.Item(x)
                        If oRun.Field("RN_EXECUTION_DATE") <= dCutoff Then

                            '' if you wish to write the list of runs to a file insert the code here 

                            ''Debug.Print oRun.Name, oRun.id, oRun.TestInstanceID, oRun.TestInstance

                            ''Debug.print  oRun.Field("RN_EXECUTION_DATE")
                            iRetire = iRetire + 1
                        End If
                        Set oRun = Nothing
                Next
                Set oTSTestFactory = Nothing
                If iRetire > 0 Then
                  Debug.Print "Purging " & CStr(iRetire) & " runs before " & CStr(dCutoff) & " from " & oConn.DomainName & ":" & oConn.ProjectName
                    oConn.PurgeRuns "", iKeep, iUnit, iUnitCount, False
                Else
                    Debug.Print "No runs to purge since " & CStr(dCutoff)
                End If

                Set oRuns = Nothing
                Set oRunFactory = Nothing
            Else
                Debug.Print "Cannot connect to " & sDomain & " : " & sProject
            End If
            oConn.DisconnectProject
            oConn.ReleaseConnection

Please use plain text.
Esteemed Contributor
William Schmitt
Posts: 337
Registered: ‎04-02-2008
Message 6 of 7 (1,045 Views)

Re: Help need to batch delete runs from 2+ years ago

I am also in need of a method to purge old test runs.  I tried both the built-in Purge function and this code.  Both methods remove the entries from the RUN table, but as far as I can tell, they do not delete the corresponding files from the repository.  Purging old runs is kind of worthless if you leave a bunch of files that use up storage space.

 

Can anyone confirm that this is true?  Do I need to add code to do the file deletion after I purge the run?

Please use plain text.
Honored Contributor
Trudy Claspill
Posts: 3,559
Registered: ‎09-09-2010
Message 7 of 7 (447 Views)

Re: Help need to batch delete runs from 2+ years ago

@William

If you are using v11.0 or newer keep in mind that Repository files may not be immediately deleted. Take a look at the Administrator Guide and read the section on "The ALM Optimized Project Repository" > "Project Repository Cleanup". There can be a delay between when you execute the Delete (or Purge) function and when the files actually get deleted.
[If this post solves or helps solve your issue, mark the thread as solved and give KUDOS to the author for their assistance.]

(Opinions expressed in my postings are mine alone, and do not reflect the opinions of my employer.No warranties express or implied for any solution/suggestion posted.)
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation