User Tasks
User Tasks allow you to manage tasks involving humans alongside standard computer tasks in your LittleHorse Workflow.
You can use the Workflow SDK's to schedule User Tasks, and also create lifecycle hooks such as:
- Automatic Reassignment
- Reminder Tasks
- Automatic Cancellation.
See the Metadata Management docs for information about how to create a UserTaskDef
.
Assigning User Tasks
You can assign a User Task in two ways:
- To a specific User, specified by an arbitrary user id (and optionally a user group).
- To a group of users.
Assigning to Users
To assign a user task to a specific user who is not a part of a group, you can use WorkflowThread#assignTaskToUser()
.
- Java
- Go
- Python
String hardCodedUserId = "some-user-id-or-email";
WfRunVariable userIdVariable = wf.addVariable("user-id", VariableType.STR);
// Hard-coded using a string
wf.assignUserTask("some-user-task-def", hardCodedUserId, null);
// Using a variable to set User Id
wf.assignUserTask("another-user-task-def", userIdVariable, null);
hardCodedUserId := "some-user-id-or-email"
userIdVariable := wf.AddVariable("user-id", lhproto.VariableType_STR)
// Hard-coded using a string
wf.AssignUserTask("some-user-task-def", &hardCodedUserId, nil)
// Using a variable to set User Id
wf.AssignUserTask("some-user-task-def", userIdVariable, nil)
hard_coded_user_id = "some-user-id-or-email"
user_id_variable = wf.add_variable("user-id", VariableType.STR)
# assign using a hard coded string
wf.assign_user_task("some-user-task", user_id=hard_coded_user_id)
# assign using a variable
wf.assign_user_task("some-user-task", user_id=user_id_variable)
You can also assign a user task to a user as part of a group using WorkflowThread#assignUserTask
:
- Java
- Go
WfRunVariable userIdVariable = wf.addVariable("user-id", VariableType.STR);
WfRunVariable userGroupVariable = wf.addVariable("user-group", VariableType.STR);
String hardCodedUserGroup = "finance";
// Hard-coded using a string
wf.asignUserTask("some-user-task-def", userIdVariable, hardCodedUserGroup);
// Using a variable to set User Group
wf.assignUserTask("another-user-task-def", userIdVariable, userGroupVariable);
Golang user task docs coming soon. But if you want, you can try it out anyways 😉.
Assigning to Groups
You can assign a task to a user group using WorkflowThread#assignUserTask()
.
- Java
- Go
String hardCodedUserGroup = "sales";
WfRunVariable userGroupVariable = wf.addVariable("user-group", VariableType.STR);
// Hard-coded using a string
String userId = null;
wf.assignUserTask("some-user-task-def", userId, hardCodedUserGroup);
// Using a variable to set User Group
wf.assignUserTask("another-user-task-def", userId, userGroupVariable);
GoLang docs for user tasks coming soon. But if you want, you can try it out anyways 😉.
Using User Task Outputs
The assignTaskToUser
and assignTaskToUserGroup
methods return a UserTaskOutput
, which is a special type of NodeOutput
. It can be used to:
- Mutate variables
- Schedule reminder tasks
- Schedule user task reassignment.
Using the Form Output
You can use a UserTaskOutput
to mutate variables. Note that a UserTaskDef
has a series of fields, where each field has a name
and value
(which is a VariableValue
containing a primitive type).
The UserTaskOutput
is essentially a Json output where each key is the name of each field, and the value is the value typed by the user. Let's say I have a user task def with two fields:
userName
, which is aSTR
age
, which is anINT
You can use the value as follows:
- Java
- Go
WfRunVariable age = wf.addVariable("age", VariableType.INT);
WfRunavariable userName = wf.addVariable("user-name", VariableType.STR);
UserTaskOutput formResults = wf.assignUserTask("my-user-task", "obi-wan", null);
wf.mutate(age, VariableMutationType.ASSIGN, formResults.jsonPath("$.age"));
wf.mutate(userName, VariableMutationType.ASSIGN, formResults.jsonPath("$.userName"));
GoLang docs for user tasks coming soon. But if you want, you can try it out anyways 😉.
Reminder Tasks
You can use the UserTaskOutput
to schedule a "Reminder Task", which is a TaskRun
that runs a set period of time after the User Task is scheduled. If the UserTaskRun
has been completed, cancelled, or reassigned by the time the Reminder Task is scheduled, the Reminder Task does not execute.
- Java
- Go
UserTaskOutput userTask = wf.assignTaskToUser("some-task", "yoda");
int delaySeconds = 60; // wait one minute before reminder
String taskArg1 = "reply to my email, you must!";
String taskArg2 = "for my ally is the Force, and a powerful ally it is";
String taskDefName = "send-reminder";
wf.scheduleTaskAfter(userTask, delaySeconds, taskDefName, taskArg1, taskArg2);
GoLang support for user tasks coming soon.
Automatic Reassignment
You can use the UserTaskOutput
to automatically "release" a task from a specific user to that user's group after a period of time passes.
This only works if you assign the user task to a user and specify the group the user belongs to.
- Java
- Go
String userGroup = "jedi-council";
UserTaskOutput userTask = wf.assignUsrTask("some-task", "Mace Windu", userGroup);
// If Mace Windu doesn't respond in 1 hour, allow any other Jedi Council member to claim
// the task.
wf.releaseToGroupOnDeadline(userTask, 60 * 60);
GoLang support for user tasks coming soon. But if you want, you can try it out anyways 😉.