Problem with Java Api for history time to live (TTL)

need to set TTL using Java API.
I have special config, which use ProcessEnginePlugin and implement 3 hooks: preInit, postInit, postProcessEngineBuild.

And i am trying to config ProcessEngine bean from context. Set all batches and TTL’s.

        processEngineConfiguration.setCustomIncidentHandlers(customIncidentHandlers);
        processEngineConfiguration
        .setHistoryRemovalTimeStrategy(HISTORY_REMOVAL_TIME_STRATEGY_END)
        .setHistoryRemovalTimeProvider(new DefaultHistoryRemovalTimeProvider())
        .initHistoryRemovalTime();

processEngineConfiguration.setHistoryCleanupStrategy(HISTORY_CLEANUP_STRATEGY_REMOVAL_TIME_BASED);

processEngineConfiguration.setHistoryCleanupBatchSize(MAX_BATCH_SIZE);
processEngineConfiguration.setHistoryCleanupBatchWindowStartTime(null);
processEngineConfiguration.setHistoryCleanupDegreeOfParallelism(1);

processEngineConfiguration.setBatchOperationHistoryTimeToLive(null);
processEngineConfiguration.setBatchOperationsForHistoryCleanup(null);

processEngineConfiguration.setBatchOperationHistoryTimeToLive("3");

processEngineConfiguration.initHistoryCleanup();   

I found this code here. And there is also no method engineConfiguration.setHistoryTimeToLive(TTL).

Okay, definition compiles, but nothing happened.

And also trying to execute in hooks example:
processEngine.getRepositoryService().updateProcessDefinitionHistoryTimeToLive(processDefinitionId, TTL);

I cannot do this, because need processDefinitionId from runtime. And my plugin hooks don’t handle process events.

How can i configure TTL using Java API?

@Sland which camunda version are you using?

I was able to configure in both SpringProcessEngineConfiguration and StandaloneProcessEngineConfiguration

SpringProcessEngineConfiguration config = new SpringProcessEngineConfiguration();
config.setHistoryTimeToLive(historyTimeToLive);

StandaloneProcessEngineConfiguration configuration2 = new StandaloneProcessEngineConfiguration();
configuration2.setHistoryTimeToLive(historyTimeToLive);

Also, you can set it via rest api also and in bpmn model also you can configure it.

https://docs.camunda.org/manual/7.11/reference/deployment-descriptors/tags/process-engine/

@aravindhrs We are using 7.10 version. And it is now possible to set ttl via REST, because we cannot use REST API.

I have config from context, so, this process engine takes from method params. ProcessEngineConfigurationImpl.

Yes, i am already checked StandaloneProcessEngineConfiguration and SpringProcessEngineConfiguration. For my case there is no method setHistoryTimeToLive. It’s strange.

@aravindhrs

Hm. I guess it’s because we use incorrect version? Camunda BPM Javadocs 7.11.21-ee

@Sland function setHistoryTimeToLive is available in camunda version 7.11. Its not available in 7.10. Anyway camunda 7.11 is stable version you can easily upgrade to latest version.

@aravindhrs Okay, thank you, i will try and notify about result.

And one more question. If I want to delete history data, is it enough for me to have only one TTL parameter?Or cleanup strategy required? Because i can set TTL using bpmn files of processes. But in ACT_HI_PROCINST database there is only start time (show attachment). So, can you clarify this information. please?

Capture

setHistoryTimeToLive at process engine level applicable across all process definitions. Instead if you want to configure different TTL at process definition level you can configure it in bpmn file itself. Even you can narrow down to specific process instance level to set TTL. It’s upto you which level you want to set TTL. e.g, ProcessEngine level/Process definition level/Process instance level.

@aravindhrs

setHistoryTimeToLive at process engine level applicable across all process definition

Yes, it’s correct case for me. And version 7.11 works. But another my question about cleanup strategy above comment. Please, can you check it?

@Sland you need to setup cleanup strategy and History TTL in process definition also. For the strategy HISTORY_CLEANUP_STRATEGY_REMOVAL_TIME_BASED, once process instance is completed, the removal time will be updated.