Fileset/Local Output filename containing datetime stamp

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Fileset/Local Output filename containing datetime stamp

  • Creator
    Topic
  • #54570
    David Teh
    Participant

      Hi folks,

      For a OB thread using protocol “Fileset/Local”, I want to have one file created per message sent.

      We have used “numfile” proc in the past but now I want the datetime stamp in the filename instead. Is there an existing proc provided that does this, else please provide some direction on how to do this.

      TIA!

    Viewing 4 reply threads
    • Author
      Replies
      • #82026
        Robert Kersemakers
        Participant

          Hi David,

          Here is a tcl-script I made to add the date/time stamp to the original filename. You can choose how the datetime-stamp needs to look like.

          Code:


          ######################################################################
          # Name:        orbis_addYYYYMMDDHHMMtoFilename
          # Purpose:     Set filename to DRIVERCTL metadata for file or fileset protocol
          #              Format: sourcethreadname_YYYYMMDDHHMM
          #
          #              Results in files containing all messages per source thread/per day
          #              Example usage: For resend/storing purposes.
          # UPoC type:   tps
          # Args:        tps keyedlist containing the following keys:
          #       MODE    run mode (”start”, “run” or “time”)
          #       MSGID   message handle
          #       ARGS    user-supplied arguments:
          # DATESTRING Format of date to be used; default “%Y%m%d%H%M”
          #               DEBUG optional default 0. if 1 provides more output
          #
          # Returns: tps disposition list:
          #          CONTINUE of all messages
          #
          # Note:    Preserves all other settings in DRIVERCTL if any, such as DIR or APPEND
          #

          proc orbis_addYYYYMMDDHHMMtoFilename { args } {
             global HciConnName

             keylget args MODE mode                  ;# Fetch mode
             keylget args CONTEXT ctx
             keylget args ARGS uargs

             set debug 0 ; keylget uargs DEBUG debug
             set datestring “%Y%m%d%H%M”; keylget uargs DATESTRING datestring

             set module “[lindex [info level 0] 0]/$HciConnName/$ctx/$mode”

             set dispList {}
             switch -exact — $mode {
                 start {
                     # Perform special init functions.
                 }

                 run {
                     # ‘run’ mode always has a MSGID; fetch and process it
                     keylget args MSGID mh

                     set driver [msgmetaget $mh DRIVERCTL]
                     set fileset “”
                     keylget driver FILESET fileset
                     set filename “”
                     keylget fileset OBFILE filename

                     if {[string length $filename] > 0} {
                       if {$debug > 0} {
                         echo “Originele filenaam: ”
                       }
                       set dot [string last . $filename]
                       set naam [string range $filename 0 [expr $dot-1]]
                       set extensie [string range $filename [expr $dot+1] end]
                     } else {
                       set naam “no_name”
                       set extensie “nul”
                     }
                     set date [clock format [clock seconds] -format $datestring]
                     set filename “${naam}_${date}.${extensie}”
                     if {$debug > 0} {
                       echo “Out filenaam: ”
                     }
                     keylset driverctl FILESET.OBFILE $filename
                     msgmetaset $mh DRIVERCTL $driverctl

                     lappend dispList “CONTINUE $mh”
                 }

                 time {
                     # Timer-based processing
             # N.B.: there may or may not be a MSGID key in args
                 }
                 
                 shutdown {
             # Doing some clean-up work
          }

                 default {
                     error “Unknown mode ‘$mode’ in $module”
                 }
             }

             return $dispList
          }

          You can add this script to the TPS Outbound Data of an outbound file(set) thread.

          Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

        • #82027
          David Teh
          Participant

            Thanks Robert!

            In your setup, you have the timestamp up to the seconds or milliseconds?

            Seconds seem insufficient to distinguish the messages as they do come fast especially for ADTs.

            Thanks!

          • #82028
            Robert Kersemakers
            Participant

              Ah, you want the date/time stamp to identify each file/message. Well, I have never done that. Basically because, as you say, you can have more than one message per second and the ‘clock format’ can only go up to seconds. So I always used a counter (numfile or gc_emulateNumberedFiles) in the filename to get a unique filename. You can combine a counter with the current date/time.

              However, since tcl 8.5 (or maybe even earlier) you can do a ‘clock microseconds’ and it will return the time in microseconds. You could use this in the above script to use this time (or maybe a combination of date/time and the last 6 digits of [clock microseconds]). However: if you have a very fast server that spits out message at an awesome rate, maybe even microseconds wouldn’t be good enough.

              So a counter is the safest way to go.

              Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

            • #82029
              David Teh
              Participant

                Thanks Robert for sharing!

              • #82030
                David Teh
                Participant

                  Hi folks,

                  Want to share this for those who might find it helpful and also to get comments in case the setup creates some other issues.

                  A request came in to implement a temporary (6 months) solution for a legacy system to receive messages using NFS.

                  The receiving system wants the file named with the date/time included.

                  And, after each file containing the message has been written to the remote server, they requested for another zero-byte file that contains the filename of the previous file to be written as well. Their concern is that they may be grabbing a file that is still being written by Cloverleaf.

                  Please give comments, if any. TIA!!!

                  The result (listing of the directory):

                  -rw-rw-r–

              Viewing 4 reply threads
              • The forum ‘Cloverleaf’ is closed to new topics and replies.