Creation and execution of a Jobs Queue.

Last Change :
02.06.2025, 16:35 Uhr

Creation and execution of a Jobs Queue.If you want to process many documents in one action, you will know the problem: InDesign® only closes documents completely at the very end of the entire action in the so-called Idle Time. Until then, the documents remain in the working memory and you only need to have enough or large enough documents to cause InDesign® to crash due to memory overflow.

The Jobs Queue solves this problem by only starting the individual orders of the overall action at idle time. are only started at idle time. Once the individual job has been completed, the queue waits until InDesign® has also closed the document for the job in the background. in the background. Only then is the next job processed, again at idle time.

All you have to do is inform the queue of the document being processed (so that the queue knows whether it has to wait at all and for what). To do this, enter the following instruction in the job queue script after opening the document:

jobs::register_doc (document::get_front (1));

The following table describes the behavior of the queue in different situations:

Document With registration Without registration
Opening and closing Processing waits until the document is also closed in the background. Only then is the next job processed. The next job is started immediately after the end of the current job and the document remains open in the background until the next idle time. In short, you can skip the queue.
Open only Processing only continues once the document has been closed. This option is particularly useful for manually editing publication documents: The queue loads and opens the next document. Then you can edit the document manually. As the queue is patient, you have time to wait until the end of the world (if the conditions are favorable). However, if the document is saved and checked-in beforehand, the next document to be processed is loaded and opened immediately. The next job is started immediately after the end of the current job. Preferably use this option to open or chack out and open a list of documents.
No document open It is of course possible that a job does not open a specific document at all, but processes the current document (or even none at all). In this case, the job IDs could contain 'any' information, e.g. the URL of a file for download. IIn this case, the next job is started immediately after the end of the currentjob.

Once all jobs have been completed, processing of the queue is automatically deactivated and must be reactivated with jobs::start to process further jobs.

Jobs are added to the queue using the jobs::add function. The call defines the script (the Action) to execute the job. And so that this script 'knows' what it is supposed to do, the call also defines a so-called job ID, which can be evaluated by the script.

As a rule, the job ID contains either the (complete) path of an InDesign® document or the document ID of a publication document. However, you can also enter any other description here - the only thing that matters is how the executing script evaluates this description.

The job ID must be not unique within the queue.

Die Job-ID wird dem ausführenden Skript in der Variable s\pan[keyword]{gJobsQueueId} übergeben. Der Wert von gJobsQueueId darf nicht geändert werden! Die folgende Tabelle beschreibt einige typische Job-IDs:

Job-ID Beispiel
Dokumentpfad

Öffne, bearbeite und sichere das Dokument $DESKTOP/aaa.indd in einer Warteschlange:

document::open (gJobsQueueId);
jobs::register_doc (); // Our doc is the front document here
...
if (!document::can_save ()) document::saveas (0, "", kMinimalUI);
document::close ();
Document-ID

Öffne, bearbeite und sichere das Dokument mit der ID 268516810 in einer Warteschlange:

publication::checkout_by_id (gJobsQueueId, 2, 0, 0, 0, 1);	// suppress UI
jobs::register_doc (); // Our doc is the front document here
...
publication::checkin_by_id (gJobsQueueId);
URL

Lade die Datei der URL http://www.hi13.de/aaa.png auf meinen Schreibtisch:

