Homepage › Clovertech Forums › Read Only Archives › Cloverleaf › Cloverleaf › Deletion TPS
- This topic has 11 replies, 7 voices, and was last updated 8 years ago by
Jim Kosloskey.
-
CreatorTopic
-
October 27, 2009 at 11:55 pm #51285
Bill May
ParticipantDear Clovertechers, I am looking for an example of of Fileset Local Deletion TPS
What I’d really like to do is move the files to an archive directory after they have been processed
Cheers,
Bill
-
CreatorTopic
-
AuthorReplies
-
-
October 28, 2009 at 3:01 pm #69531
Sundeep Kumar
ParticipantBill,
I recall from an earlier post I read, an explanation of how the Dir Parse and Deletion Procs work. I cannot seem to find the link. But here it goes: You can use the Dir. Parse tps and choose which files in the configured directory you want to process.
-
October 29, 2009 at 1:36 pm #69532
Greg Eriksen
ParticipantIt’s been awhile since I wrote this, but here’s an example of a fileset local deletion tps that moves files to an archive directory.
Code:
######################################################################
# Name: tps_local_archive
# Purpose: used as fileset ibdel proc to archive rather than
# delete processed file.
# UPoC type: tps
# Args: tps keyedlist containing the following keys:
# MODE run mode (”start”, “run” or “test”)
# MSGID message handle
# ARGS user-supplied arguments:
#
#
# Returns: tps disposition list:
# Returns “KILL” so thread does not try to delete file which
# no longer exists because it has been renamed and moved.
#proc tps_local_archive { args } {
keylget args MODE mode
set proc_name [lindex [info level [info level]] 0]switch -exact — $mode {
start {
# Perform special init functions
# N.B.: there may or may not be a MSGID key in args
}run {
# ‘run’ mode always has a MSGID; fetch and process it
keylget args MSGID mh
keylget args CONTEXT ctx# Check for correct context
if {![cequal $ctx “fileset_ibdel”]} {
echo “ERROR proc used in wrong context”
echo “Context should be fileset_ibdel”
echo “Proc called in: $ctx”
return “{KILL $mh}”
}# As far as I can tell from testing, whereas the ibdirparse proc
# message contains a list of file name(s), this ibdel proc gets passed
# just one file name per call and it includes the full file path. So,
# while I extract the “first” element from the “list”, I don’t believe
# it’s strictly necessary.
set msgList [msgget $mh]
set filePath [lindex $msgList 0]# Collect or create the file names and paths for archiving.
set fileDir [file dirname $filePath]
set fileName [file tail $filePath]
set timestamp [clock format [clock seconds] -format %Y%m%d%H%M%S]
set archiveName ${fileName}.$timestamp
set archiveDir [file join $fileDir archive]
set archivePath [file join $archiveDir $archiveName]
set emails “INTEGRATION@yourdomain.org”# Create the archive subdirectory if it doesn’t already exist.
if {![file exists $archiveDir]} {
echo “creating archive directory”
if {[catch {file mkdir $archiveDir} err]} {
echo “***n*** $proc_name – Error creating archive directoryn***”
echo $err
set subject “_ERROR_ – Archive $fileDir”
set message “nError creating archive directory in $fileDir”
if {[catch {your_email_proc “$emails” “$subject” “$message” “your_email_server” “your_domain.org” “” “”} err]} {
echo “error sending email”
echo $err
}
}
}# Rename file while moving to archive subdirectory.
if {[catch {file rename $filePath $archivePath} err]} {
echo “***n*** $proc_name – Error moving and renaming file:n*** $filePath to $archivePath n***”
echo $err
set subject “_ERROR_ – Archive $fileName”
set message “nError renaming file $filePath to $archivePath”
if {[catch {your_email_proc “$emails” “$subject” “$message” “your_email_server” “your_domain.org” “” “”} err]} {
echo “error sending email”
echo $err
}
} else {
echo “***n*** $proc_name – archived file: $archivePath n***”
}# Attempt to gzip or compress the archived file.
if {[catch {exec gzip $archivePath} err]} {
echo “***n*** $proc_name – Error gzipping file $archivePath n***”
echo $err
if {[catch {exec compress “$archivePath”} err]} {
echo “***n*** $proc_name – Error compressing $archivePath n***”
echo $err
}
}return “{KILL $mh}”
}time {
# Timer-based processing
# N.B.: there may or may not be a MSGID key in args
}shutdown {
echo “*** $proc_name shutting down.”
}default {
error “Unknown mode ‘$mode’ in $proc_name”
}
}
} -
October 29, 2009 at 2:53 pm #69533
Kevan Riley
ParticipantAnd just for comparison, here is one I wrote a little while back:
Code:
######################################################################
#
# Name: ibdel_cp_to_ibsave
#
# Purpose: Save a copy of the file(s) to Inboundsave before the
# engine deletes it
#
# Creator: Kevan Riley
#
# On: 2009.09.01
#
# UPoC type: fileset_ibdel
#
# Args: tps keyedlist containing the following keys:
# {MODE run}
# {MSGID message0}
# {CONTEXT fileset_ibdel}
# {ARGS {}}
# {VERSION 3.0}
#
# Returns: CONTINUE – where the “message” is the list
# of file names for the engine to delete.
#
#
######################################################################proc ibdel_cp_to_ibsave { args } {
global env HciConnName HciSiteDir
set procName “[lindex [info level 1] 0]”
set Process “[lindex [split [pwd] /] end]”
set module “$HciConnName/$procName”
set conn “$HciConnName”set context [keylget args CONTEXT]
set mode [keylget args MODE]
catch {keylget args MSGID mh}set dispList {} ;# Nothing to return
echo #########################################
echo “[clock format [clock seconds] -format “%Y-%m-%d %H:%M:%S”]”
echo PROC: $procName
echo CONTEXT: $context MODE: $mode
catch {echo [set filelist [msgget $mh]]}
echo #########################################switch -exact — $mode {
start {
# Perform special init functions
}run {
set ibSaveDir [file join $env(HCISITEDIR) exec processes]
set ibSaveDir [file join $ibSaveDir $Process InboundSave]
#
# make sure “ibSaveDir exists, if not create it
#
if {![file exists $ibSaveDir]} {
echo ” creating InboundSave directory….”
if {[catch {file mkdir $ibSaveDir} result]} {
puts “ERROR: $module – $context – Unable to create “$ibSaveDir””
puts ” result was: $result”
} ;#end if
} ;#end if#
# there really should only be one file here, but we’ll treat it as a
# list just in case
#
foreach file $filelist {set filename $file
set newFile “[file tail $file]”
append newFile “_”
append newFile [clock format [clock seconds] -format “%Y%m%d_%H%M”]
set newFile [file join $ibSaveDir $newFile]
echo “INFO: Archiving file to $newFile.gz”if {[catch {file copy $filename $newFile} result]} {
echo “ERROR: file rename $filename $newFile failed with: $result”
} ;#end ifset cmd “exec gzip $newFile &”
if {[catch $cmd result]} {
echo “ERROR: gzip failed with: $result”
} ;#end ifset dttm “[clock format [clock seconds] -format “%Y-%m-%d %H:%M:%S”]”
echo “INFO: $module – Done – $dttm”} ;#end foreach file
lappend dispList “CONTINUE $mh”
}time {
# Timer-based processing
}
shutdown {
# Doing some clean-up work
}
} ;#end switch modereturn $dispList
} ;# end proc dirdelete_nchess
Kevan Riley
Adventist Health System – Information Services
Lake Mary FL
-
January 20, 2010 at 6:55 pm #69534
Jennifer Hardesty
ParticipantThere must be some trick to getting this to work on fileset-ftp. When I try to do the same thing — copying the file from the ftp folder to a local archive folder — I get a message: “error renaming “WX_CHG.001″: no such file or directory”. However, all of the messages in the file are processed correctly.
Has anyone done this with ftp?
-
November 24, 2015 at 8:39 pm #69535
Dianna Braden
ParticipantI have a successful deletion tps – which moves the file as needed.
But from the output of this tps – I just need the filename string passed on to a VRL to HL7 xlate
Instead I am getting contents of the file no matter what I try.
Any help will be appreciated…
-
November 24, 2015 at 9:37 pm #69536
Jim Kosloskey
ParticipantClarification please.
Are you saying you do not want the data in the files, just the names of the files?
Or do you want the data in the files AND the names of the files?
If both, do you want them separately or do you want the name of the file associated with each message, or …?
email: jim.kosloskey@jim-kosloskey.com
-
November 24, 2015 at 10:20 pm #69537
Dianna Braden
ParticipantI just need the “names of the files only” to be passed on from my fileset local thread
-
November 24, 2015 at 10:33 pm #69538
Jim Kosloskey
ParticipantOne thought…
In your dirparse take the file list and write that to a file (one file name per record). Then return an empty list to Cloverleaf. That will stop Cloverleaf from reading those files. No need for a delete.
Then in another Fileset/Local search for and read the file created above with the file names in it.
Each of those will be a message and route and Xlate that.
email: jim.kosloskey@jim-kosloskey.com
-
November 24, 2015 at 10:52 pm #69539
Dianna Braden
ParticipantOk – I see how that could work.
Was just hoping to do most of the work of getting the filename and moving it in the same proc.
If I can pass the filename AND contents together – then I could have a different inbound tps proc to parse out the filename right?
How do I add filename to contents being passed?
-
November 24, 2015 at 10:59 pm #69540
Dianna Braden
Participantnevermind I need that file intact and not added to
Your file with list of files is probably best
-
November 24, 2015 at 11:37 pm #69541
Jim Kosloskey
ParticipantYou should be able to get the IBFILENAME from the metadata of each message. So no need to actually add it to the data.
However you will need to decide how to extract one and only one instance of each file name from multiple messages, etc.
That could be doable I guess if you decide to go that way.
email: jim.kosloskey@jim-kosloskey.com
-
-
AuthorReplies
- The forum ‘Cloverleaf’ is closed to new topics and replies.