Run Human Task in Automation Process
Run Human Task in Automation Process
An EasyRpa Automation Process can be easily extended to include a Human Interaction step by using pre-defined eu.ibagroup.easyrpa.engine.task.ht.HumanTask class from 'easy-rpa-engine-ht' artefact.
You're in charge of controlling thread pool size
As the Automation Process isn't finished after you create Human Task, it waits for results to continue processing. It means that Java Thread is used at that time.
You should always develop your automation process keeping in mind that you can have some active (uncompleted) Human Tasks in parallel, so you should predict the possible amount of uncompleted Human Tasks.
If all threads from thread pool are in use - Automation Process won't be able to continue working with the different steps, because all threads are occupied by Human Tasks.
There're 3 Automation Process parameters you can control:
remoteExecutionService.poolSize - the number of threads to use for in automation process execution service for task processing. i.e. the number of task tat could be running in parallel at the same time.
- remoteExecutionService.batchSize - the number of threads to use for split tasks in execution service, i.e. the number of flow that could be running in parallel at the same time.
remoteExecutionService.taskTimeout - task timeout in minutes. If task is running more that it specified here, the automation process that injects the task will be moved into STOPPED_IDLE status till the task completes.
You can find the default values on page Administration → CS Configuration:
Prerequisites
Before running any HumanTask the following prerequisites should be defined/existing:
- Automation Process pom.xml includes following dependency
<dependency> <groupId>eu.ibagroup</groupId> <artifactId>easy-rpa-engine-ht</artifactId> </dependency>
- Pre-defined Human Task Type uploaded or custom Human Task Type created in CS
- A Document Type created to refer the Human Task Type from previous step
Prepare input data
Before launching Human Task you must prepare an object of eu.ibagroup.easyrpa.engine.task.ht.HumanTaskData:
- inputJson to be set to Map of the required by the involved Human Task json structure with input data. Input data can be a text to be classified,
or message to be overridden like in the example below
- outputJson to be set to Map of the required by the involved HumanTask json structure with output data. In the UI provided data will be rendered to pre-populated values in the input fields.
- mandatory documentType to be set to the name of the document type defined for the process
- mandatory name string to provide meaningful name for the interaction
- optional description string to provide detailed context of the work to be done
- optional priority integer to specify how important is the task
and provide this object as output from your own Task class with the key eu.ibagroup.easyrpa.engine.task.ht.HumanTask.HUMAN_TASK_DATA_KEY.
As an example, let's look at the PrepareInputApTask java class below. It is a simple ApTask which creates and provides HumanTaskData as an output.
@ApTaskEntry(name = "Prepare Human Task Input") @Slf4j public class PrepareInputApTask extends ApTask { @Output(HumanTask.HUMAN_TASK_DATA_KEY) private HumanTaskData humanTaskData; @Override public void execute(){ this.humanTaskData = new HumanTaskData(); this.humanTaskData.setInputJson(new HashMap<>()); this.humanTaskData.setDescription("Human Task Example"); this.humanTaskData.setDocumentType("example"); this.humanTaskData.setName("Human Task"); this.humanTaskData.setPriority(1); log.info("Injecting task into workspace {} ", humanTaskData); } }
Execute Human Task
Now let's look how to set input and execute HumanTask from your ApModule class.
public TaskOutput run() throws Exception { return execute(getInput(), PrepareInputApTask.class) .thenCompose(execute(HumanTask.class)) .thenCompose(execute(ProcessHumanTaskResultsTask.class)).get(); }
Work with Human Task results
When Human Task will be completed you may need to handle output results. They will be provided in input as HumanTaskData object with the same HUMAN_TASK_DATA_KEY key.
Bellow an example how to obtain and work with Human Task results.
@ApTaskEntry(name = "Working with Human Task results.") @Slf4j @InputToOutput public class ProcessHumanTaskResultsTask extends ApTask { @Input(HumanTask.HUMAN_TASK_DATA_KEY) private HumanTaskData humanTaskData; @Override public void execute() throws Exception { log.info("Received response from Human Task {} ", humanTaskData.getTaskUuid()); Map outputJson = humanTaskData.getOutputJson(); //work with output.. } }
Advanced Examples
For further reading please use Human Task Sample (HT Sample) sample - it provide set of in-depth examples how to run different Human Task type in Automation Processes.
Running Human Task in a Document Processor AP
Human Task plays important part in Document Processors - it is used for collecting training and re-training data for ML models. There is no need to explicitly run a Human Task within a Document Processor AP - it is already incorporated into the default flow.