<?xml version="1.0" encoding="iso-8859-1"?>

<spooler>

  <config>

    <jobs>

      <job name       = "scheduler_rotate_log"
           title      = "Rotate and compress logfiles"
           spooler_id = "">

        <description>
          <include file = "jobs/JobSchedulerRotateLog.xml"/>
        </description>
  
        <params>
          <!-- store archive with compressed log files in this directory, otherwise the current log directory is used -->
          <!--<param name = "file_path" value = "/tmp/backup"/>-->
          <!-- compress log files with the given file specification, otherwise compress all files with the suffixs .log -->
          <!--<param name = "file_specification" value = "^(scheduler)([0-9\-]+)(" + spooler.id + "\.log)$"/>-->
          <!-- compress log files older than the given number of days -->
          <!--<param name = "file_age" value = "14"/>-->
        </params>
        
        <script language   = "VBScript"
                use_engine = "task"><![CDATA[
              Function spooler_process ()
              
                Dim filePath, fileAge, fileSpec
              
                spooler_process = False

                ' give a path for files to remove 
                filePath = spooler.log_dir
      
                ' give the number of days, defaults to 14 days
                fileAge = 14
      
                ' give a regular expression as file specification
                fileSpec = "^(scheduler)([0-9\-]+)"


                If Not isNull(spooler.id) And Not isEmpty(spooler.id) And spooler.id <> "" Then
                  fileSpec = fileSpec & "(\." & spooler.id & ")"
                End If
                fileSpec = fileSpec & "(\.log)$"

                If Not isEmpty(spooler_task.params.var("file_path")) Then
                  filePath = spooler_task.params.var("file_path")
                  spooler_log.info(".. job parameter [file_path]: " + filePath)
                End If

                If Not isEmpty(spooler_task.params.var("file_age")) Then
                  fileAge = spooler_task.params.var("file_age")
                  spooler_log.info(".. job parameter [file_age]: " + fileAge)
                End If

                If Not isEmpty(spooler_task.params.var("file_spec")) Then
                  fileSpec = spooler_task.params.var("file_spec")
                  spooler_log.info(".. job parameter [file_spec]: " + fileSpec)
                End If

                fileDate = DateAdd("d", -fileAge, date())

                On Error Resume Next
                   spooler.log.start_new_file()
                   If err.number <> 0 Then
                      spooler_log.warn("an error occurred rotating log file: " & err.description)
                      Exit Function
                   End If
                On Error Goto 0

                On Error Resume Next
                   counter = 0
                   If Right(filePath,1) <> "/" Then filePath = filePath & "/"
        
                   Set hw = CreateObject("hostware.global")
                   Set hf = CreateObject("hostware.file")

                   hf.open("select * where filename =~ '" & fileSpec & "' and creation_time < '" & hw.date_as_string(fileDate) & "' | dir " & spooler.log_dir & "/*")
                   While Not hf.eof()
                     counter = counter + 1
                     Set file = hf.get()
                     hw.copy_file "file -b " & file.path, "gzip | file -b " & filePath & file.filename & ".gz"

                     If err.number = 0 Then
                       hw.remove_file(file.path)
                     End If

                     If err.number <> 0 Then
                       spooler_log.warn("an error occurred compressing log file [" & file.path & "] to gzip file: " & err.description)
                       Exit Function
                     End If

                     spooler_log.info( ".. log file [" & file.path & "] compressed to: " & filePath & file.filename & ".gz")
                   Wend
                On Error Goto 0
                   
                If counter > 0 Then spooler_log.info(counter & " log files compressed")

              End Function
        ]]></script>

        <!-- rotate log files every day of the week at the given hour -->
        <!--
        <run_time let_run = "yes"
                  begin   = "00:00"
                  end     = "24:00">
           <period single_start = "00:00"/>
        </run_time>
        -->

      </job>


      <job name       = "scheduler_cleanup_history"
           title      = "Compress log entries in Job Scheduler history">

        <description>
           <include file = "jobs/JobSchedulerCleanupHistory.xml"/>
        </description>

        <params>
          <!-- reduce log files of history entries to the given log level -->
          <!--<param name = "cleanup_history_log_level" value = "0"/>-->
          <!-- chose history entries in the given interval of days -->
          <!--<param name = "cleanup_history_interval"  value = "3"/>-->

          <!-- alternatively give the start date for cleanup of log files -->
          <!--<param name = "cleanup_history_date_from" value = "2004-03-22"/>-->
          <!-- alternatively give the end date for cleanup of log files -->
          <!--<param name = "cleanup_history_date_to"   value = "2004-11-04"/>-->
        </params>

        <script language   = "VBScript"
                use_engine = "task">

          <include file = "jobs/scheduler_cleanup_history.vbs"/>
          <include file = "jobs/scheduler_include_job.vbs"/>
          
        </script>

        <!-- cleanup history entries every day of the week at the given hour -->
        <!--
        <run_time let_run = "yes"
                  begin   = "00:00"
                  end     = "24:00">
           <period single_start = "01:00"/>
        </run_time>
        -->

      </job>


      <job name       = "scheduler_dequeue_mail"
           title      = "Send buffered mails from mail queue">

        <description>
           <include file = "jobs/JobSchedulerDequeueMailJob.xml"/>
        </description>

        <script language   = "VBScript"
                use_engine = "task"><![CDATA[

              Function spooler_open ()
              
                  Dim count
                  On Error Resume Next
                  spooler_open = False

                  count = spooler_log.mail.dequeue()
                  If err.number = 0 Then
                    If count > 0 Then spooler_log.info( count & " buffered mails were sent, mail queue is empty" )
                  Else
                    spooler_log.warn( "mail queue could not be processed: " & err.description )
                  End If

              End Function

        ]]></script>

        <!-- repeat dequeueing in the given interval of seconds (1/2 hour) -->
        <!--
        <run_time let_run = "yes"
                  repeat  = "1800"/>
        -->

      </job>


      <job name       = "scheduler_restart"
           title      = "Restart Job Scheduler">

        <description>
           <include file = "jobs/JobSchedulerRestart.xml"/>
        </description>

        <script language   = "VBScript"
                use_engine = "task"><![CDATA[
                
                spooler.terminate_and_restart(600)

        ]]></script>

        <!-- restart scheduler every day of the week at the given hour -->
        <!--
        <run_time let_run = "yes"
                  begin   = "00:00"
                  end     = "24:00">
           <period single_start = "04:00"/>
        </run_time>
        -->

      </job>
      
    
    </jobs>

  </config>
  
</spooler>