commercetools Data Cleanup is a data reorganisation tool for commercetools. Configure predicates for your resources and commercetools Data Cleanup will periodically delete resources that match the predicate.
Add our Spring Boot Starter to your gradle or maven file.
implementation "tech.bison:commercetools-datacleanup-spring-boot-starter:x.y.z"
(latest version numbers avaible on Maven Central)
Use application properties to configure the cleanup predicates for the commercetools resources to cleanup:
datacleanup:
predicates:
custom-object:
container: myContainer
where:
- createdAt > "{{now-6M}}"
category:
- ...
classes:
- com.example.myCommand
The where clause of a predicate must be in the commercetools query predicate syntax. Within the predicate you can provide a datetime pattern enclosed with double curly brackets to get a relative datetime. The basic format is {{now[diff...]}}.
- diff is optional
- There can be multiple diff's and they can be specified in any order
- Whitespaces are allowed before and after each diff
Examples:
- {{now}}}
- {{now-3M}}
- {{now+1y+1M}}
Predicates of type custom-object require a value in the container attribute. This attribute should only be set for this type of predicate. The attribute is ignored for all other predicate types.
If you want full control of the cleanup logic you can configure a class which implements the CleanupCommand interface. The class must be configured by its fully qualified name.
Take your background job library of your choice and execute the cleanup commands with the Core API. Example with Spring Scheduling and ShedLock:
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
//...
@AutoWired
public CleanupJob(DataCleanup dataCleanup) {
this.dataCleanup = dataCleanup;
}
@Scheduled(cron = "0 2 * * *")
@SchedulerLock(name = "cleanup")
public void scheduledTask() {
LockAssert.assertLocked();
dataCleanup.execute();
}
Add the data cleanup core module to your gradle or maven file.
implementation "tech.bison:commercetools-datacleanup-core:x.y.z"
(latest version numbers avaible on Maven Central)
DataCleanup dataCleanup = DataCleanup.configure()
.withApiProperties(new CommercetoolsProperties("clientId", "clientSecret", "apiUrl", "authUrl", "projectKey"))
.withPredicate(CUSTOM_OBJECT, "container = \"email\" and createdAt > \"2024 - 08 - 28T08:25:59.157Z\"")
.load()
.execute();
There is a possibility to use alternative url to maven central: create gradle.properties and set for example: REPO1_URL=https://artifactory.example.com/repo1
commercetools Data Cleanup is published under the Apache License 2.0, see http://www.apache.org/licenses/LICENSE-2.0 for details.