-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Workflow History pruning and prune time settings (#7343)
Github issue / Community forum post (link here to close automatically):
- Loading branch information
Showing
13 changed files
with
401 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { TIME } from '@/constants'; | ||
|
||
export const WORKFLOW_HISTORY_PRUNE_INTERVAL = 1 * TIME.HOUR; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/cli/src/workflows/workflowHistory/workflowHistoryManager.ee.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { WorkflowHistoryRepository } from '@/databases/repositories'; | ||
import { Service } from 'typedi'; | ||
import { WORKFLOW_HISTORY_PRUNE_INTERVAL } from './constants'; | ||
import { getWorkflowHistoryPruneTime, isWorkflowHistoryEnabled } from './workflowHistoryHelper.ee'; | ||
import { DateTime } from 'luxon'; | ||
import { LessThan } from 'typeorm'; | ||
|
||
@Service() | ||
export class WorkflowHistoryManager { | ||
pruneTimer?: NodeJS.Timeout; | ||
|
||
constructor(private workflowHistoryRepo: WorkflowHistoryRepository) {} | ||
|
||
init() { | ||
if (this.pruneTimer !== undefined) { | ||
clearInterval(this.pruneTimer); | ||
} | ||
|
||
this.pruneTimer = setInterval(async () => this.prune(), WORKFLOW_HISTORY_PRUNE_INTERVAL); | ||
} | ||
|
||
shutdown() { | ||
if (this.pruneTimer !== undefined) { | ||
clearInterval(this.pruneTimer); | ||
this.pruneTimer = undefined; | ||
} | ||
} | ||
|
||
async prune() { | ||
if (!isWorkflowHistoryEnabled()) { | ||
return; | ||
} | ||
|
||
const pruneHours = getWorkflowHistoryPruneTime(); | ||
// No prune time set | ||
if (pruneHours === -1) { | ||
return; | ||
} | ||
const pruneDateTime = DateTime.now().minus({ hours: pruneHours }).toJSDate(); | ||
|
||
await this.workflowHistoryRepo.delete({ | ||
createdAt: LessThan(pruneDateTime), | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.