Przeglądaj źródła

【新增】GLUE模式(Python) 扩展,可选 "GLUE(Python3)" 或 "GLUE(Python2)" 两种模式,分别支持 python3/2 多版本;

xuxueli 2 miesięcy temu
rodzic
commit
8eff07d7ab

+ 1 - 0
doc/XXL-JOB官方文档.md

@@ -2554,6 +2554,7 @@ public void execute() {
 - 8、【修复】合并PR-3506,修复小概率情况下任务重复调度问题;
 - 9、【修复】合并PR-3747,修复异常情况下资源泄漏风险;
 - 10、【优化】调度中心系统日志调整,支持启动时指定 -DLOG_HOME 参数自定义日志位置;同时优化日志格式提升易读性;
+- 11、【新增】GLUE模式(Python) 扩展,可选 "GLUE(Python3)" 或 "GLUE(Python2)" 两种模式,分别支持 python3/2 多版本;  
 
 - 3、【规划中】登录安全升级,密码加密处理算法从Md5改为Sha256;
 ```

+ 2 - 0
xxl-job-admin/src/main/resources/static/js/jobinfo.index.1.js

@@ -519,6 +519,8 @@ $(function() {
 			$("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_shell").val() );
 		} else if ('GLUE_PYTHON'==glueType){
 			$("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_python").val() );
+		} else if ('GLUE_PYTHON2'==glueType){
+			$("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_python2").val() );
 		} else if ('GLUE_PHP'==glueType){
             $("#addModal .form textarea[name='glueSource']").val( $("#addModal .form .glueSource_php").val() );
         } else if ('GLUE_NODEJS'==glueType){

+ 3 - 0
xxl-job-admin/src/main/resources/templates/jobcode/jobcode.index.ftl

@@ -133,6 +133,9 @@
     <#elseif jobInfo.glueType == "GLUE_PYTHON" >
         <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/python/python.js" />
         <#assign glueTypeIdeMode = "text/x-python" />
+    <#elseif jobInfo.glueType == "GLUE_PYTHON2" >
+        <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/python/python.js" />
+        <#assign glueTypeIdeMode = "text/x-python" />
     <#elseif jobInfo.glueType == "GLUE_PHP" >
         <#assign glueTypeModeSrc = "${request.contextPath}/static/plugins/codemirror/mode/php/php.js" />
         <#assign glueTypeIdeMode = "text/x-php" />

+ 16 - 1
xxl-job-admin/src/main/resources/templates/jobinfo/jobinfo.index.ftl

@@ -281,6 +281,22 @@ exit 0
 import time
 import sys
 
+print("xxl-job: hello python")
+
+print("${I18n.jobinfo_script_location}:", sys.argv[0])
+print("${I18n.jobinfo_field_executorparam}:", sys.argv[1])
+print("${I18n.jobinfo_shard_index}:", sys.argv[2])
+print("${I18n.jobinfo_shard_total}:", sys.argv[3])
+
+print("Good bye!")
+exit(0)
+</textarea>
+<textarea class="glueSource_python2" style="display:none;" >
+#!/usr/bin/python
+# -*- coding: UTF-8 -*-
+import time
+import sys
+
 print "xxl-job: hello python"
 
 print "${I18n.jobinfo_script_location}:", sys.argv[0]
@@ -299,7 +315,6 @@ logging.basicConfig(level=logging.DEBUG)
 logging.info("脚本文件:" + sys.argv[0])
 -->
 </textarea>
-<#--这里有问题,新建一个运行模式为 php 的任务后,GLUE 中没有下边的 php 代码-->
 <textarea class="glueSource_php" style="display:none;" >
 <?php
 

+ 4 - 3
xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueTypeEnum.java

@@ -8,10 +8,11 @@ public enum GlueTypeEnum {
     BEAN("BEAN", false, null, null),
     GLUE_GROOVY("GLUE(Java)", false, null, null),
     GLUE_SHELL("GLUE(Shell)", true, "bash", ".sh"),
-    GLUE_PYTHON("GLUE(Python)", true, "python", ".py"),
-    GLUE_PHP("GLUE(PHP)", true, "php", ".php"),
+    GLUE_PYTHON("GLUE(Python3)", true, "python3", ".py"),
+    GLUE_PYTHON2("GLUE(Python2)", true, "python", ".py"),
     GLUE_NODEJS("GLUE(Nodejs)", true, "node", ".js"),
-    GLUE_POWERSHELL("GLUE(PowerShell)", true, "powershell", ".ps1");
+    GLUE_POWERSHELL("GLUE(PowerShell)", true, "powershell", ".ps1"),
+    GLUE_PHP("GLUE(PHP)", true, "php", ".php");
 
     private String desc;
     private boolean isScript;

+ 5 - 7
xxl-job-executor-samples/xxl-job-executor-sample-springboot-ai/src/main/resources/logback.xml

@@ -2,28 +2,26 @@
 <configuration debug="false" scan="true" scanPeriod="1 seconds">
 
     <contextName>logback</contextName>
-    <property name="log.path" value="/data/applogs/xxl-job/xxl-job-executor-sample-springboot-ai.log"/>
-
+    <property name="log.path" value="${LOG_HOME:-/data/applogs}/xxl-job/xxl-job-executor-sample-springboot-ai.log" />
     <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
         <encoder>
-            <pattern>%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
+            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
         </encoder>
     </appender>
 
     <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
         <file>${log.path}</file>
         <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
-            <fileNamePattern>${log.path}.%d{yyyy-MM-dd}.zip</fileNamePattern>
+            <fileNamePattern>${log.path}.%d{yyyy-MM-dd}.log</fileNamePattern>
         </rollingPolicy>
         <encoder>
-            <pattern>%date %level [%thread] %logger{36} [%file : %line] %msg%n
-            </pattern>
+            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
         </encoder>
     </appender>
 
     <root level="info">
         <appender-ref ref="console"/>
-        <appender-ref ref="file"/>
+        <!--<appender-ref ref="file"/>-->
     </root>
 
 </configuration>

+ 5 - 7
xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/resources/logback.xml

@@ -2,28 +2,26 @@
 <configuration debug="false" scan="true" scanPeriod="1 seconds">
 
     <contextName>logback</contextName>
-    <property name="log.path" value="/data/applogs/xxl-job/xxl-job-executor-sample-springboot.log"/>
-
+    <property name="log.path" value="${LOG_HOME:-/data/applogs}/xxl-job/xxl-job-executor-sample-springboot.log" />
     <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
         <encoder>
-            <pattern>%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
+            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
         </encoder>
     </appender>
 
     <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
         <file>${log.path}</file>
         <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
-            <fileNamePattern>${log.path}.%d{yyyy-MM-dd}.zip</fileNamePattern>
+            <fileNamePattern>${log.path}.%d{yyyy-MM-dd}.log</fileNamePattern>
         </rollingPolicy>
         <encoder>
-            <pattern>%date %level [%thread] %logger{36} [%file : %line] %msg%n
-            </pattern>
+            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
         </encoder>
     </appender>
 
     <root level="info">
         <appender-ref ref="console"/>
-        <appender-ref ref="file"/>
+        <!--<appender-ref ref="file"/>-->
     </root>
 
 </configuration>