Basic Ruby Script examples and their usage

This section presents some basic Worker Side Scripts in Ruby that you need to include in your Worker Side Script to avoid warnings in your logs. These scripts show you how to:

Callback a worker item

Perform setup operations

Perform a rollback

Close a callback worker item

The Java class must be accessible in the engine lib directory for all participating workers. A new instance is created by each Worker and invoked for each item processed.

If the Java class implements autoCloseable, this is invoked when processing completes.

For scripting languages:

If a top-level function called nuixWorkerItemCallbackInit exists, it is called when processing starts.

If a top-level function called nuixWorkerItemCallbackClose exists, it is called once processing ends.

For each item processed by the Worker, a function called nuixWorkerItemCallback must be present so that it can be called with a single argument, which is the current workerItem being processed.

When Nuix Worker servers (Workers) invoke your callback, they provide a workerItem instance which contains information about the item the Worker is about to process. From the WorkerItem, you can get additional information from the associated sourceItem by calling workerItem.getSourceItem().

Callback a worker item

Define the nuixWorkerItemCallback method in your Worker Side Script to apply the logic to each WorkerItem as it is processed, per the following example:

#Define our worker item callback

def nuixWorkerItemCallback(workerItem) #Do interesting things here

end

Perform setup operations

Define the nuixWorkerItemCallbackInit method to call when the Worker is initialized to perform setup operations, if needed, per the following example:

#Define our initialization callback def nuixWorkerItemCallbackInit

#Perform some setup here

end

#Define our worker item callback

def nuixWorkerItemCallback(workerItem) #Do interesting things here

end

Perform a roll back

Define the nuixWorkerItemCallbackCheckpoint method to perform a roll back action, if needed, per the following example:

#Define our file retry

def nuixWorkerItemCallbackCheckpoint() #perform an action to rollback a retry

end

This method, in effect, is a notification which indicates that all worker items processed by this Worker since the last nuixWorkerItemCallbackCheckpoint call are now committed to the Nuix database. This may allow custom code in the Worker Side Script to commit various artifacts. If a Worker is killed or restarted, then any outstanding worker items since the last nuixWorkerItemCallbackCheckpoint call will potentially be redelivered to other Workers for reprocessing, since they represent uncommitted work.

Close a worker callback item

Define the nuixWorkerItemCallbackClose method to close a worker callback item, when the Worker completes processing, per the following example:

#Define our initialization callback def nuixWorkerItemCallbackInit

#Perform some setup here

end

#Define our worker item callback

def nuixWorkerItemCallback(workerItem)

#Do interesting things here

end

#Define our closing callback def nuixWorkerItemCallbackClose

#Perform cleanup here

end