We had the same problem.
To not spam users, we've been looking for a mechanism that we could use to control the de-duplication feature for certain notification types.
Since they check TASK_ID - we can use it to control de-duplication by adding something unique. For example a timestamp.
TASK_ID is the last part of the task name. Task name looks like this -
projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID.
If we need to create a task that will be executed once per 10 seconds - we can generate a name like this - projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/notification-like-${timestamp}.
Other tasks created within these 10 seconds will be rejected with an error.
JavaScript snippet that generates a task name
/**
* Round time up to given coefficient.
* @param {number} coefficient - Coefficient in milliseconds.
*/
const roundTime = (coefficient) => {
const date = new Date();
return new Date(Math.ceil(date.getTime() / coefficient) * coefficient).getTime();
};
const coefficient = 1000 * 10; // Trigger once per 10 seconds
const taskId = `notification-like-${roundTime(coefficient)}`;
const taskName = `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/${taskId}`;
console.log(taskName);
// projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/notification-like-1643898560000