Skip to content

Commit 643e468

Browse files
committed
add ProcessTaskLog
1 parent a8b1beb commit 643e468

File tree

5 files changed

+109
-58
lines changed

5 files changed

+109
-58
lines changed

CHANGELOG.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
TBD
11+
12+
## [3.2.0] - 2021-05-06
13+
1014
### Added
1115

12-
- Cleanup `ProcessTaskLog`
16+
- Cleanup `ProcessTaskLog` (thanks to [@ashwinineha] :tada:)
17+
18+
[@ashwinineha]: https://github.com/ashwinineha
1319

14-
## [3.0.1] - 2021-04-30
20+
## [3.1.0] - 2021-04-30
1521

1622
### Added
1723

@@ -103,7 +109,8 @@ Initial release
103109
- Carts
104110

105111

106-
[Unreleased]: https://github.com/sap-commerce-tools/sanecleanup/compare/v3.1.0...HEAD
112+
[Unreleased]: https://github.com/sap-commerce-tools/sanecleanup/compare/v3.2.0...HEAD
113+
[3.2.0]: https://github.com/sap-commerce-tools/sanecleanup/compare/v3.1.0...v.3.2.0
107114
[3.1.0]: https://github.com/sap-commerce-tools/sanecleanup/compare/v3.0.0...v3.1.0
108115
[3.0.0]: https://github.com/sap-commerce-tools/sanecleanup/compare/v2.0.0...v3.0.0
109116
[2.0.0]: https://github.com/sap-commerce-tools/sanecleanup/compare/v1.0.1...v2.0.0

