Skip to main content

Version: 19.05 (EOL)

Job Action

The Job Action service is used to provide a custom Job step action service for job processing. This could be used to perform custom processing such as calling an external system.

Service Invoke Parameters

Parameters are not nullable except where otherwise indicated.

ParameterDescription
svcDefSvcDef
A service definition value object.
jobJob
A transaction record value object.
jobActionJobAction
A transaction record value object.
actionPropertiesMap
A job definition action properties map (since Journey Manager 18.05).
requestHttpServletRequest
A HTTP servlet request.
userUser
Nullable. An authenticated user.

Error Handling

Job action processing is generally performed asynchronously by a background job. If an error occurs with asynchronous processing, the end user never sees this error. If an exception is thrown by the Job Action service, the Job Controller service logs the error in the Journey Manager database error log.

If the Job is configured to process submissions immediately ("processSubmitImmediate": "true"), the job action may be processed in the user thread depending upon the job definition. If a job action executing in the user thread throws an exception then the submission transaction is rolled back, and a generalized transaction error is logged in the Journey Manager database error log.

info

The normal job error logging to the database will not be available as the entire submission transaction has been rolled back. To determine the root cause of an error, review the server log file.

It is important that any custom action running in the user thread handles errors gracefully and does not throw an exception. The action should also execute quickly so the user experience is not degraded and the systems performance is not impacted under heavy loads.

Depending upon the service's configuration, the Job Controller service may automatically attempt to retry the action service several times if the action fails.

Templates

Service

import com.avoka.core.groovy.GroovyLogger as logger
import com.avoka.tm.job.*
import com.avoka.tm.util.*
import com.avoka.tm.vo.*
import java.util.*
import javax.servlet.http.*

class FluentJobActionService {

/*
* Perform a job action service invocation
*
* return: the job action result
*/
ActionResult invoke(SvcDef svcDef, Job job, JobAction jobAction, Map actionProperties, HttpServletRequest request, User user) {

// TODO: perform your logic

String xml = Jobs.getStartTxnXml(job)

Path path = new Path(xml)

String email = path.val('//Contact/Email')

return new ActionResultBuilder()
.setStatus('Completed')
.setMessage('Action completed for: ' + email)
.build()
}
}

Unit Test

import com.avoka.core.groovy.GroovyLogger as logger
import com.avoka.tm.job.*
import com.avoka.tm.svc.*
import com.avoka.tm.test.*
import com.avoka.tm.util.*
import com.avoka.tm.vo.*
import org.junit.Test

class UnitTest extends AbstractJUnitTest {

/*
* Perform service unit test
*
* throws exception if unit test fails
*/
@Test
void testActionCompleted() throws Exception {

String formXml = testParams['Test XML Data']
Job job = new MockVoBuilder().createJobInProgressWithXml(formXml)
JobAction jobAction = job.jobSteps[0].jobActions[0]
Map actionProperties = new HashMap()
MockRequest request = new MockRequest()

Map params = [
"svcDef": svcDef,
"job": job,
"jobAction": jobAction,
"actionProperties": actionProperties,
"request": request,
"user": null
]

ActionResult result = (ActionResult) new ServiceInvoker(svcDef).invoke(params)

logger.info 'result: ' + result

assert result != null

assert result.message == 'Action completed for: [email protected]'
}
}