def rpc_wildapricot_push(): if request.method == 'POST': pull_groups() json_data = request.get_json() user_ids = None if json_data: if 'user_ids' in json_data.keys(): user_ids = json_data['user_ids'] if current_user.get_task_in_progress('mcp.wildapricot.functions.push_users_task'): flash('A push task is currently in progress', 'warning') data = {'status': 'failure'} status = 400 else: current_user.launch_task('mcp.wildapricot.functions.push_users_task', 'Pushing user info to WA: ', 180, user_ids=user_ids) db.session.commit() data = {'status': 'success'} status = 200 response = current_app.response_class( response=json.dumps(data), status=status, mimetype='application/json' ) return response
def rpc_wildapricot_pull(): if request.method == 'POST': pull_groups() json_data = request.get_json() user_ids = updated_since = None if json_data: print(json_data) if 'user_ids' in json_data.keys(): user_ids = json_data['user_ids'] print('>>>>>>>>>>>>>>>>>>',user_ids) if 'updated_since' in json_data.keys(): updated_since = datetime.today() - timedelta(days=json_data['updated_since']) # updated_since = datetime.today()-timedelta(days=1) if current_user.get_task_in_progress('mcp.wildapricot.functions.pull_users_task'): flash('A pull task is currently in progress', 'warning') data = {'status': 'failure'} status = 400 else: current_user.launch_task('mcp.wildapricot.functions.pull_users_task', 'Pulling user info from WA: ', 300, user_ids=user_ids, updated_since=updated_since) db.session.commit() data = {'status': 'success'} status = 200 response = current_app.response_class( response=json.dumps(data), status=status, mimetype='application/json' ) return response
def process_project_route(id): """Launches a background job to process the project with the specified id. Parameters ---------- id : int The id of the project that should be processed. Returns ------- repsonse : str The jsonified response object. """ response_object = {'status': 'success'} if request.method == 'POST': with database.engine.begin() as connection: app = flask.current_app params = request.get_json()['params'] task = current_user.launch_task( 'morphocut.server.api.process_project', 'Processing project...', id, id, params) response_object['job_id'] = task.id print("return process") return jsonify(response_object), 202
def launch_task(name, description, *args, **kwargs): ''' Launches a task with the given function and args. Then launches a task which starts when the first one is finished, writing its results to the database. deprecated:: 14.04.2019 `tasks.launch_task` will be removed soon, it is replaced by User.launch_task `tasks.write_result` will be removed soon, it is replaced by User.launch_task ''' execute_and_save(name, description, 0, 0, *args, **kwargs) task, rq_job = current_user.launch_task(name, description, *args, **kwargs) database.session.commit() rq_job.meta['enqueued_at'] = datetime.datetime.now() # Need to look into this more. This should enqueue a job to write back the result right after the processing job is finished # but if some other job is enqueued before that, it is started before this writeback job even when this is enqueued at the front write_result_job = redis_queue.enqueue( 'morphocut.server.tasks.write_result', task.id, depends_on=rq_job, at_front=True) return task