cli/vacuum: accept a --queued flag

This will permit to removed the queued tasks.
2 files changed, 8 insertions(+), 5 deletions(-)

M rework/cli.py
M rework/helper.py
M rework/cli.py +4 -2
@@ 500,9 500,10 @@ def import_scheduled(dburi, path):
 @click.argument('dburi')
 @click.option('--workers', is_flag=True, default=False)
 @click.option('--tasks', is_flag=True, default=False)
+@click.option('--queued', is_flag=True, default=False)
 @click.option('--domain', default='default')
 @click.option('--days', type=int, default=0)
-def vacuum(dburi, workers=False, tasks=False, domain='default', days=0):
+def vacuum(dburi, workers=False, tasks=False, queued=False, domain='default', days=0):
     " delete non-runing workers or finished tasks "
     if not (workers or tasks):
         print('to cleanup old workers or tasks '

          
@@ 521,7 522,8 @@ def vacuum(dburi, workers=False, tasks=F
         print(f'deleted {count} workers')
 
     if tasks:
-        count = cleanup_tasks(engine, finished, domain)
+        status = 'queued' if queued else 'done'
+        count = cleanup_tasks(engine, finished, domain, status)
         print(f'deleted {count} tasks')
 
 

          
M rework/helper.py +4 -3
@@ 151,20 151,21 @@ def cleanup_workers(engine, finished, do
     return count
 
 
-def cleanup_tasks(engine, finished, domain):
+def cleanup_tasks(engine, finished, domain, status='done'):
     with engine.begin() as cn:
         count = cn.execute(
             'with deleted as '
             '(delete from rework.task as t'
             '        using rework.operation as o'
-            '        where t.status = \'done\' and '
+            '        where t.status = %(status)s and '
             '              t.finished < %(finished)s and'
             '              t.operation = o.id and '
             '              o.domain = %(domain)s'
             ' returning 1) '
             'select count(*) from deleted',
             finished=finished,
-            domain=domain
+            domain=domain,
+            status=status
         ).scalar()
     return count