Browse Source

update cicd

lym 4 months ago
parent
commit
29aa482154
6 changed files with 160 additions and 4 deletions
  1. 7 4
      handleManager.py
  2. 43 0
      index.html
  3. 33 0
      test/fileServer.py
  4. 25 0
      test/fileServer_test.py
  5. 44 0
      test/move_mouse.py
  6. 8 0
      test/testIp6.py

+ 7 - 4
handleManager.py

@@ -19,11 +19,12 @@ handlerFileName = 'spider_result_handler'
 py_code_source_dir = os.environ.get('FAAS_CODE_DIR', 'F:/codes/python/clientSpider/')
 
 py_code_handler_path_list = [py_code_source_dir + handlerFileName]
+# 安全考虑,只能调用该目录下的方法,而不是任意模块方法,且作为 faas 服务内部约定,外部服务不需要感知该模块/目录名;但其目录下子目录/模块不做限制
 py_code_handler_module_prefix = handlerFileName + '.'
 
 # --------------------------------------约定------------------------------------------------------
-support_function_name = 'support'
-default_function_name = 'handle'
+faas_function_name__support = 'support'
+faas_function_name__handle = 'handle'
 
 const_key_function_id = "faas__function-id"
 const_key_request_wrap = "faas__request_wrap"
@@ -46,6 +47,7 @@ const_key_trace_id = "faas__trace_id"
 loaded_functions_cache = {}
 
 
+# todo 进程锁
 def load_functions(force_reload_module):
     """
     加载指定目录下的所有函数
@@ -73,6 +75,7 @@ def func_route(func_dic, func_name, args={}):
     """
     函数路由: 根据函数名执行调用
     """
+    # fixme 判断是否存在
     func = func_dic[func_name]
     print(func)
 
@@ -95,8 +98,8 @@ def handle(pycode_file_name, req):
 
     json_req = json.loads(req)
 
-    support_func_name = py_code_handler_module_prefix + "%s-%s" % (pycode_file_name, support_function_name)
-    pycode_function_id = py_code_handler_module_prefix + "%s-%s" % (pycode_file_name, default_function_name)
+    support_func_name = py_code_handler_module_prefix + "%s-%s" % (pycode_file_name, faas_function_name__support)
+    pycode_function_id = py_code_handler_module_prefix + "%s-%s" % (pycode_file_name, faas_function_name__handle)
 
     global loaded_functions_cache
 

+ 43 - 0
index.html

@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+    <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.6.0.js" type="text/javascript"></script>
+    <!-- <script src="./jquery-3.6.0.js" type="text/javascript"></script> -->
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+</head>
+
+<body>
+    <form id="uploadForm" action="/upload" enctype="multipart/form-data" method="post" onsubmit="return submitFile()">
+        <div><input type="file" name="file" multiple></div>
+        <br>
+        <div><input type="submit" value="upload"> </div>
+    </form>
+    <script>
+        function submitFile() {
+            // formData = new FormData($('#uploadForm')[0])
+            files = $('#uploadForm')[0].file.files
+            for (i = 0; i < files.length; i++) {
+                $.ajax({
+                    url: "/upload?fileName=" + encodeURIComponent(files[i].name),
+                    type: "POST",
+                    data: files[i],
+                    success: function (data) {
+                        console.info("success", data);
+                    },
+                    error: function (data) {
+                        console.warn("fail", data);
+                    },
+                    processData: false,
+                    contentType: "multipart/form-data",
+                    // contentType: "application/octet-stream"
+                });
+            }
+            return false;
+        }
+    </script>
+</body>
+
+</html>

+ 33 - 0
test/fileServer.py

@@ -0,0 +1,33 @@
+#!-*-encoding:utf-8-*-
+
+"""
+Faas 脚本定位函数
+"""
+
+from flask import Flask, request, send_file
+import os
+
+tmp_dir = '../uploads'
+key = 'simplepwd'
+
+app = Flask(__name__)
+
+@app.route('/upload', methods=['POST'])
+def upload():
+    file = request.files['file']
+    file.save(os.path.join(tmp_dir, file.filename))
+    return 'File uploaded successfully'
+
+@app.route('/download/<filename>', methods=['GET'])
+def download(filename):
+    #if not os.path.exists(os.path.join(tmp_dir, filename)):
+    #    return send_file(os.path.join(tmp_dir, filename), as_attachment=True)
+    #else:
+    return send_file(os.path.join(tmp_dir, filename), as_attachment=True)
+
+if not os.path.exists(tmp_dir):
+    os.makedirs(tmp_dir)
+
+if __name__ == '__main__':
+    app.run(debug=False)
+

+ 25 - 0
test/fileServer_test.py

@@ -0,0 +1,25 @@
+#!-*-encoding:utf-8-*-
+
+"""
+Faas 脚本定位函数
+"""
+import time
+import requests
+import os
+
+baseAddress = 'http://localhost:5000'
+
+def download_file(file_id):
+    req_start_time = time.time()
+    r = requests.get(baseAddress + '/download/' + file_id)
+    req_cost = time.time() - req_start_time
+    return r.content
+
+def upload_file(file_id, file):
+    req_start_time = time.time()
+    r = requests.post(baseAddress + '/download/' + file_id)
+    req_cost = time.time() - req_start_time
+
+
+if __name__ == '__main__':
+    download_file('')

+ 44 - 0
test/move_mouse.py

@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+# !-*-coding:utf-8 -*-
+import time
+import pyautogui
+
+if __name__ == '__main__':
+    time.sleep(2)
+    x1, y2 = pyautogui.position()
+    while True:
+        x, y = pyautogui.position()
+        pyautogui.leftClick()
+        time.sleep(0.5)
+        if abs(x - x1) > 50:
+            break
+        pyautogui.leftClick()
+
+
+    # while i < 16:
+    #     # 5秒钟移动一次鼠标(移动鼠标时间可以根据自己需要设定)
+    #     pyautogui.moveTo(x=165, y=510)
+    #     pyautogui.leftClick()
+    #     time.sleep(0.5)
+    #     x, y = pyautogui.position()
+    #     if abs(x - 165) > 50:
+    #         break
+    #     pyautogui.moveTo(x=500, y=700)
+    #     pyautogui.leftClick()
+    #     time.sleep(0.5)
+    #     x, y = pyautogui.position()
+    #     if abs(x - 500) > 50:
+    #         break
+    #     pyautogui.moveTo(x=280, y=222)
+    #     pyautogui.leftClick()
+    #     time.sleep(0.5)
+    #     x, y = pyautogui.position()
+    #     if abs(x - 280) > 50:
+    #         break
+    #     pyautogui.moveTo(x=985, y=700)
+    #     pyautogui.leftClick()
+    #     time.sleep(0.5)
+    #     x, y = pyautogui.position()
+    #     if abs(x - 985) > 50:
+    #         break
+    #     i = i + 1

+ 8 - 0
test/testIp6.py

@@ -0,0 +1,8 @@
+import socket
+
+
+def get_ipv6_address():
+    return socket.getaddrinfo(None, None, socket.AF_INET6)
+
+if __name__ == '__main__':
+    print(get_ipv6_address())