From f807b03e742ec1c613717ef96585e64fd605d275 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 14 Jul 2016 19:24:13 +0200 Subject: [PATCH] Added auto cleanup on untouched open tasks if more the 30 are open. --- .../app/lib/app_post/task_manager.coffee | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/app/lib/app_post/task_manager.coffee b/app/assets/javascripts/app/lib/app_post/task_manager.coffee index 8b4f9531a..a0295ce69 100644 --- a/app/assets/javascripts/app/lib/app_post/task_manager.coffee +++ b/app/assets/javascripts/app/lib/app_post/task_manager.coffee @@ -193,13 +193,13 @@ class _taskManagerSingleton extends App.Controller if !task && !@workers[params.key] && !params.persistent task = new App.Taskbar task.load( - key: params.key - params: params.params - callback: params.controller + key: params.key + params: params.params + callback: params.controller client_id: 123 - prio: @newPrio() - notify: false - active: params.show + prio: @newPrio() + notify: false + active: params.show ) @allTasksByKey[params.key] = task.attributes() @@ -270,6 +270,8 @@ class _taskManagerSingleton extends App.Controller else @showControllerHideOthers(params.key, params_app) + @tasksAutoCleanupDelay() + showControllerHideOthers: (thisKey, params_app) => for key of @workers if key is thisKey @@ -498,6 +500,26 @@ class _taskManagerSingleton extends App.Controller return if !task.id App.Taskbar.destroy(task.id) + tasksAutoCleanupDelay: => + delay = => + @tasksAutoCleanup() + App.Delay.set(delay, 10000, 'task-autocleanup') + + tasksAutoCleanup: => + + # auto cleanup of old tasks + currentTaskCount = => + Object.keys(@allTasksByKey).length + + maxTaskCount = 30 + if currentTaskCount() > maxTaskCount + for task in App.Taskbar.search(sortBy:'updated_at', order:'ASC') + if currentTaskCount() > maxTaskCount + if !task.active + if _.isEmpty(task.state) || (_.isEmpty(task.state.ticket) && _.isEmpty(task.state.article)) + @log 'notice', "More then #{maxTaskCount} tasks open, close oldest untouched task #{task.key}" + @remove(task.key) + tasksInitial: => @init()