def render_POST_advanced(self, request, response): print("Received Task Request!") # unpack request wrapper = messages_pb2.WrapperMessage() wrapper.ParseFromString(request.payload) # print request (do nothing right now) print(" Framework Name: " + wrapper.run_task.task.framework.name) print(" Framework ID: " + wrapper.run_task.task.framework.framework_id) print(" Task Name: " + wrapper.run_task.task.name) print(" Task ID: " + wrapper.run_task.task.task_id) print(" Selected Agent: " + wrapper.run_task.task.agent_id) for i in range(len(wrapper.run_task.task.resources)): resource = wrapper.run_task.task.resources[i] print(" Resource: (" + resource.name + ") type: " + str(resource.type) + " amt: " + str(resource.scalar).strip()) # TODO: Forward the request onto the particular device through a ping/pong db.add_task(wrapper.run_task) # construct response wrapper = messages_pb2.WrapperMessage() wrapper.pong.agent_id = "1234" response.payload = wrapper.SerializeToString() response.code = defines.Codes.CHANGED.number response.content_type = defines.Content_types[ "application/octet-stream"] return self, response
def user_page(name): if request.method == 'POST': user_id = get_user_id(name) title = request.form['title'] content = request.form['content'] end_date = request.form['end_date'] add_task(user_id, title, content, end_date) user_tasks = get_tasks(name) return render_template('user.html', name=name, tasks=user_tasks)
def add_valid_task(self): error = None for task in db.get_tasks(): if self.name.data == task[2]: error = "Deploying task failed, already in database." return error options = dumps({'vapp_name': self.vapp.data, 'list': self.deploy_list.data}) db.add_task(self.deploy_time.data, 0, self.name.data, options) return error
def add_tasks(): if request.method == 'POST': if not request.is_json: return jsonify({"msg": "Missing JSON in request"}), 400 print(request.get_json()) add_task(request.get_json()) return 'Task Added' return get_tasks_by_id()
def new_task(): name = request.form['name'] date = request.form['due_date'] priority = request.form['priority'] userid = session['user_id'] if not name or not date or not priority: flash("All fields are required. Please try again.") return redirect(url_for('tasks')) else: db.add_task(userid, name, date, priority, 1) flash('New entry was successfully posted. Thanks.') return redirect(url_for('tasks'))
def tasks(): if request.method == 'POST': if not request.form['address']: flash('Enter site:') else: err, new_task = add_task(request.form['address']) if err: flash(str(err)) else: task_dict = { 'id': new_task.id, 'address': new_task.address } try: count_words.delay(task_dict) except Exception as e: task_dict['error'] = str(e) flash(task_dict['error']) err = add_result(task_dict, do_finished=False) if err: flash(str(err)) else: err = task_pending(new_task) if err: flash(str(err)) err, tasks = get_tasks() if err: flash(str(err)) tasks = [] return render_template('show_tasks.html', tasks = tasks)
def create_task_item(): global username #get the task details task_name_value = task_name.get() priority_of_task_value = priority_of_task.get() category_value = category.get() is_done_value = is_done.get() deadline_value=deadline.get() if inputs_validation(): item_values = (task_name_value, priority_of_task_value, category_value, is_done_value, deadline_value) item_id = db.add_task(item_values,username) tree.insert("", "end", item_id, text=item_id, values=(item_values[0], item_values[1], item_values[2], item_values[3], item_values[4])) task_name.set("") priority_of_task.set("") category.set("") deadline.set("") is_done.set(False) create_button["state"] = "normal" change_button["state"] = "disabled" notify()
def handle_adding_task(update: Update, context: CallbackContext): user = update.message.from_user task = update.message.text current_list = context.user_data["current_list"] if task == "Done": logger.info("User %s finished adding tasks to the list \"%s\"", user.first_name, current_list["name"]) tasks = db.get_tasks(current_list["id"]) update.message.reply_text(format_tasks(tasks), reply_markup=ReplyKeyboardRemove()) return ConversationHandler.END logger.info( "User %s added task \"%s\" to the list \"%s\"", user.first_name, task, current_list["name"], ) db.add_task(task, False, current_list["id"]) update.message.reply_text("Task added.") return conversations["add_tasks"]["handle_tasks"]
def tasks(): ''' Вывод всех результатов задач подсчета слов на сайтах (GET) Обработчик запросов адресов (POST) и так же вывод всех реультатов ''' if request.method == 'POST': if not request.form['address']: flash('Please enter Site') else: # пишем в базу данные поступившей задачи err, new_task = add_task(request.form['address']) if err: flash(str(err)) else: task_dict = {'id': new_task.id, 'address': new_task.address} # передача задачи через Celery по подсчету слов на сайте по введенному адресу # могут быть исключения, например, недоступен Redis у Celery try: count_words.delay(task_dict) except Exception as e: task_dict['error'] = str(e) flash(task_dict['error']) # в случае исключения при передачи задачи, # пишем в базу результат с ошибкой, но БЕЗ статуса "завершено" err = add_result(task_dict, do_finished=False) if err: flash(str(err)) else: # если задача передалась, то помечаем ее, как "ожидание результата" err = task_pending(new_task) if err: flash(str(err)) err, tasks = get_tasks() if err: flash(str(err)) tasks = [] return render_template('show_tasks.html', tasks=tasks)
def RunTask(wrapper): lock.acquire() # print request (do nothing right now) print(" Framework Name: " + wrapper.run_task.task.framework.name) print(" Framework ID: " + wrapper.run_task.task.framework.framework_id) print(" Task Name: " + wrapper.run_task.task.name) print(" Task ID: " + wrapper.run_task.task.task_id) print(" Selected Agent: " + wrapper.run_task.task.agent_id) for i in range(len(wrapper.run_task.task.resources)): resource = wrapper.run_task.task.resources[i] print(" Resource: (" + resource.name + ") type: " + str(resource.type) + " amt: " + str(resource.scalar).strip()) # Verify that the RunTaskRequest is on an unexpired offer of the right resources and try: offer = db.get_offer_by_offer_id(wrapper.run_task.offer_id) except ValueError: print("Not a valid offer ID") wrapper = messages_pb2.WrapperMessage() wrapper.type = messages_pb2.WrapperMessage.Type.ERROR wrapper.error.error = "Not a valid offer ID" lock.release() return wrapper.SerializeToString() #unexpired if time.time() > offer.expiration_time: print("Offer expired") wrapper = messages_pb2.WrapperMessage() wrapper.type = messages_pb2.WrapperMessage.Type.ERROR wrapper.error.error = "Offer Expired" lock.release() return wrapper.SerializeToString() #check for valid resources - just scalars for now for tresource in wrapper.run_task.task.resources: r = { x.name: (x.type, x.scalar, x.ranges, x.set, x.text, x.device) for x in offer.resources } if tresource.name not in r: print("Resource not in offer") wrapper = messages_pb2.WrapperMessage() wrapper.type = messages_pb2.WrapperMessage.Type.ERROR wrapper.error.error = "Resource not in offer" lock.release() return wrapper.SerializeToString() elif tresource.type != r[tresource.name][0]: print("Resource type doesn't match offer") wrapper = messages_pb2.WrapperMessage() wrapper.type = messages_pb2.WrapperMessage.Type.ERROR wrapper.error.error = "Resource type doesn't match offer" lock.release() return wrapper.SerializeToString() elif tresource.scalar.value and r[ tresource.name][1].value and tresource.scalar.value > r[ tresource.name][1].value: print("Resource value exceeds offer") wrapper = messages_pb2.WrapperMessage() wrapper.type = messages_pb2.WrapperMessage.Type.ERROR wrapper.error.error = "Resource value exceeds offer" lock.release() return wrapper.SerializeToString() # TODO: Forward the request onto the particular device through a ping/pong db.add_task(wrapper.run_task) # construct response wrapper = messages_pb2.WrapperMessage() wrapper.type = messages_pb2.WrapperMessage.Type.PONG wrapper.pong.agent_id = wrapper.run_task.task.agent_id lock.release() return wrapper.SerializeToString()
def enter_channel(m, summ): print(m.text) bot.send_message(m.chat.id, "Задание опубликовано!") db.add_task(summ, m.from_user.id, m.text)
async def add_task(message: types.Message): db.add_task(message.chat.id, message.text) await get_list(message)
def new_task(update, context): db.add_task(update.effective_user, pydo.Task(update.message.text)) context.bot.send_message(chat_id=update.effective_chat.id, text=f"created task: {update.message.text}")
def cli(): global parser global DB_FILENAME parser.add_argument( '--db-file', dest='db_file', action='store', default=DB_FILENAME, help='Specify SQLite DB file to be used (default: {}'.format( DB_FILENAME)) manage = parser.add_argument_group('Manage Tasks') manage.add_argument('-a', "--add", dest='task_definition', action='store', help='Add task') manage.add_argument('-Tn', "--task-name", dest='task_name', default="", action='store', help='') manage.add_argument('-Tt', "--task-type", dest='task_type', default="python", action='store', help='') manage.add_argument('-Tp', "--task-parameter", dest='task_parameter', default="", action='store', help='') manage = parser.add_argument_group('Run Tasks') manage.add_argument('-r', "--run", dest='run_single', default=0, action='count', help='Run task') manage.add_argument('-rL', "--run-loop", dest='run_loop', default=0, action='count', help='Run task in infinite loop') args = parser.parse_args() #Handle operations if args.task_definition: db.add_task(db_filename=args.db_file, definition=args.task_definition, tasktype=args.task_type, parameters=args.task_parameter) elif args.run_single: run_task(args.db_file) elif args.run_loop: while True: run_task(args.db_file) time.sleep(0.01) db.get_status(args.db_file)