How can we change bulk timers

Hi,

I have a process with timer and I have created around 200 running instances and now I want to add 5hrs to all the timer waiting instances, please let us know if there is any way we can achieve this scenario (I am using camunda version 7.17).

Thanks,
Venkaiah.

Hey @venky1982,

timers are jobs to be executed at a certain point in time. Every job has a due date in the Camunda 7 database so you could fetch all jobs first and then update them with a newly calculated due date through the REST API.

Best,
Hendrik

3 Likes

Thank you Hendrik,

Could you please let mw know in which table and in which column the timers jobs are stored and also please let me know what is the process to calculate to set a new date and time. Thanks in advance.

Thanks,
Venkaiah.

Probably something along these lines…

The REST interface information is in the links that hendrik posted

Hey @venky1982,

jobs are stored in the table ACT_RU_JOB with the due date being in the column DUEDATE_.

Here’s a quickly cobbled together Postman script written in JavaScript that updates existing due dates via the REST API. Ofcourse you can do this with any other programming or scripting language as well.

const hoursToAdd = 5; // Specify hours to add to existing job due dates

const getJobsRequest = {
  url: 'http://localhost:8080/engine-rest/job/',
  method: 'POST',
  header: {
    'Content-Type': 'application/json'
  },
  body: {
    mode: 'raw',
    raw: JSON.stringify({ processDefinitionKey: 'TimerUpdateTestProcess', jobDefinitionId: 'bc0ce1a7-6a97-11ed-9fe5-18264972ef47' })
  }
};

// Fetch all existing jobs for the process definition with the key "TimerUpdateTestProcess" & job definition ID "c29a1a1e-6a8f-11ed-a036-18264972ef47" (to prevent unwanted updates of other timers)
pm.sendRequest(getJobsRequest, function(error, response) {
  if (error) {
    console.log(error);
  }

  for (index in response.json()) {
    const job = response.json()[index];
    const jobId = job.id;

    const currentDueDate = job.dueDate;
    const newDueDate = getNewDueDateInIsoFormat(currentDueDate);

    const updateDueDateRequest = {
	  url: 'http://localhost:8080/engine-rest/job/' + jobId + '/duedate/',
	  method: 'PUT',
	  header: {
	    'Content-Type': 'application/json'
	  },
	  body: {
	    mode: 'raw',
		raw: JSON.stringify({ duedate: newDueDate, cascade: false }) // If "cascade" is set to true subsequent timer jobs will also be updated
	  }
	};

	// Update job with new due date
	pm.sendRequest(updateDueDateRequest, function(error, response) {
	  if (error) {
		console.log(error);
	  }

	  console.log('Modified due date for job "' + jobId + '" (' + currentDueDate + ' -> ' + newDueDate + ')');
	})  
  }
});

function getNewDueDateInIsoFormat(currentDueDate) {
  let newDueDate = new Date(currentDueDate);
  newDueDate.setTime(newDueDate.getTime() + (hoursToAdd * 60 * 60 * 1000)); // Add hours to job due date

  // The REST API endpoint only accepts a specific due date format so we need to adjust the time zone offset manually
  const timeZoneOffsetInMs = new Date().getTimezoneOffset() * 60000;
  const formattedTimeZoneOffset = -timeZoneOffsetInMs / 60000 / 60 * 100;
  const isoDateSuffix = (formattedTimeZoneOffset < 0 ? "" : "+") + formattedTimeZoneOffset.toString().padStart(4, '0');
  const newDueDateInIsoFormat = new Date(newDueDate - timeZoneOffsetInMs).toISOString().slice(0, -1) + isoDateSuffix;

  return newDueDateInIsoFormat;
}

Best,
Hendrik

1 Like

Thank you for the details Hendrik.