Example batch process for a background task

The following Gosu code is an example of a custom batch process that operates as a background task instead of one that operates on a batch of units of work. Its process history does not does not track the number of items that processed successfully or that failed, because it has no formal units of work.

The following Gosu batch process purges old workflows. It takes one parameter that indicates the number of days for successful processes. Pass this parameter in the constructor to this batch process class. In other words, your implementation of IProcessesPlugin must pass this parameter such as the new MyClass(myParameter) when it instantiates the batch process. If the parameter is missing or null, it uses a default system setting.

Notice also that the second constructor uses the TC_PURGEWORKFLOWS typecode on the BatchProcessType typelist. If this typecode does not exist, you must create it.

package gw.processes

uses gw.processes.BatchProcessBase
uses java.lang.Integer
uses gw.api.system.PLConfigParameters
uses gw.api.admin.WorkflowUtil

class PurgeWorkflows extends BatchProcessBase {
  var _succDays = PLConfigParameters.WorkflowPurgeDaysOld.Value

   construct() {
    this(null)
  }
  
  construct(arguments : Object[]) {
    super(typekey.BatchProcessType.TC_PURGEWORKFLOWS)
    if (arguments != null) {
      _succDays = arguments[0] != null ? (arguments[0] as Integer) : _succDays
    }
  }

  override function doWork() : void {
    WorkflowUtil.deleteOldWorkflowsFromDatabase( _succDays )
  }

}
Important: You must use the runWithNewBundle API if want to modify entity data in your custom batch process.

See also