def redis_callback(t): req = t.get_req() resp = t.get_resp() state = t.get_state() error = t.get_error() if state != wf.WFT_STATE_SUCCESS: print("state:{} error:{} errstr:{}".format( state, error, wf.get_error_string(state, error))) return else: val = resp.get_result() if val.is_error(): print("Error reply. Need a password?") return cmd = req.get_command() if cmd == "SET": user_data = t.get_user_data() n = wf.create_redis_task(user_data.url, retry_max=2, callback=redis_callback) n.get_req().set_request("GET", [user_data.key]) wf.series_of(t).push_back(n) print("Redis SET request success. Trying to GET...") else: if val.is_string(): print("Redis GET success. Value = {}".format(val.string_value())) else: print("Error. Not a string value") print("Finish")
def http_callback(t): req = t.get_req() resp = t.get_resp() state = t.get_state() error = t.get_error() if state != wf.WFT_STATE_SUCCESS: print("http: state:{} error:{} errstr:{}".format( state, error, wf.get_error_string(state, error))) return body_len = resp.get_body_size() if body_len == 0: print("Error: empty Http body!") return series = wf.series_of(t) context = series.get_context() context.body_len = body_len redis_url = context.redis_url redis_task = wf.create_redis_task(redis_url, retry_max=2, callback=redis_callback) redis_task.get_req().set_request( "SET", [context.http_url, resp.get_body()]) series.push_back(redis_task)
def mysql_callback(task): state = task.get_state() error = task.get_error() if state != wf.WFT_STATE_SUCCESS: print(wf.get_error_string(state, error)) return resp = task.get_resp() cursor = wf.MySQLResultCursor(resp) for result_set in wf.MySQLResultSetIterator(cursor): if result_set.get_cursor_status() == wf.MYSQL_STATUS_GET_RESULT: fields = result_set.fetch_fields() print(header_line(len(fields))) print(format_row(fields)) print(header_line(len(fields))) for row in wf.MySQLRowIterator(result_set): print(format_row(row)) print(header_line(len(fields))) print("{} {} in set\n".format( result_set.get_rows_count(), "row" if result_set.get_rows_count() == 1 else "rows")) elif result_set.get_cursor_status() == wf.MYSQL_STATUS_OK: print("OK. {} {} affected. {} warnings. insert_id={}. {}".format( result_set.get_affected_rows(), "row" if result_set.get_affected_rows() == 1 else "rows", result_set.get_warnings(), result_set.get_insert_id(), as_str(result_set.get_info()))) if resp.get_packet_type() == wf.MYSQL_PACKET_OK: print("OK. {} {} affected. {} warnings. insert_id={}. {}".format( resp.get_affected_rows(), "row" if resp.get_affected_rows() == 1 else "rows", resp.get_warnings(), resp.get_last_insert_id(), as_str(resp.get_info()))) elif resp.get_packet_type() == wf.MYSQL_PACKET_ERROR: print("ERROR. error_code={} {}".format(resp.get_error_code(), as_str(resp.get_error_msg()))) url = wf.series_of(task).get_context() next_task = create_next_task(url, mysql_callback) if next_task is not None: wf.series_of(task).push_back(next_task) pass
def redis_callback(t): req = t.get_req() resp = t.get_resp() state = t.get_state() error = t.get_error() if state != wf.WFT_STATE_SUCCESS: print("redis: state:{} error:{} errstr:{}".format( state, error, wf.get_error_string(state, error))) return else: val = resp.get_result() if val.is_error(): print("Error reply. Need a password?") return context = wf.series_of(t).get_context() print("redis SET success: key: {}, value size: {}".format( context.http_url, context.body_len)) context.success = True
def wget_callback(t): req = t.get_req() resp = t.get_resp() state = t.get_state() error = t.get_error() if state != wf.WFT_STATE_SUCCESS: print("state:{} error:{} errstr:{}".format( state, error, wf.get_error_string(state, error))) return print("{} {} {}".format(req.get_method(), req.get_http_version(), req.get_request_uri())) req_headers = req.get_headers() for h in req_headers: print("{}: {}".format(h[0], h[1])) print("") print("{} {} {}".format(resp.get_http_version(), resp.get_status_code(), resp.get_reason_phrase())) headers = resp.get_headers() for h in headers: print("{}: {}".format(h[0], h[1])) print("\nbody size:{} (ignore body for a clear output)".format( len(resp.get_body())))