On this page |
Overview ¶
You can call functions on the HQueue server through an XML/RPC client (from the same machine or over the network). You can use the server’s API to submit or query jobs.
XML/RPC is a simple language-agnostic standard for translating function calls and return values into HTTP requests and responses. Python comes with a built-in XML/RPC client library, so you don’t actually need to know anything about the protocol, it is simply the underlying technology that makes remote calls possible.
You can also connect and call functions on HQueue clients, however the API is quite limited.
Connecting to the server ¶
In Python 3 you can connect to the server using the xmlrpc.client
library (In Python 2 this was called xmlrpclib
). XML/RPC clients are available in other languages, however we will limit ourselves to showing Python on this page.
import xmlrpc.client # Connect to the HQueue server hq = xmlrpc.client.ServerProxy("http://hq_server_hostname:5000")
The returned object acts as a proxy for the remote API: you can call function attributes on the object as if you were calling functions inside the remote HQueue server. See the list of available functions below.
If the connection is not valid, trying to call a function on the proxy will raise an exception:
try: hq.ping() except ConnectionRefusedError: print("HQueue server is not available")
Note
Check the XML/RPC client library documentation to see what kind of exceptions it will raise.
The following examples show how you call functions on the proxy object:
-
Submit a new job:
# Define a job that renders an image from an IFD using Mantra. job_spec = { "name": "Render My Image", "shell": "bash", "command": ( "cd $HQROOT/houdini_distros/hfs;" " source houdini_setup;" " mantra < $HQROOT/path/to/ifds/some_frame.ifd" ) } job_ids = hq.newjob(job_spec)
-
You can use the job ID(s) returned by
newjob()
to query job progress usinggetJob()
:job = hq_server.getJob(job_ids[0], ["progress", "status"]) status = job["status"] print("The job status is", status) if status in hq.getRunningJobStatusNames(): print("{:.2f}% complete".format(job["progress"] * 100.0))
Connecting to clients ¶
HQueue clients also act as an XML/RPC API server. This allows you to call functions that force the client to send a heartbeat to the server, or cause the client to exit.
import xmlrpc.client # Connect to the HQueue client. hq_client = xmlrpc.client.ServerProxy("http://hq_client_hostname:5001")
Client API ¶
getVersion()
→ str
Returns the HQueue client version.
ping()
→ bool
Test whether the HQueue client is alive and active. Always returns True.
wakeup()
Wake up the client if it is sleeping and force it to send a hearbeat to the server.
terminate()
Request the client to terminate. Terminating a client results in the following:
-
Any paused jobs on the client are canceled.
-
New jobs cannot be assigned to the client.
-
Any jobs currently running on the client continue executing until they are complete.
-
The client is removed from the list of clients in the HQueue server.
-
Once all jobs on the client are finished, the client process exits.
Server API ¶
Queue ¶
runcmd(cmd)
→ int
Executes the given command on the HQueue farm. This is done by creating a new anonymous job with its command
property set to ‹cmd›. The job is assigned to a client machine and processed.
Returns the id of the anonymous job.
getNumWaitingJobs(wait_time=0, min_priority=-1, max_priority=-1)
→ int
Returns the number of jobs waiting for at least ‹wait_time› minutes.
A waiting job is a job waiting for a resource; for example, an available client machine.
If ‹wait_time› is 0 or negative, returns the total number of waiting jobs.
If ‹min_priority› is greater than or equal to 0, only jobs with priorities greater than or equal to ‹min_priority› are included in the returned number. If it is less than 0 then there is no minimum priority restriction.
If ‹max_priority› is greater than or equal to 0, only jobs with priorities less than or equal to ‹max_priority› are included in the returned number. If it is less than 0 then there is no maximum priority restriction.
getServerTime()
→ xmlrpc.client.DateTime
Returns the current time reported by the HQueue server. The time is in UTC.
getServerErrors()
→ dict
Returns the errors reported by the HQueue server.
The returned dictionary contains two keys: total
and errors
. total
is the number of server errors, and errors
is the list of errors (each error is a dict
).
Returns an empty dict
if no error is reported.
getVersion()
→ str
Returns the HQueue server version.
ping()
→ bool
Test whether the HQueue server is alive and active. Always returns True.
Clients ¶
getClients(client_ids=None, attribs=None)
→ list
of dict
Returns a list of dictionaries where each dictionary contains the attributes for a client specified in ‹client_ids›.
‹client_ids› must be a list of client id numbers. If it is not specified or is set to None, then attributes for all registered clients are returned.
You can optionally set the ‹attribs› argument to a list of client attributes that will be returned. This can help reduce the function’s execution time and the amount of data returned.
Here is a list of client attributes:
-
available
- whether the client is available to process jobs at the current time or not -
availabilityRules
- list of rules outlining the client’s availability on the farm -
cpus
- number of cpus -
cpuSpeed
- processor speed -
description
- the client’s description if set. An empty string is returned if no description is set for the client. -
disabled
- whether the client has been disabled on the farm or not -
groups
- list of group ids that the client is a member of -
hostname
- client machine name -
id
- client id -
idleTime
- number of minutes that the client has been idle (no activity from the logged-in user). Only applies to workstations. Is set to -1 if the idle time is unknown. -
ip
- client’s IP address -
label
- client’s display label. If the client has noname
set, the label is the client’shostname
. Otherwise the label ishostname:name
wherehostname
andname
are the client’s hostname and name respectively. -
lastHeartbeat
- time when the client last contacted the server. The time is in UTC. -
latestNote
- the text of the latest note from the thread corresponding to the client. An empty string is returned if there is no corresponding thread. -
load
- client load -
memory
- amount of physical memory in kilobytes -
memoryInUse
- amount of physical memory in kilobytes currently in-use by processes -
name
- the name of the client if a name has been specified in the client’shqnode.ini
file. By default this is empty (i.e.""
). -
needsUpgrade
- whether the client’s code is out-of-date and requires an update -
platform
- client’s operating system and architecture -
runningJobs
- ids for the jobs currently running on the client -
threadId
- the id of the note thread corresponding to the client.null
is returned if there is no corresponding thread. -
version
- hash string representing the version of the HQueue code installed on the client.
getClient(client_id, attribs=None)
→ dict
Convenience function for getClients(). Returns a dictionary of attributes for the specified client.
getClientByName(clientname, attribs=None)
→ dict
Convenience function for getClients(). Returns a dictionary of attributes for the specified client.
‹clientname› can be in the hostname
format to specify a client by hostname
or the hostname:name
format to refer to a client with the specified hostname
and name
.
By default, clients have an empty (""
) name.
getClientsByName(clientnames, attribs=None)
→ list
of dict
Convenience function for getClients(). Returns a list of dictionaries where each dictionary contains the attributes for a client specified by a clientname in ‹clientnames›.
‹clientnames› must be a list of clientnames. You can list clientnames in the hostname
format to specify a client by hostname,
or in the hostname:name
format to refer to a client with the specified hostname
and name
.
getClientErrors(client_id)
→ dict
Returns the errors reported by the a client specified in ‹client_ids›.
The returned dictionary contains two keys: total
and errors
. total
is the number of client errors, and errors
is the list of errors (each error is a dict
).
Returns an empty dict if no error is reported.
upgradeClients(client_ids)
Upgrades the clients associated with the list of ‹client_ids›.
Client groups ¶
createClientGroup(name)
→ int
Creates a new client group with name specified by ‹name›. Returns the id of the new group.
getClientGroups(group_ids=None, attribs=None)
→ list
of dict
Returns a list of dictionaries where each dictionary contains the attributes for a client group specified in ‹group_ids›.
‹group_ids› must be a list of group id numbers. If it is not specified or is set to None
, then attributes for all registered client groups are returned.
You can optionally set the ‹attribs› argument to a list of client group attributes that is returned. This can help reduce the function’s execution time and the amount of data returned.
Here is a list of client group attributes:
-
clients
- list of ids for clients that are members of the group. -
id
- group id -
name
- group name
getClientGroup(group_id, attribs=None)
→ dict
Convenience function for getClientGroups(). Returns a dictionary of attributes for the specified client group.
getClientGroupByName(name, attribs=None)
→ dict
Convenience function for getClientGroups(). Returns a dictionary of attributes for the specified client group.
addClientToGroup(group_id, client_id)
Adds the client associated with the ‹client_id› to the group associated with the ‹group_id›.
removeClientFromGroup(group_id, client_id)
Removes the client associated with ‹client_id› from the group associated with the ‹group_id›.
deleteClientGroup(group_id)
Deleted the client group associated with the ‹group_id›.
Job management ¶
newjob(jobspec,parent_id=None,child_ids=[])
→ list
of int
Submit a job to the server. ‹jobspec› can be either a JSON string, a dictionary or a list of dictionaries representing the job specification(s). See The Job Specification for details on job specifications.
The optional argument ‹parent_id› is an id for the job that the new job should be parented to.
The optional argument ‹child_ids› is a list of ids for existing jobs that should be parented to the new job.
Returns a list of ids for the new jobs.
getUnfinishedRootJobIds()
→ list
of int
Returns a list of job ids for all unfinished root jobs. Root jobs have no parent.
getFinishedRootJobIds()
→ list
of int
Returns a list of job ids for all finished root jobs. Root jobs are jobs that have no parent.
pauseJobs(job_ids)
Pauses all the jobs linked to each job in the list of job_ids.
This function is asynchronous and returns immediately.
resumeJobs(job_ids)
Resumes all the jobs linked to each job in the list of job_ids.
This function is asynchronous and returns immediately.
rescheduleJobs(job_ids)
Reschedules all the jobs linked to each job in the list of job_ids.
This function is asynchronous and returns immediately.
cancelJobs(job_ids)
Cancels all the jobs linked to each job in the list of job_ids.
This function is asynchronous and returns immediately.
deleteJobs(job_ids)
Deletes all the jobs linked to each job in the list of job_ids.
This function is asynchronous and returns immediately.
ejectJobs(job_ids)
Ejects all the jobs linked to each job in the list of job_ids.
This function is asynchronous and returns immediately.
Job queries ¶
getJobs(job_ids, attribs=None)
→ list
of dict
Returns a list of dictionaries where each dictionary contains the attributes for a job specified in ‹job_ids›.
‹job_ids› must be a list of job id numbers.
You can optionally set the ‹attribs› argument to a list of job attributes that is returned. This can help reduce the function’s execution time and the amount of data returned.
Here is a list of job attributes:
-
children
- list of child job ids -
clients
- list of clients executing or have executed the job -
clientsOnHold
- list of clients on hold (or reserved) for the job. Clients can be held for a job if the job requires multiple clients to execute but only some clients are available now. Once the job has enough clients on-hold, those clients are assigned to the job. -
conditions
- list of scheduling conditions imposed on the job -
endTime
- time when the job ended. The time is in UTC. Is set toNone
if the job has not finished. -
ETA
- estimated number of seconds before the job is finished. Is set to -1 if the ETA cannot be determined. Note that calculation of this attribute requires HQueue to query the job and all of its descendants which can significantly slow down the performance ofgetJobs
. -
id
- job id -
latestNote
- the text of the latest note for the thread associated with the job. An empty string is returned if there is no such thread. -
logs
- list of entries for the job’s status change log -
name
- job name -
overallProgress
- overall progress percentage (between 0.0 and 1.0) of the job and its descendants. Note that calculation of this attribute requires HQueue to query the job and all of its descendants which can significantly slow down the performance ofgetJobs
. -
parents
- list of parent job ids -
priority
- job priority -
progress
- progress percentage (between 0.0 and 1.0) of the job command. If the job has no command to execute, then the progress will always be set to 0.0. -
queueTime
- time when the job was submitted, or queued, in HQueue. The time is in UTC. -
resources
- dictionary of the resources a job requires. Each key is a resource name and value is the amount of the respective resource the job requires.None
is returned if the job does not require any resources. See Resources for more information on job resources. -
showBlockedClientsWarning
- a boolean flag indicating whether a warning icon will be displayed in the status column of the Running Jobs table on the Jobs page for the job. Clicking on the icon will show a dialog with information about the job’s blocked clients. -
startTime
- time when the job or one of its descedents started. The time is in UTC. -
status
- internal job status. HQueue queries only the job itself (and not its descendants) so requesting this attribute is extremely fast. If you are interested only in whether a job is finished or not, then request for this attribute instead of uiStatus. Possible values of this attribute are abandoned, canceled, failed, paused, pausing, resuming, running, succeeded, runnable and queued. runnable is the equivalent of the waiting for machine UI status. queued indicates that the job is waiting for descedent jobs to finish before it can run. -
tags
- list of tags, or custom properties, attached to the job. Of note, the single tag indicates that the job can only run on a machine with no other jobs. -
threadId
- the id of the thread associated with the job.None
is returned if there is no such thread. -
triesLeft
- the number of times the job will attempt to run after a failure. For example, if a job has atriesLeft
of 2 and it fails after running, it will automatically be rescheduled and queued, and itstriesLeft
will be decremented and set to 1. -
uiStatus
- job status which appears in the HQueue web interface. A list of the possible UI job statuses is listed at Job Statuses. Note that this attribute requires HQueue to query the job and all of its descendants which can significantly slow down the performance ofgetJobs
. -
waitingFor
- the reason why the job is waiting if available. An empty string is returned if the job is not waiting or if the reason is not available.
getJob(job_id, attribs=None)
→ dict
Convenience function for getJobs(). Return a dictionary of attributes for the specified job.
getJobHistory(client_id, limit=5)
→ list
of int
Returns a list of ids for jobs that recently ran on the specified client. The ids are ordered by job end times with the first item in the list representing the id for the job that last finished on the client. You can optionally specify the ‹limit› argument to cap the maximum number of ids returned.
getJobOutput(job_id, max_last_chars=None)
→ str
Returns the output log for the given job. Returns at most the last ‹max_last_chars› characters of the log. If ‹max_last_chars› is less than one or is not specified, returns the entire output log.
getJobIdsAssignedToClient(client_id)
→ list
of int
Returns a list of ids for jobs assigned to the specified client. Returns an empty list if the client does not exist.
getJobIdsByStatus(statuses)
→ list
of int
Returns a list of ids for jobs with a status found in the given list of statuses.
Valid status names are:
-
abandoned
-
cancelled
-
failed
-
paused
-
pausing
-
queued
-
resuming
-
running
-
runnable
-
succeeded
-
waiting
Meta ¶
getNetworkFolders()
→ list
of dict
Returns the list of registered network folders. Each network folder in the list is represented as a dictionary of string keys to string values.
Here are the keys in the network folder dictionary:
-
name
- The name of the network folder. The name is used for the variable in the job environment representing the network folder path. -
linuxMount
- The mount point path of the network folder on Linux machines. -
macOSMount
- The mount point path of the network folder on macOS machines. -
windowsMount
- The mount point path of the network folder on Windows machines. -
linuxHostPath
(deprecated, for backwards compatibility only) - The host server and path of the network folder. This key was used when requesting HQueue to create mount points on Linux machines. -
macOSHostPath
(deprecated, for backwards compatibility only) - The host server and path of the network folder. This key was used when requesting HQueue to create mount points on macOS machines. -
windowsHostPath
(deprecated, for backwards compatibility only) - The host server and path of the network folder. This key was used when requesting HQueue to create mount points on Windows machines.
getAllJobStatusNames()
→ list
of str
Returns a list of all the possible job statuses.
getRunningJobStatusNames()
→ list
of str
Returns a list containing the statuses that denote a running job.
getPausedJobStatusNames()
→ list
of str
Returns a list containing the statuses that denote a paused job.
getFinishedJobStatusNames()
→ list
of str
Returns a list statuses that denote a finished job.
getSucceededStatusNames()
→ list
of str
Returns a list containing the names of a succeeded job status.
getWaitingJobStatusNames()
→ list
of str
Returns a list containing the statuses that denote a waiting job.
getFailedJobStatusNames()
→ list
of str
Returns a list of statuses that denote a failed job.
getUnfinishedJobStatusNames()
→ list
of str
Returns a list containing the statuses that denote an unfinished job.
getPriorityChangedEventNames()
→ list
of str
Returns a list containing the names of the priority change events.
getStartedJobEventNames()
→ list
of str
Returns a list containing the names of a start job event.
getRescheduledEventNames()
→ list
of str
Returns a list containing the names of the reschedule events.
getResumedEventNames()
→ list
of str
Returns a list containing the names of the resume events.
Resources ¶
See resources for more information.
getResources(resource_ids=None)
→ list
of dict
Returns a list of dictionaries where each dictionary represents a resource. If no argument is passed in, it returns a list of all resources.
Configuration ¶
getConfig(key)
→ str
or None
Returns the configuration value for the given key or None
if the key does not exist in the configuration file.
getPermittedClientsList(job_id)
→ list
of str
Returns a list of the clients permitted to run the specified job. The clients are specified by hostname if there is no name set for the client, otherwise they are in the hostname:name
format where hostname
is the client’s hostname, and name
is the client’s name.
savePermittedClientsList(job_id, clients_list)
Save the new list of permitted clients to the job with the provided job id and create the appropriate conditions such that only the specified clients are permitted to run this job. Any previously existing conditions will be replaced.
Clients in the ‹clients_list› can be specified in one of the following formats:
-
'hostname' → allow any client with the hostname 'hostname' to run this job.
-
'hostname:name' → only allow the client with the hostname 'hostname' and name 'name' to run this job.
-
'hostname:' → only allow the client with the hostname 'hostname' and an empty (“”) name to run this job.
setdisabled(clientname, disabled)
→ bool
Disables or enables the given client machine depending on the value of ‹disabled›. ‹disabled› must be either True
or False
.
‹clientname› can be in the hostname
format to specify a client by hostname
or the hostname:name
format to refer to a client with the specified hostname
and name
.
By default, clients have an empty (""
) name.
Returns True
if the method succeeds. Return None
otherwise.
setShowBlockedClientsWarning(job_id, state)
Sets the value of the specified job’s showBlockedClientsWarning
attribute. Set ‹state› to True
to have a warning icon be displayed in the status column of the Running Jobs table on the Jobs page corresponding to the specified job. Otherwise, set ‹state› to False
to hide the warning icon. Clicking on the icon will display a dialog with information about the job’s blocked clients as well as the option to view the job’s permitted clients list.
Notes ¶
See how to use notes for more information.
getNoteThreads(thread_ids=None,thread_attribs=None,note_attribs=None)
→ list
of dict
Returns a list of dictionaries where each dictionary contains the attributes for a thread specified in ‹thread_ids›.
If ‹thread_ids› is None
then dictionaries for all threads are returned.
The ‹thread_attribs› may be set to a list of thread attributes that will be returned. If the notes attribute is to be returned, then ‹note_attribs› may be set to a list of note attributes that will be returned. These arguments can help reduce the execution time of the function and the amount of data returned.
Here is a list of thread attributes:
-
clientHostname
- The hostname of the client associated with the thread. -
clientId
- The id of the client associated with the thread. -
clientLabel
- The display label of the client associated with the thread. If no name is set for the client, this is the same asclientHostname
, otherwise this ishostname:name
wherehostname
is the client’s hostname, andname
is the client’s name. -
id
- The note thread’s id. -
jobId
- The id of the job associated with the thread. -
notes
- The notes that belong to the threads.
Here is a list of note attributes:
-
clientHostname
- The hostname of the client associated with the thread. -
clientId
- The id of the client associated with the thread. -
clientLabel
- The display label of the client associated with the thread. If no name is set for the client, this is the same asclientHostname
, otherwise this ishostname:name
wherehostname
is the client’s hostname, andname
is the client’s name. -
date
- The date and time that the note was last added. -
id
- The note’s id. -
jobId
- The id of the job associated with the thread. -
text
- The contents of the note. -
threadId
- The id of the note’s parent thread.
getNoteThreadIds()
→ list
of int
Returns a list of ids for all threads.
threadExists(thread_id)
→ bool
or None
Returns a boolean representing whether a thread with the given id exists or not.
Returns None
if an error occurs when executing this method.
removeSingleThread(thread_id)
→ bool
Removes the thread with the specified id and all of the notes belonging to that thread.
Returns True
if successful. Return False
otherwise.
removeThreads(thread_ids)
→ list
of int
Removes the threads with the specified ids and all of the notes belonging to those threads.
Returns a list of ids for threads that could not be deleted.
getLatestNotes(thread_ids=None, attribs=None)
→ list
of dict
Returns a list of dictionaries where each dictionary contains the attributes for the latest note of a thread specified in ‹thread_ids›.
‹thread_ids› must be a list of thread id numbers or None
. If it is None
then the latest notes for all jobs are returned.
You can optionally set the ‹attribs› argument to a list of note attributes that will be returned. This can help reduce the execution time of the function and also reduce the amount of data returned.
Here is a list of note attributes:
-
clientHostname
- The hostname of the client associated with the thread. -
clientId
- The id of the client associated with the thread. -
clientLabel
- The display label of the client associated with the thread. If no name is set for the client, this is the same asclientHostname
, otherwise this ishostname:name
wherehostname
is the client’s hostname, andname
is the client’s name. -
date
- The date and time that the note was last added. -
id
- The note’s id. -
jobId
- The id of the job associated with the thread. -
text
- The contents of the note. -
threadId
- The id of the note’s parent thread.
addNote(note_text, thread_id, job_id, client_id)
→ bool
Adds a note to an existing message thread or to a new thread.
If ‹client_id› is not None
, the note is added to the message thread associated to the specified client.
If ‹job_id› is not None
, the note is added to the message thread associated to the specified job.
If ‹thread_id› is not None
, the note is added to the specified message thread.
Create a new message thread if ‹client_id›, ‹job_id› and ‹thread_id› are None
, or if no existing message thread could be found for those arguments.
If more than one of ‹client_id›, ‹job_id› and ‹thread_id› are specified and not None
, then RPC fault is returned and the note is not added.
removeNotes(note_ids)
→ list
of int
Removes the notes with the specified ids from the server. When deleting many notes, put the id of the first note in the thread at the end of ‹note_ids›.
Returns a list of ids for notes that could not be deleted.
removeSingleNote(note_id)
→ bool
Removes the note with the specified id from the server.
Returns True
if successful, or False
otherwise.
Deprecated functions ¶
getClientsByHostname(hostnames, attribs=None)
→ list
of dict
Deprecated Use getClientsByName() instead.
getClientByHostname(hostname, attribs=None)
→ dict
Deprecated Use getClientByName() instead.
getHQRoot(platform, is_client=True)
→ str
or None
Returns the value of the $HQROOT
environment variable as it appears on a machine of the given platform. ‹platform› must be either “linux”, “windows” or “macos”. The use of “macosx” for the ‹platform› is deprecated.
Returns None
if ‹platform› is not one of those values. Returns the UNC path if ‹platform› is “windows” and ‹is_client› is True.
getEnvRoot(platform, name, is_client=True)
→ str
or None
Returns the value of the $‹name› environment variable as it appears on a machine of the given platform. ‹name› must be a valid environment variable defined in the Network Folders page. ‹platform› must be either “linux”, “windows” or “macos”. The use of “macosx” for the ‹platform› is deprecated.
Returns None
if ‹platform› is not one of those values. Returns the UNC path if ‹platform› is “windows” and ‹is_client› is True.