on 2024 Jul 16 8:42 AM
Dear,
how to clean up tasklog
SAP Hybris recommends to cleanup the TaskLogs table periodically.
The information contained in this table can be interesting for an audit trail. Make sure to backup your database and only cleanup this table if you are sure you will not need these log entries anymore.
A valid approach to cleanup the TaskLogs could be to implement the MaintenanceCleanupStrategy to remove logs for processes that are in the SUCCEEDED state and that where completed before a certain number of days.
Here is sample groovy script to clean up tasklog
import de.hybris.platform.core.Registry
import de.hybris.platform.core.model.task.TaskLogModel
import de.hybris.platform.servicelayer.search.FlexibleSearchQuery
import de.hybris.platform.servicelayer.search.SearchResult
import de.hybris.platform.servicelayer.search.impl.DefaultFlexibleSearchService
import de.hybris.platform.servicelayer.model.ModelService
// Get the FlexibleSearchService and ModelService
FlexibleSearchService flexibleSearchService = Registry.getApplicationContext().getBean("flexibleSearchService")
ModelService modelService = Registry.getApplicationContext().getBean("modelService")
// Specify the number of days to keep TaskLog entries
int daysToKeep = 30
// Calculate the cutoff date
Calendar calendar = Calendar.getInstance()
calendar.add(Calendar.DAY_OF_YEAR, -daysToKeep)
Date cutoffDate = calendar.getTime()
// Create a FlexibleSearch query to find TaskLog entries older than the cutoff date
String queryString = "SELECT {pk} FROM {TaskLog} WHERE {creationtime} < ?cutoffDate"
FlexibleSearchQuery query = new FlexibleSearchQuery(queryString)
query.addQueryParameter("cutoffDate", cutoffDate)
// Execute the query
SearchResult<TaskLogModel> result = flexibleSearchService.search(query)
// Delete the old TaskLog entries
result.getResult().each { taskLog ->
try {
modelService.remove(taskLog)
println "Deleted TaskLog entry with PK: ${taskLog.pk}"
} catch (Exception e) {
println "Failed to delete TaskLog entry with PK: ${taskLog.pk} due to: ${e.message}"
}
}
println "TaskLog cleanup complete. Deleted ${result.getResult().size()} entries older than ${daysToKeep} days."
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
12 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.