import json
import os
from lxml import etree
from yandex.maps.wiki.tasks import grinder

SERVICES_CFG = '../../../cfg/services/services.local.%s.xml' % os.environ['USER']

cfg = etree.parse(SERVICES_CFG)
node = cfg.xpath('/config/common/grinder/host')[0]
grinder_host = node.text

gateway = grinder.GrinderGateway(grinder_host)
tasks = gateway.tasks()
print('Count ' + str(len(tasks)))
for task_id in tasks:
    print('Clear taskid ' + task_id)
    gateway.cancel_task(task_id)
