Message-ID: <247609714.8629.1711692358321.JavaMail.confluence@host3.pipelinefx.com> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_8628_2042596608.1711692358321" ------=_Part_8628_2042596608.1711692358321 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Universal Callbacks

Universal Callbacks

=20 Icon=20
=20
New in Qube 6.6
=20
=20
=20

Overview

Universal callbacks are operations which are automatically attached= to every job that is submitted. These are installed by a site administrato= r either on the Supervisor's local disk or on a file system which is access= ible by the supervisor service.

Setting Up Univer= sal Callbacks

To set up Universal Callbacks, the site administrator needs to make a di= rectory (default $QBDIR/callback) and create a text-based configuration fil= e, called "callbacks.conf" in that directory. Further, in the sam= e directory, files containing the implementation (aka "code") of = each Universal Callback must also be installed.

The callbacks.conf file serves as a map that tells the system which call= back code should be triggered to run on what events.

The "c= allbacks.conf" file

The callbacks.conf file is a text file, much like qb.conf, containing on= e or more lines with a "key =3D value" pair, associating each imp= lementation file to a trigger event. The syntax is:

=20
# lines starting with a hash mark are comments
filename =3D trigger
=20

The filename points to a file in the same directory tha= t implements the callback code. Note that Universal Callbacks support Pytho= n, Perl, and Qube callbacks, and the filename must have the extension .py, = .pl, or .qcb, respectively.

The trigger specifies the triggering event that activat= es the callback, described in details at Triggers

Here's an example:

=20
#
# callbacks.conf
#
# syntax of this file is :
# filename =3D triggers
#
logFailuresToDB.py =3D failed-job-self
mail-status.qcb =3D done-job-self
checkWork.pl =3D done-work-self-*
submitted.py =3D submit-job-self
=20

In this example, there are presumably 4 implementation files in th= e callback directory, logFailuresToDB.py, mail-status.qcb, submitted.py, an= d = checkWork.pl, that have the implementation code in them.

=20
=20

Use subprocess.Popen in callbacks

=20 Icon=20
=20

If you ever need to run an external script in a callback, we recommend t= he use of subprocess.Popen() to run the external script inside= the callback. This returns immediately and allows the callback to continue= running, rather than blocking and waiting for the external script to compl= ete; otherwise the supervisor process is tied up for the duration of the ex= ternal script's execution.

Do not use os.system() to run the external script, as t= his call will block until the external script exits. When a large number of= callbacks tie up supervisor processes at the same time, your supervisor pe= rformance will suffer.

=20
=20
=20
=20

Never use sys.exit() in a callback

=20 Icon=20
=20

Do not call sys.exit() at the end of the callback code, thi= s kills the calling supervisor process.

=20
=20
=20
submitted.py
=20
#!/usr/bin/env python

import sys
import qb
import traceback

fh =3D open('/tmp/univeral_callback_test', 'a')
try:
    # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D
    #  =3D=3D=3D NOTE: =3D=3D=3D
    #  the qb.jobinfo() in callbacks is not the
    #  same as the one in the external python API=20
    # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D
    job =3D qb.jobinfo("-id", qb.jobid())[0]
    fh.write('submitted %(id)s: %(name)s\n' % job)
except:
    fh.write(traceback.format_exc())
fh.close()
=20

 

Universal C= allbacks vs. FlightChecks

At first glance, Universal Callbacks and the&= nbsp;Job Pre- and Post-FlightChecks appear similar, but they h= ave an important difference:

qb.conf Parameters

supervisor_universal_callback_path

 

 

------=_Part_8628_2042596608.1711692358321--