def post(self, *args, **kwargs):
        app = self.checkAppAccess(args)
        template_shared = self.get_argument('template_shared', False)
        template_name = self.get_argument('template_name', None)
        timeRelatively = self.get_argument('template_time_relatively', False)

        # создаем задачу из аргументов
        task = createTaskFromRequestArguments(self.request.arguments)

        # создаем шаблон
        taskTemplate = TaskTemplate()
        taskTemplate.appId = app.appId
        taskTemplate.name = template_name
        taskTemplate.userId = self.get_current_user().userId
        taskTemplate.shared =  TaskTemplate.SHARED_NO
        if template_shared:
            taskTemplate.shared = TaskTemplate.SHARED_YES

        session = self.getDBSession()
        session.add(taskTemplate)
        session.commit()

        # скидываем на диск
        taskTemplateFile = TaskTemplateFile(self.application.getTemplatePath(), task = task, taskTemplate = taskTemplate)
        taskTemplateFile.timeRelatively = bool(timeRelatively)
        taskTemplateFile.baseDate = datetime.now()
        taskTemplateFile.save()

        self.redirect('/dashboard/app/{}/new?template={}'.format(app.code, taskTemplate.taskTemplateId))
    def post(self, *args, **kwargs):
        app = self.checkAppAccess(args)

        saveAsTemplate = str(self.get_argument("saveAsTemplate", default=""))

        # создаем задачу из аргументов
        task = createTaskFromRequestArguments(self.request.arguments)
        session = self.getDBSession()

        if saveAsTemplate:
            # сохраняем шаблон
            taskTemplate = TaskTemplate()
            taskTemplate.appId = app.appId
            taskTemplate.name = self.get_argument("taskName", default=None)
            taskTemplate.userId = self.get_current_user().userId
            taskTemplate.shared = TaskTemplate.SHARED_NO

            session.add(taskTemplate)
            session.commit()

            # скидываем на диск
            taskTemplateFile = TaskTemplateFile(
                self.application.getTemplatePath(), task=task, taskTemplate=taskTemplate
            )
            taskTemplateFile.baseDate = datetime.now()
            taskTemplateFile.save()

            self.redirect("/dashboard/app/{}/#templates".format(app.code))
            return

        user = self.get_current_user()

        # объект для записи в базу
        worker = Worker()
        worker.userId = user.userId
        worker.startDate = datetime.now()
        worker.status = Worker.STATUS_ALIVE
        worker.appId = app.appId
        worker.name = self.get_argument("taskName", default=None)

        # генерируем имя запроса
        appService = AppService(self.application.getAppConfigPath())
        appConfig = appService.getAppConfig(app.code)
        nameConstructor = NameConstructor(appConfig, task)
        if not worker.name:
            worker.name = nameConstructor.generateTaskName()

        session.add(worker)
        session.commit()

        # конструирем запрос
        constructor = HiveQueryConstructor(task, appConfig)
        querys = constructor.getHiveQuerys(worker.workerId)

        # task.stageCount = constructor.getStageCount()
        # создаем WorkerService - он будет связывать тред с файловой системой
        workerService = WorkerService(self.application.getResultPath(), worker)
        workerService.setQuery(querys)
        workerService.setTask(task)
        workerService.init()

        # создаем и запускаем тред
        workerThread = self.createHiveWorker(workerService)
        workerThread.start()

        self.redirect("/dashboard/app/" + app.code + "/#new_task/" + str(worker.workerId))