Skip to content

Commit

Permalink
🐛 fix: cleanup config and scheduled workflow deletion bug, add more d…
Browse files Browse the repository at this point in the history
…escriptive stdout (#38)
  • Loading branch information
garden-of-delete authored Mar 22, 2024
1 parent a640b9d commit 4a95b1a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type CleanupCmdOpt struct {

func getCleanupCmdOpt() CleanupCmdOpt {
return CleanupCmdOpt{
ScheduledWorkflowTimeout: viper.GetDuration("cleanup.scheduledWorkflowTimeout"),
ScheduledWorkflowTimeout: viper.GetDuration("cleanup.scheduledWorkflow"),
WorkflowActivationLockTimeout: viper.GetDuration("cleanup.workflowActivationLock"),
WorkflowSchedulerLockTimeout: viper.GetDuration("cleanup.workflowSchedulerLock"),
}
Expand Down
11 changes: 6 additions & 5 deletions service/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ type Cleanup struct {
}

func (s *Cleanup) Run() {
fmt.Println("Deleting expired activation locks...")
fmt.Println("Cleanup started")
s.deleteExpiredActivatorLocks(database.GetInstance())
fmt.Println("Deleting expired scheduler locks...")
s.deleteExpiredSchedulerLocks(database.GetInstance())
fmt.Println("Deleting expired scheduled workflows...")
s.deleteExpiredScheduledWorkflows(database.GetInstance())
fmt.Println("Cleanup complete")
}

func (s *Cleanup) deleteExpiredActivatorLocks(db *gorm.DB) {
expiryTime := time.Now().Add(-s.WorkflowActivationLockTimeout)
fmt.Printf("Deleting activation locks older than %s ...\n", expiryTime)

db.Model(&table.WorkflowActivatorLock{}).
Where("lock_time < ?", expiryTime).
Expand All @@ -34,6 +33,7 @@ func (s *Cleanup) deleteExpiredActivatorLocks(db *gorm.DB) {

func (s *Cleanup) deleteExpiredSchedulerLocks(db *gorm.DB) {
expiryTime := time.Now().Add(-s.WorkflowSchedulerLockTimeout)
fmt.Printf("Deleting scheduler locks older than %s ...\n", expiryTime)

db.Model(&table.WorkflowSchedulerLock{}).
Where("lock_time < ?", expiryTime).
Expand All @@ -42,8 +42,9 @@ func (s *Cleanup) deleteExpiredSchedulerLocks(db *gorm.DB) {

func (s *Cleanup) deleteExpiredScheduledWorkflows(db *gorm.DB) {
expiryTime := time.Now().Add(-s.ScheduledWorkflowTimeout)
fmt.Printf("Deleting scheduled workflows older than %s ...\n", expiryTime)

db.Unscoped().Model(&table.ScheduledWorkflow{}).
db.Model(&table.ScheduledWorkflow{}).
Where("updated_at < ?", expiryTime).
Delete(&table.ScheduledWorkflow{})
Unscoped().Delete(&table.ScheduledWorkflow{})
}

0 comments on commit 4a95b1a

Please sign in to comment.