Calls using the Flex SDK within scripts are not transactional. This is unlike the legacy scripting approach, but is unavoidable now that Flex is a distributed microservices-based system. This means that is the responsibility of the script developer to anticipate failures and to perform any clear up operations in case of failure.
Example
The JEF Script action example below creates new media asset of variant v1, the variant having a default media asset metadata definition that does not have a field named field-that-does-not-exist.
def execute() {
def assetService = flexSdkClient.getAssetService()
def assetPlaceholder = NewAssetPlaceholder.builder()
.type('media-asset')
.name('demo asset')
.variant('v1')
.build()
def asset = assetService.createAsset(assetPlaceholder)
def metadata = assetService.getAssetMetadata(asset.getId())
def field = metadata.getField('field-that-does-not-exist')
}
If a job of this type is executed, it will fail (with a tv.nativ.mio.commons.MioException: FlexSdkException: No field exists with name: string-fiedld error), but the new demo asset media asset will exist. This is different to the legacy scripting framework whereby the exception thrown when trying to retrieve the non-existing field would cause a transaction rollback (and hence the asset would be removed from the underlying database).
In the updated example below, the script now catches any exceptions and destroys the created asset:
def execute() {
def assetService = flexSdkClient.getAssetService()
def assetPlaceholder = NewAssetPlaceholder.builder()
.type('media-asset')
.name('demo asset')
.variant('v1')
.build()
def asset = assetService.createAsset(assetPlaceholder)
try {
def metadata = assetService.getAssetMetadata(asset.getId())
def field = metadata.getField('string-field').setValue('qwerty')
assetService.setAssetMetadata(asset, metadata)
} catch (Exception e) {
assetService.destroy(asset.id)
throw e
}
}
Note that the exception is re-thrown in order to ensure that the job fails. The choice of what and how to rollback is up to the script developer. If no manual rollbacks are performed, please be aware that the system maybe left in a logically inconsistent state.
Comments
0 comments
Please sign in to leave a comment.