Eileen,

If you only want one instance of your startTest.xml job to be running at a
time, then you could use a mutex semaphore within your job's xml file to
ensure this.  The STAF Semaphore (SEM) service provides the ability to
create and manipulate mutex semaphores and is described in section "8.15
Semaphore (SEM) Service" in the STAF User's Guide at
http://staf.sourceforge.net/current/STAFUG.htm#HDRSEMSRV.

So, within your startTest.xml file's main function (it's default function),
you add a try/finally block around your main function's content and have
try block request a mutex semaphore on your STAX service machine/  If the
mutex semaphore is not currently owned, then your main function will
continue on.  If the mutex semaphore is owned (because another instance of
this job is already running), then it will wait for the mutex semaphore to
become available (the SEM service puts the mutex request on the Pending
Requests list for this mutex semaphore).  The try block needs to have a
finally block to ensure that the mutex semaphore is released when the job
ends (normally or if it is terminated).  For example:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "stax.dtd">
<stax>
  <defaultcall function="Main"/>

  <script>mutexName = 'StartTest/MutexSem'</script>

  <function name="Main">
    <try>
      <sequence>

        <log message="1">'Requesting mutex semaphore %s...' %
(mutexName)</log>

        <stafcmd>
          <location>'local'</location>
          <service>'SEM'</service>
          <request>'REQUEST MUTEX %s' % (mutexName)</request>
        </stafcmd>

        <if expr="RC != 0">
          <sequence>
            <log message="1">
              'Request for mutex semaphore %s failed: RC=%s Result=%s' % \
              (mutexName, RC, STAFResult)
            </log>
            <terminate block="'main'"/>
          </sequence>
        </if>

        <log message="1">'Starting test...'</log>

        <!-- Put your startTest.xml job's main function code here or call
it -->

      </sequence>

      <finally>
        <sequence>

          <log message="1">'Releasing mutex semaphore %s...' %
(mutexName)</log>

          <stafcmd>
            <location>'local'</location>
            <service>'SEM'</service>
            <request>'RELEASE MUTEX %s' % (mutexName)</request>
          </stafcmd>

          <if expr="RC != 0">
            <sequence>
              <log message="1">
                'Release of mutex semaphore %s failed: RC=%s Result=%s' % \
                (mutexName, RC, STAFResult)
              </log>
            </sequence>
          </if>

        </sequence>
      </finally>
    </try>
  </function>

</stax>

--------------------------------------------------------------
Sharon Lucas
IBM Austin,   luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313




From:   Eileen Wei <e...@fekete.com>
To:     "staf-users@lists.sourceforge.net"
            <staf-users@lists.sourceforge.net>
Date:   11/08/2010 03:55 PM
Subject:        [staf-users] How to queue the requests to run a stax job?



I have a stax job “startTest.xml” located in a test machine (machine name
“testpc”), and I would like to run it from a remote machine (“buildpc”)
using the following command when a new build is ready (they have added each
other to trust level 5):
staf testpc stax EXECUTE FILE C:/AutomatedTesting/startTest.xml

When a new request come in and if the current stax job is still running, I
would like the request to be queued until the current job finishes.

How can I achieve that?

Thanks,
Eileen


------------------------------------------------------------------------------

The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a
Billion" shares his insights and actions to help propel your
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users
------------------------------------------------------------------------------
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a 
Billion" shares his insights and actions to help propel your 
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

Reply via email to