README.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ SELECT
104104
ELSE
105105
'saved'
106106
END
107-
AS "cart type",
107+
AS "cart type",
108108
COUNT({c:pk}) AS "total",
109-
MIN({c:modifiedtime}) AS "oldest",
109+
MIN({c:modifiedtime}) AS "oldest",
110110
MAX({c:modifiedtime}) AS "newest"
111111
FROM
112112
{ Cart AS c
@@ -203,7 +203,7 @@ This cleanup is enabled by default in recent SAP Commerce patch releases, so thi
203203

204204
```sql
205205
SELECT
206-
{bp:processDefinitionName} AS "source process",
206+
{bp:processDefinitionName} AS "source",
207207
{m:sent},
208208
COUNT({m:pk}) AS "total",
209209
MIN({m:modifiedtime}) AS "oldest",
@@ -261,7 +261,8 @@ FROM
261261
WHERE
262262
(
263263
{i:code} LIKE '0_______'
264-
OR {i:code} LIKE 'generated impex media - %'
264+
OR {i:code} LIKE
265+
'generated impex media - %'
265266
)
266267
```
267268

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

319+
</td></tr>
320+
<tr><td>ProcessTaskLog</td><td>
321+
322+
```sql
323+
-- Query tested with MS SQL
324+
-- Adjust the date calculation for
325+
-- other databases
326+
SELECT
327+
COUNT({l:pk}) AS "total",
328+
MIN({l:modifiedtime}) AS "oldest",
329+
MAX({l:modifiedtime}) AS "newest"
330+
FROM
331+
{ProcessTaskLog AS l}
332+
WHERE
333+
{l:creationTime} < DATEADD(
334+
MONTH,
335+
-2,
336+
GETUTCDATE()
337+
)
338+
```
339+
340+
</td><td>
341+
342+
We recommend customer to BusinessProcess cleanup, which will eventually take care of TaskLogs cleanup.
343+
There might be the few scenarios for ProcessTaskLog cleanup:
344+
1. The customer wants to keep the BusinessProcess for reporting, although we don't recommend it.
345+
1. The customer might be using the custom task without any business process.
346+
318347
</td></tr>
319348
<tr><td>SavedValues,SavedValueEntry</td><td>
320349

@@ -353,7 +382,8 @@ GROUP BY
353382
ORDER BY
354383
"total" DESC
355384

356-
-- orphaned SavedValueEntry - there shouldn't be any
385+
-- orphaned SavedValueEntry
386+
-- (there shouldn't be any)
357387
SELECT
358388
COUNT({e:pk}) AS "total",
359389
MIN({e:modifiedtime}) AS "oldest",

resources/impex/sanecleanup/acceleratorservices/001-cleanup-emails.impex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ $twoWeeks = 1209600
88
# - Are there more than a handful sent/unsent messages?
99
# - Are there messages that do not belong to any process?
1010
# SELECT
11-
# {bp:processDefinitionName} AS "source process",
11+
# {bp:processDefinitionName} AS "source",
1212
# {m:sent},
1313
# COUNT({m:pk}) AS "total",
1414
# MIN({m:modifiedtime}) AS "oldest",

resources/impex/sanecleanup/core/002-cleanup-savedvalueentries.impex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ $sessionLanguage = $config-sanecleanup.jobs.sessionlanguage
3939
# {s:modifiedItem}
4040
# ORDER BY
4141
# "total" DESC
42-
# -- orphaned SavedValueEntry - there shouldn't be any
42+
# -- orphaned SavedValueEntry
43+
# -- (there shouldn't be any)
4344
# SELECT
4445
# COUNT({e:pk}) AS "total",
4546
# MIN({e:modifiedtime}) AS "oldest",

resources/impex/sanecleanup/processing/004-cleanup-processtasklog.impex

Lines changed: 61 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,79 @@ UPDATE GenericItem[processor=de.hybris.platform.commerceservices.impex.impl.Conf
33
$sessionLanguage=$config-sanecleanup.jobs.sessionlanguage
44

55
# @readme ProcessTaskLog
6-
# We recommend customer to BusinessProcess cleanup, which will eventually take care of TaskLogs cleanup. There might be the few scenarios for ProcessTaskLog cleanUp
7-
#1. The customer wants to keep the BusinessProcess for reporting, although we don't recommend it.
8-
#1. The customer might be using the custom task without any business process.
9-
#
10-
# -- Queries is adjusted based MSSQL
11-
# -- further adjustment required for other Database Type
6+
# We recommend customer to BusinessProcess cleanup, which will eventually take care of TaskLogs cleanup.
7+
# There might be the few scenarios for ProcessTaskLog cleanup:
8+
# 1. The customer wants to keep the BusinessProcess for reporting, although we don't recommend it.
9+
# 1. The customer might be using the custom task without any business process.
10+
# -- Query tested with MS SQL
11+
# -- Adjust the date calculation for
12+
# -- other database types
1213
# SELECT
13-
# COUNT({pk})
14+
# COUNT({l:pk}) AS "total",
15+
# MIN({l:modifiedtime}) AS "oldest",
16+
# MAX({l:modifiedtime}) AS "newest"
1417
# FROM
15-
# {ProcessTaskLog}
18+
# {ProcessTaskLog AS l}
1619
# WHERE
17-
# {creationTime} < DATEADD(
20+
# {l:creationTime} < DATEADD(
1821
# month,
1922
# -2,
20-
# SYSDATETIME()
23+
# GETUTCDATE()
2124
# )
22-
#
23-
2425
INSERT_UPDATE Script; code[unique=true]; description[default = $sessionLanguage]; content; active[default=true]
2526
;directCleanupProcessTaskLogScript;"Delete ProcessTaskLog" ;"
26-
import de.hybris.platform.servicelayer.search.FlexibleSearchQuery;
27-
import de.hybris.platform.util.persistence.PersistenceUtils;
28-
fss = spring.getBean('flexibleSearchService')
29-
ms = spring.getBean('modelService')
27+
import de.hybris.platform.servicelayer.search.FlexibleSearchQuery
28+
import de.hybris.platform.util.persistence.PersistenceUtils
29+
30+
import java.time.Instant
31+
import java.time.ZoneId
32+
import java.time.temporal.ChronoUnit
33+
34+
def fss = spring.getBean('flexibleSearchService')
35+
def ms = spring.getBean('modelService')
3036

3137
PersistenceUtils.doWithSLDPersistence({ ->
32-
// -3 3 Month ADJUST
33-
processTaskLogQuery = new FlexibleSearchQuery(/SELECT {pk} FROM {ProcessTaskLog} WHERE {creationTime} < DATEADD(month, -3, SYSDATETIME() ) /);
34-
processTaskLogQuery.setCount(10000); // ADJUST TOTAL COUNT
35-
processTaskLogCounts = fss.search(processTaskLogQuery).result
36-
// out.println('ProcessTaskLog count: ' + processTaskLogCounts.size())
37-
if (processTaskLogCounts.size() > 0) {
38-
// out.println('Deleting ProcessTaskLog: ' + processTaskLogCounts.size())
39-
try { // try bulk remove
40-
ms.removeAll(processTaskLogCounts)
41-
counter = processTaskLogCounts.size()
38+
// TODO: adjust retention period
39+
def retention = Date.from(Instant.now().atZone(ZoneId.systemDefault()).minus(3, ChronoUnit.MONTHS).toInstant())
40+
def processTaskLogQuery = new FlexibleSearchQuery('SELECT {pk} FROM {ProcessTaskLog} WHERE {creationTime} < ?CALC_RETENTION_TIME');
41+
processTaskLogQuery.addQueryParameter('CALC_RETENTION_TIME', retention)
42+
processTaskLogQuery.setCount(10000); // TODO: adjust total count
43+
def processTaskLogs = fss.search(processTaskLogQuery).result
44+
// out.println('ProcessTaskLog count: ' + processTaskLogs.size())
45+
if (processTaskLogs.size() > 0) {
46+
// out.println('Deleting ProcessTaskLog: ' + processTaskLogs.size())
47+
def counter
48+
try { // try bulk remove
49+
ms.removeAll(processTaskLogs)
50+
counter = processTaskLogs.size()
51+
processTaskLogs.each {
52+
ms.detach(it)
53+
}
4254

43-
} catch (Exception bulkEx) { // if exception do individual remove
44-
// out.println('Exception: ' + bulkEx.getMessage())
45-
counter = 0
46-
for (processTaskLogCount in processTaskLogCounts) {
47-
try{
48-
ms.remove(processTaskLogCount)
49-
counter++
50-
// out.println(counter + ' | Deleted - ProcessTaskLog: ' + processTaskLogCount?.pk + ' - ' + processTaskLogCount?.actionId + ' - ' + processTaskLogCount?.process)
51-
} catch (Exception indEx) {
52-
// out.println('Exception: ' + indEx.getMessage())
55+
} catch (Exception bulkEx) { // if exception do individual remove
56+
// out.println('Exception: ' + bulkEx.getMessage())
57+
counter = 0
58+
for (taskLog in processTaskLogs) {
59+
try {
60+
ms.remove(taskLog)
61+
ms.detach(taskLog)
62+
counter++
63+
// out.println(counter + ' | Deleted - ProcessTaskLog: ' + taskLog?.pk + ' - ' + taskLog?.actionId + ' - ' + taskLog?.process)
64+
} catch (Exception indEx) {
65+
// out.println('Exception: ' + indEx.getMessage())
66+
}
5367
}
5468
}
55-
}
56-
// out.println('Deleted ProcessTaskLog: ' + counter)
57-
// processTaskLogQuery.setCount(-1);
58-
// processTaskLogCounts = fss.search(processTaskLogQuery).result
59-
// return [deleted: counter, remaining: processTaskLogCounts.size()]
60-
return [deleted: counter]
69+
// out.println('Deleted ProcessTaskLog: ' + counter)
70+
// processTaskLogQuery.setCount(-1);
71+
// processTaskLogs = fss.search(processTaskLogQuery).result
72+
// return [deleted: counter, remaining: processTaskLogs.size()]
73+
return [deleted: counter]
6174

62-
} else {
63-
// out.println('NO ProcessTaskLog to delete.')
64-
return [deleted: 0, remaining: 0]
65-
}
75+
} else {
76+
// out.println('NO ProcessTaskLog to delete.')
77+
return [deleted: 0, remaining: 0]
78+
}
6679
});
6780
";
6881

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

75-
# runs every 40 mins ADJUST
76-
INSERT_UPDATE Trigger; cronjob(code)[unique = true]; cronExpression; active
88+
# every 40 minutes
89+
INSERT Trigger; cronjob(code)[unique = true]; cronExpression; active
7790
;directCleanupProcessTaskLogCronjob ;0 0/40 * ? * * * ;true

0 commit comments

Comments
 (0)