Setting history TTL different for every process and spring boot profile

I want to have something like:

  • “dev” profile:
    • Process A - TTL 1 day
    • Process B - TTL 5 days
  • “prod” profile:
    • Process A - TTL 0 days
    • Process B - TTL 30 days

If I were to use the process engine API like processEngine.getRepositoryService().updateProcessDefinitionHistoryTimeToLive(processDefinitionId, 5);. How should I implement it so that my application isn’t processing transactions before I’ve updated the TTL?

If I use the REST API, when should I be setting the TTL? do I only need to do it one time per process and profile? what happens if I update the process and do a deployment, would the existing TTL that I set using the API be overwritten by whatever default TTL I had set in the bpmn file?

Hi @crimson589.

My first idea is to write a process engine plugin that overwrites the TTL and is only activated for a specific spring profile.
That way you could really define the TTL in the process definition to be the one used in production.

I got it working somehow using the code below but I have a problem when a deployment happens and there’s a new version of the process. .latestVersion() still retrieves the version before and is setting the ttl for that so what happens is the new version deployed still has the default ttl of what I set on the camunda bpmn file.

I tried to look at what I get using the processDefinitionQuery and it doesn’t seem to include the version that is about to be deployed, or for example a new deployment with an empty database, processDefinitionQuery doesn’t return any results, what am I doing wrong here?

@Override
public void postInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
    List<ProcessDefinition> processDefinitionList = processEngineConfiguration.getRepositoryService().createProcessDefinitionQuery().latestVersion().list();
    processDefinitionList.forEach(processDefinition -> {
        processEngineConfiguration.getRepositoryService().updateProcessDefinitionHistoryTimeToLive(processDefinition.getId(), ttl);
    });
}

Sorry I didn’t explain thoroughly enough what I meant.
In the plugin implement the preInit method and add a custom post deployer to the process engine configuration.
This deployer can then iterate through all deployed process definitions and change the TTL of it.

public class TimeToLiveDeployer implements Deployer {

    @Override
    public void deploy(final DeploymentEntity deployment) {
        deployment.getDeployedProcessDefinitions()
            .forEach(definition -> definition.setHistoryTimeToLive(...);
    }

}

Am I missing something? there doesn’t seem to be a setHistoryTimeToLive here or any set methods at all.

Forgot that you have to cast the class.
Here is an example for the plugin:

public class TimeToLivePlugin extends AbstractProcessEnginePlugin {

    @Override
    public void preInit(final ProcessEngineConfigurationImpl processEngineConfiguration) {
        processEngineConfiguration.setCustomPostDeployers(Collections.singletonList(
                deployment -> deployment.getDeployedProcessDefinitions()
                        .stream()
                        .map(ResourceDefinitionEntity.class::cast)
                        .forEach(definition -> definition.setHistoryTimeToLive(30)
                )
        ));
    }

}
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.