Skip to content

Commit

Permalink
add ProcessTaskLog
Browse files Browse the repository at this point in the history
  • Loading branch information
mpern committed May 6, 2021
1 parent a8b1beb commit 643e468
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 58 deletions.
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

TBD

## [3.2.0] - 2021-05-06

### Added

- Cleanup `ProcessTaskLog`
- Cleanup `ProcessTaskLog` (thanks to [@ashwinineha] :tada:)

[@ashwinineha]: https://github.com/ashwinineha

## [3.0.1] - 2021-04-30
## [3.1.0] - 2021-04-30

### Added

Expand Down Expand Up @@ -103,7 +109,8 @@ Initial release
- Carts


[Unreleased]: https://github.com/sap-commerce-tools/sanecleanup/compare/v3.1.0...HEAD
[Unreleased]: https://github.com/sap-commerce-tools/sanecleanup/compare/v3.2.0...HEAD
[3.2.0]: https://github.com/sap-commerce-tools/sanecleanup/compare/v3.1.0...v.3.2.0
[3.1.0]: https://github.com/sap-commerce-tools/sanecleanup/compare/v3.0.0...v3.1.0
[3.0.0]: https://github.com/sap-commerce-tools/sanecleanup/compare/v2.0.0...v3.0.0
[2.0.0]: https://github.com/sap-commerce-tools/sanecleanup/compare/v1.0.1...v2.0.0
Expand Down
40 changes: 35 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ SELECT
ELSE
'saved'
END
AS "cart type",
AS "cart type",
COUNT({c:pk}) AS "total",
MIN({c:modifiedtime}) AS "oldest",
MIN({c:modifiedtime}) AS "oldest",
MAX({c:modifiedtime}) AS "newest"
FROM
{ Cart AS c
Expand Down Expand Up @@ -203,7 +203,7 @@ This cleanup is enabled by default in recent SAP Commerce patch releases, so thi

```sql
SELECT
{bp:processDefinitionName} AS "source process",
{bp:processDefinitionName} AS "source",
{m:sent},
COUNT({m:pk}) AS "total",
MIN({m:modifiedtime}) AS "oldest",
Expand Down Expand Up @@ -261,7 +261,8 @@ FROM
WHERE
(
{i:code} LIKE '0_______'
OR {i:code} LIKE 'generated impex media - %'
OR {i:code} LIKE
'generated impex media - %'
)
```

Expand Down Expand Up @@ -315,6 +316,34 @@ ORDER BY
Are there are cronjob with more than ~10 logs and/or logs older than 14 days?
(those are default values for log file retention)

</td></tr>
<tr><td>ProcessTaskLog</td><td>

```sql
-- Query tested with MS SQL
-- Adjust the date calculation for
-- other databases
SELECT
COUNT({l:pk}) AS "total",
MIN({l:modifiedtime}) AS "oldest",
MAX({l:modifiedtime}) AS "newest"
FROM
{ProcessTaskLog AS l}
WHERE
{l:creationTime} < DATEADD(
MONTH,
-2,
GETUTCDATE()
)
```

</td><td>

We recommend customer to BusinessProcess cleanup, which will eventually take care of TaskLogs cleanup.
There might be the few scenarios for ProcessTaskLog cleanup:
1. The customer wants to keep the BusinessProcess for reporting, although we don't recommend it.
1. The customer might be using the custom task without any business process.

</td></tr>
<tr><td>SavedValues,SavedValueEntry</td><td>

Expand Down Expand Up @@ -353,7 +382,8 @@ GROUP BY
ORDER BY
"total" DESC

-- orphaned SavedValueEntry - there shouldn't be any
-- orphaned SavedValueEntry
-- (there shouldn't be any)
SELECT
COUNT({e:pk}) AS "total",
MIN({e:modifiedtime}) AS "oldest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $twoWeeks = 1209600
# - Are there more than a handful sent/unsent messages?
# - Are there messages that do not belong to any process?
# SELECT
# {bp:processDefinitionName} AS "source process",
# {bp:processDefinitionName} AS "source",
# {m:sent},
# COUNT({m:pk}) AS "total",
# MIN({m:modifiedtime}) AS "oldest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ $sessionLanguage = $config-sanecleanup.jobs.sessionlanguage
# {s:modifiedItem}
# ORDER BY
# "total" DESC
# -- orphaned SavedValueEntry - there shouldn't be any
# -- orphaned SavedValueEntry
# -- (there shouldn't be any)
# SELECT
# COUNT({e:pk}) AS "total",
# MIN({e:modifiedtime}) AS "oldest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,79 @@ UPDATE GenericItem[processor=de.hybris.platform.commerceservices.impex.impl.Conf
$sessionLanguage=$config-sanecleanup.jobs.sessionlanguage

# @readme ProcessTaskLog
# We recommend customer to BusinessProcess cleanup, which will eventually take care of TaskLogs cleanup. There might be the few scenarios for ProcessTaskLog cleanUp
#1. The customer wants to keep the BusinessProcess for reporting, although we don't recommend it.
#1. The customer might be using the custom task without any business process.
#
# -- Queries is adjusted based MSSQL
# -- further adjustment required for other Database Type
# We recommend customer to BusinessProcess cleanup, which will eventually take care of TaskLogs cleanup.
# There might be the few scenarios for ProcessTaskLog cleanup:
# 1. The customer wants to keep the BusinessProcess for reporting, although we don't recommend it.
# 1. The customer might be using the custom task without any business process.
# -- Query tested with MS SQL
# -- Adjust the date calculation for
# -- other database types
# SELECT
# COUNT({pk})
# COUNT({l:pk}) AS "total",
# MIN({l:modifiedtime}) AS "oldest",
# MAX({l:modifiedtime}) AS "newest"
# FROM
# {ProcessTaskLog}
# {ProcessTaskLog AS l}
# WHERE
# {creationTime} < DATEADD(
# {l:creationTime} < DATEADD(
# month,
# -2,
# SYSDATETIME()
# GETUTCDATE()
# )
#

INSERT_UPDATE Script; code[unique=true]; description[default = $sessionLanguage]; content; active[default=true]
;directCleanupProcessTaskLogScript;"Delete ProcessTaskLog" ;"
import de.hybris.platform.servicelayer.search.FlexibleSearchQuery;
import de.hybris.platform.util.persistence.PersistenceUtils;
fss = spring.getBean('flexibleSearchService')
ms = spring.getBean('modelService')
import de.hybris.platform.servicelayer.search.FlexibleSearchQuery
import de.hybris.platform.util.persistence.PersistenceUtils

import java.time.Instant
import java.time.ZoneId
import java.time.temporal.ChronoUnit

def fss = spring.getBean('flexibleSearchService')
def ms = spring.getBean('modelService')

PersistenceUtils.doWithSLDPersistence({ ->
// -3 3 Month ADJUST
processTaskLogQuery = new FlexibleSearchQuery(/SELECT {pk} FROM {ProcessTaskLog} WHERE {creationTime} < DATEADD(month, -3, SYSDATETIME() ) /);
processTaskLogQuery.setCount(10000); // ADJUST TOTAL COUNT
processTaskLogCounts = fss.search(processTaskLogQuery).result
// out.println('ProcessTaskLog count: ' + processTaskLogCounts.size())
if (processTaskLogCounts.size() > 0) {
// out.println('Deleting ProcessTaskLog: ' + processTaskLogCounts.size())
try { // try bulk remove
ms.removeAll(processTaskLogCounts)
counter = processTaskLogCounts.size()
// TODO: adjust retention period
def retention = Date.from(Instant.now().atZone(ZoneId.systemDefault()).minus(3, ChronoUnit.MONTHS).toInstant())
def processTaskLogQuery = new FlexibleSearchQuery('SELECT {pk} FROM {ProcessTaskLog} WHERE {creationTime} < ?CALC_RETENTION_TIME');
processTaskLogQuery.addQueryParameter('CALC_RETENTION_TIME', retention)
processTaskLogQuery.setCount(10000); // TODO: adjust total count
def processTaskLogs = fss.search(processTaskLogQuery).result
// out.println('ProcessTaskLog count: ' + processTaskLogs.size())
if (processTaskLogs.size() > 0) {
// out.println('Deleting ProcessTaskLog: ' + processTaskLogs.size())
def counter
try { // try bulk remove
ms.removeAll(processTaskLogs)
counter = processTaskLogs.size()
processTaskLogs.each {
ms.detach(it)
}

} catch (Exception bulkEx) { // if exception do individual remove
// out.println('Exception: ' + bulkEx.getMessage())
counter = 0
for (processTaskLogCount in processTaskLogCounts) {
try{
ms.remove(processTaskLogCount)
counter++
// out.println(counter + ' | Deleted - ProcessTaskLog: ' + processTaskLogCount?.pk + ' - ' + processTaskLogCount?.actionId + ' - ' + processTaskLogCount?.process)
} catch (Exception indEx) {
// out.println('Exception: ' + indEx.getMessage())
} catch (Exception bulkEx) { // if exception do individual remove
// out.println('Exception: ' + bulkEx.getMessage())
counter = 0
for (taskLog in processTaskLogs) {
try {
ms.remove(taskLog)
ms.detach(taskLog)
counter++
// out.println(counter + ' | Deleted - ProcessTaskLog: ' + taskLog?.pk + ' - ' + taskLog?.actionId + ' - ' + taskLog?.process)
} catch (Exception indEx) {
// out.println('Exception: ' + indEx.getMessage())
}
}
}
}
// out.println('Deleted ProcessTaskLog: ' + counter)
// processTaskLogQuery.setCount(-1);
// processTaskLogCounts = fss.search(processTaskLogQuery).result
// return [deleted: counter, remaining: processTaskLogCounts.size()]
return [deleted: counter]
// out.println('Deleted ProcessTaskLog: ' + counter)
// processTaskLogQuery.setCount(-1);
// processTaskLogs = fss.search(processTaskLogQuery).result
// return [deleted: counter, remaining: processTaskLogs.size()]
return [deleted: counter]

} else {
// out.println('NO ProcessTaskLog to delete.')
return [deleted: 0, remaining: 0]
}
} else {
// out.println('NO ProcessTaskLog to delete.')
return [deleted: 0, remaining: 0]
}
});
";

Expand All @@ -72,6 +85,6 @@ INSERT_UPDATE ScriptingJob;code[unique = true];scriptURI
INSERT_UPDATE CronJob;code[unique=true]; job(code); sessionLanguage(isoCode)[default = $sessionLanguage];
;directCleanupProcessTaskLogCronjob;directCleanupProcessTaskLogScriptJob ;

# runs every 40 mins ADJUST
INSERT_UPDATE Trigger; cronjob(code)[unique = true]; cronExpression; active
# every 40 minutes
INSERT Trigger; cronjob(code)[unique = true]; cronExpression; active
;directCleanupProcessTaskLogCronjob ;0 0/40 * ? * * * ;true

0 comments on commit 643e468

Please sign in to comment.