file::download (gJobsQueueId, "$DESKTOP/abc.png);
Beliebig

aaa++bbb++ccc

int i;
  for (i = 0; i < string::get_token_count (gJobsQueueId, "++"); i++) {   showmessage (string::get_token (gJobsQueueId, "++", i); }
Beachten Sie bitte, dass erneute Aufrufe von string::get_token das Ergebnis des letzten Aufrufes überschreiben. Wenn Sie also mehrere Tokens in einem Aufruf verwenden wollen, müssen Sie deren Inhalte zuerst in lokale Variablen kopieren!

static int jobs::add(
  int jobsQueueID,
  int actionID = 0,
  char* actionPath = 0)

Add a job to the Jobs Queue. Processing of the jobs is started with jobs::start.

Name Type Default Description
Return int   0 or Error Code
jobsQueueID char* oder String - Description of the job. The information is passed to the executing script in the parameter gJobsQueueId and usually contains the ID or path of a document to be processed. However, you can also use any other name that you evaluate accordingly in the job script (the action).
actionID int 0 Id a defined action of the data connection to execute the job

≤ 0 : Use actionPath
actionPath char* or String 0 Complete path of the action for executing the job. The parameter is only used if actionID ≤ 0 is.

Create a processing job for each of five existing documents. After that, a new document should be created in a further job. At the end of the script, the queue processing of the jobs is started.

#pragma plain
int main () { int actionID = 0; char * actionPath = "$DESKTOP/bbb.cpp";
jobs::add ("$DESKTOP/aaa.indd", actionID, actionPath); jobs::add ("$DESKTOP/bbb.indd", actionID, actionPath); jobs::add ("$DESKTOP/ccc.indd", actionID, actionPath); jobs::add ("$DESKTOP/ddd.indd", actionID, actionPath); jobs::add ("create", actionID, actionPath);
wlog ("", "Jobs in queue : %d\n", jobs::count ());
jobs::start (); return 0; }

The example shows a simple script for a Jobs Queue job. It is important to open and close the target document and registering the document in the queue using the variable gOpenedDoc.

#include "internal/types.h"
int main () { ItemRef fr = item::alloc (); int result;
wlog ("", "# Working on '%s', %d docs are opened before\n",   gJobsQueueId,   document::count ());
// Open or create the document to apply // if (strcmp (gJobsQueueId, "create") == 0) document::create (); else document::open (gJobsQueueId);
// Register the document in the Jobs Queue // item::define (gOpenedDoc, document::get_front (), 1);
// Create a star // result = frame::create2 (   fr,   kStar,   0.0, 0.0, 110.0, 110.0,   1, // Page   "", // Layer name   1, // Number of columns   0, // Vertical columns?   0.0, // Gutter   5, 50); // Number and length of edges of the star
// Fill and rotate the star // frame::color_rgb (fr, 0, 153, 204); frame::rotate (fr, -20.0);
// If we have a new or converted document, ask for 'Save As'. // Otherwise save // if (!document::can_save ()) document::saveas (0, "", kMinimalUI); document::close ();
wlog ("", "# Working on '%s' done.\n", gJobsQueueId);
return 0; }

v5.0 R36580, 21. April 2025

priint:comet InDesign® Plug-Ins

start
document::open
publication::checkout_by_id

static int jobs::start()

Start processing the jobs in the Jobs Queue.

Once all jobs have been completed, the processing of the queue is automatically deactivated and must be reactivated with jobs::start to process further jobs.

v5.0 R36580, 21. April 2025

priint:comet InDesign® Plug-Ins

add
stop

static int jobs::active()

Is Jobs Queue processing activated?

Name Type Default Description
Return int   0 : No
1 : Yes

v5.0 R36580, 21. April 2025

priint:comet InDesign® Plug-Ins

add
start
stop

static int jobs::stop(int doClear = 0)

Stop processing the jobs in the queue.

Name Type Default Description
Return int   0 or Error Code
doClear int 0 Should all jobs that are still in the queue also be removed?

0 : No
1 : Yes

v5.0 R36580, 21. April 2025

priint:comet InDesign® Plug-Ins

add
start
clear

static int jobs::clear(int doStop = 0)

Remove all pending and unstarted jobs from the queue.

Name Type Default Description
Return int   0 or Error Code
doClear int 0 Should the processing of the queue also be deactivated?

0 : No
1 : Yes

v5.0 R36580, 21. April 2025

priint:comet InDesign® Plug-Ins

add
start
stop

static int jobs::count()

How many orders (jobs) are still in the queue?

Name Type Default Description
Return int   Number of orders still outstanding in the queue

v5.0 R36580, 21. April 2025

priint:comet InDesign® Plug-Ins

add
clear
get_nth

static int jobs::get_nth(
  int nth,
  IDType* data = 0,
  char* docId = 0)

Get the data of the nth order in the queue.

Name Type Default Description
Return int   0 or Error Code
nth int - 0-based index of the order in the queue
data IDType 0 Allocated IDType for the order data or 0, see add
jobsQueueID char* oder String 0 Allocated string/char* for the job identifier or 0, see add.

Is a job of the Jobs Queue currently being executed? If so, write the job ID in the log file.

int doc_job_running (char * docID)
{
    IDType	jobData	= idtype::alloc ();
    int 	result 	= 0;
if (jobs::get_nth (0, jobData, docID) == 0) { if (idtype::id2 (jobData) >= 0) result = 1 }
item::release (jobData);
return result; }
int main () { char docID [5000];
if (doc_job_running (docID)) { wlog ("", "Document Job running : '%s'\n", docID); }
return 0; }

v5.0 R36580, 21. April 2025

priint:comet InDesign® Plug-Ins

add
count
clear

static int jobs::register_doc(ItemRef docRef = 0)

Register the processing of a document by a queue script. If a Jobs Qqueue script has registered a document, the queue waits after the end of the script until the registered document has also been closed in the background by InDesign®.

Name Type Default Description
Return int   0 or Error Code

201 docNotFoundErr : Document not found or no document opened
3004 parameterValueErr : The script is not a Jobs Queue script.
docRef ItemRef 0 Valid document reference, e.g. via document::get_front

0 : Current front document

v5.0 R36670, 2. May 2025

priint:comet InDesign® Plug-Ins

add
start

Since
v5.0 R36580, 21. April 2025
Version
02.06.2025, 16:35 Uhr
Author
Paul Seidel

Alphabetic index HTML hierarchy of classes or Java