Start process at a given time in the past

How to start a process on a specific date in the past?
For example, I need to run the version of the process that was active at 5:00 p.m yesterday.
I use remote engine camunda/camunda-bpm-platform:run-7.19.0 and Spring Boot App.

Hello @Art ,

that is not as easy as described. A solution would be to look up which was the latest deployment of the process for the given time (can be done via API) and then check the process definition (with its id) that was contained. From there, you can start an instance for this specific process definition by id.

I hope this helps

Jonathan

@jonathan.lukas thanks for quick answer

All I was able to figure out is to call this method:

val searchResult = processDefinitionApi.getProcessDefinitions(
    null, //processDefinitionId,
    null, //processDefinitionIdIn,
    null, //name,
    null, //nameLike,
    null, //deploymentId,
    date, //deployedAfter,
    null, //deployedAt,
    "key", //key,
    null, //keysIn,
    null, //keyLike,
    null, //category,
    null, //categoryLike,
    null, //version,
    null, //latestVersion,
    null, //resourceName,
    null, //resourceNameLike,
    null, //startableBy,
    true, //active,
    null, //suspended,
    null, //incidentId,
    null, //incidentType,
    null, //incidentMessage,
    null, //incidentMessageLike,
    null, //tenantIdIn,
    null, //withoutTenantId,
    null, //includeProcessDefinitionsWithoutTenantId,
    null, //versionTag,
    null, //versionTagLike,
    null, //withoutVersionTag,
    null, //startableInTasklist,
    null, //notStartableInTasklist,
    null, //startablePermissionCheck,
    "deployTime", //sortBy,
    "desc", //sortOrder,
    0, //firstResult,
    1 //maxResults
);

return searchResult.get(0).getId();

Is that what You mean?

Hello @Art ,

I was not aware that you could get the deploy time from a process definition, yet this seems to be a good solution.

However, the filtering cannot be done using a time range I fear, so fetching more than just one process definition will be required.

Jonathan

@jonathan.lukas
Like You said, it’s not that easy :confused:

Let’s consider 2 deployments. First one is deployed at 08:00 and active immediately and the second one is deployed at 09:00 and active at 10:00 (using parameter deployment-activation-time).

Lets say it’s 9:30. If I want to start the process that was active at 09:20, I can use deploymentApi.getDeployments to get deployment that was valid (at that moment) and then use processDefinitionApi.getProcessDefinitions with filter active=true which give me no result, but using recurrence I can find proper version.

BUT, when it’s 10:30 and I try to do the same trick, there is a problem, because the definitions from the second deployment are not suspended anymore. There are active, and I’m unable to see that there were inactive at 09:20

Help :slight_smile:

This is what I have

private String resolveProcessId(Date date) throws ApiException {
    val deployments = deploymentApi.getDeployments(
        null, //id,
        applicationName, //name,
        null, //nameLike,
        null, //source,
        null, //withoutSource,
        null, //tenantIdIn,
        null, //withoutTenantId,
        null, //includeDeploymentsWithoutTenantId,
        null, //after,
        date, //before,
        "deploymentTime", //sortBy,
        "desc", //sortOrder,
        0, //firstResult,
        1 //maxResults
    );

    DeploymentDto deployment;
    if (!isEmpty(deployments)) {
        deployment = deployments.get(0);
    } else {
        deployment = deploymentApi.getDeployments(
            null, //id
            applicationName, //name
            null, //nameLike
            null, //source
            null, //withoutSource
            null, //tenantIdIn
            null, //withoutTenantId
            null, //includeDeploymentsWithoutTenantId
            null, //after
            null, //before
            "deploymentTime", //sortBy
            "asc", //sortOrder
            0, //firstResult
            1 //maxResults
        ).get(0);
    }

    val processDefinitions = processDefinitionApi.getProcessDefinitions(
        null, //processDefinitionId
        null, //processDefinitionIdIn
        null, //name
        null, //nameLike
        deployment.getId(), //deploymentId
        null, //deployedAfter
        null, //deployedAt
        key, //key
        null, //keysIn
        null, //keyLike
        null, //category
        null, //categoryLike
        null, //version
        null, //latestVersion
        null, //resourceName
        null, //resourceNameLike
        null, //startableBy
        true, //active
        null, //suspended
        null, //incidentId
        null, //incidentType
        null, //incidentMessage
        null, //incidentMessageLike
        null, //tenantIdIn
        null, //withoutTenantId
        null, //includeProcessDefinitionsWithoutTenantId
        null, //versionTag
        null, //versionTagLike
        null, //withoutVersionTag
        null, //startableInTasklist
        null, //notStartableInTasklist
        null, //startablePermissionCheck
        null, //sortBy
        null, //sortOrder
        null, //firstResult
        null //maxResults
    );

    if (!isEmpty(processDefinitions)) {
        return processDefinitions.get(0).getId();
    } else {
        return resolveProcessId(deployment.getDeploymentTime());
    }
}

Ok, I think I found a solution. I needed to use additional service: historicJobLogApi.getHistoricJobLogs where is information when particular process has become active.

1 Like

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