Hi,
We are planning to delete the workflows which are older than 60 days. iwgetwfobj -c will provide the list of completed workflows, but is there any command to get the list of workflow which are open for more than 60 days?
Thanks
Ajay
Nope. You need to query each and check the date
I wrote such a process.
I loop through all the jobs and send a warning at 21 days, then delete them at 30 days.
If possible, could you please share the code snippet?
We are windows based and I did it in PERL.
I went for "let's get this done, it runs once per week when no one is around." Efficiency during run-time was last on my list of priorities.
The basic idea:
Get all the active job numbers:
$iwgetwfobj = `iwgetwfobj`;
$iwgetwfobj =~ s/\n/,/g;$iwgetwfobj =~ s/.*<activeworkflows>(.*)<\/activeworkflows>.*/$1/;$iwgetwfobj =~ s/[^0-9,]//g;
@jobs = split /,/, $iwgetwfobj;
foreach (@jobs) { deleteOldJobs($_); #jobId is in $_}
.....
in deleteOldJobs:
...
$jobXML = `iwgetwfobj $jobId`;$jobXML =~ s/\n//g;if ($jobXML =~ m/owner="(ENT.)?([^"]+)".*activationtime="(\d+)".*<description>(.*)<\/description>/m) {$owner = $2;$activationTime = $3;$description = $4;$jobStatus = $4;$ageSeconds = time - $activationTime;$ageDays = $ageSeconds / (3600*24);
if ($ageDays > 30) {
`iwrmjob $jobId`;
} else {
if ($ageDays > 23) {
--- send email here warning of the pending deletiong
}
This was the easy part. The part that took time was all the stuff around it to send notifications of what is about to be deleted in 7 days. I included things like where it was in the workflow and what files are attached.
Things to think about - if you kill a job, what do you do with the attached files? Do you leave them modified? Do you revert them back to the last staged version?
If you like the answer - please mark it as solved.
You could avoid the XML parsing by using the existing modules - something like:
#!c:/interwoven/teamsite/iw-perl/bin/iwperluse strict;use warnings;use TeamSite::WFsystem;use TeamSite::WFworkflow;use TeamSite::Config;use constant THRESHOLD_WARN => 23;use constant THRESHOLD_REMOVE => 30;(my $iwhome = TeamSite::Config::iwgethome()) =~ tr|\\|/|;my $wfs = TeamSite::WFsystem->new();my $jobs = $wfs->GetActiveWorkflows();foreach my $job (@{$jobs}) { my $seconds = time - $job->GetActivationTime(); my $days = $seconds / (3600 * 24); if ($days > THRESHOLD_REMOVE) { push @rmjobs, $job->GetId(); } elsif ($days > THRESHOLD_WARN) { # Retrieve job information (e.g.: owner, comment, etc.) # Send email notification }}my $cmd = qq($iwhome/bin/iwrmjob ) . join " ", @rmjobs;my $errs = qx($cmd 2>&1);print "$errs\nDONE\n";
Note that the above attempts to remove all the expired jobs in one step, which is more efficient than looping through them one at a time; however - if you have a large number of expired jobs to process (> 100?), you may need to break it down into smaller chunks, or just loop through them one-by-one as you stand the chance of exceeding either the maximum command line length or maximum number of command line arguments.
A slight alternative to the above would be:
#!c:/interwoven/teamsite/iw-perl/bin/iwperluse strict;use warnings;use TeamSite::WFsystem;use TeamSite::WFworkflow;use TeamSite::WFtask;use TeamSite::Config;use constant THRESHOLD_WARN => 23;use constant THRESHOLD_REMOVE => 30;(my $iwhome = TeamSite::Config::iwgethome()) =~ tr|\\|/|;my $wfs = TeamSite::WFsystem->new();my $tasks = $wfs->GetActiveTasks();my @rmjobs;foreach my $task (@{$tasks}) { my $seconds = time - $task->GetActivationTime(); my $days = $seconds / (3600 * 24); if ($days > THRESHOLD_REMOVE) { push @rmjobs, $task->GetWorkflowId(); } elsif ($days > THRESHOLD_WARN) { # Retrieve task and/or job information # Send email notification }}my $cmd = qq($iwhome/bin/iwrmjob ) . join " ", @rmjobs;my $errs = qx($cmd 2>&1);print "$errs\nDONE\n";
The distinction being that you work from the activation time of the active task rather than the job. The advantage would be to allow for N-days difference between when the job was instantiated and when it was last interacted with. The disadvantage of doing this would be if you have properly setup timeout handles that send out notifications for tardy task completion and then re-activate the same task - in such a case it is unlikely that the task's age will ever hit the threshold.