Procházet zdrojové kódy

!721 任务调度新增执行作业
Merge pull request !721 from 一克猫/next

zuohuaijun před 2 roky
rodič
revize
03a92f1014

+ 6 - 0
Admin.NET/Admin.NET.Core/Enum/ErrorCodeEnum.cs

@@ -520,6 +520,12 @@ public enum ErrorCodeEnum
     [ErrorCodeItemMetadata("禁止修改作业编号")]
     D1704,
 
+    /// <summary>
+    /// 执行作业失败
+    /// </summary>
+    [ErrorCodeItemMetadata("执行作业失败")]
+    D1705,
+
     /// <summary>
     /// 已存在同名打印模板
     /// </summary>

+ 11 - 0
Admin.NET/Admin.NET.Core/Service/Job/SysJobService.cs

@@ -279,6 +279,17 @@ public class SysJobService : IDynamicApiController, ITransient
         scheduler?.Start();
     }
 
+    /// <summary>
+    /// 执行作业
+    /// </summary>
+    /// <param name="input"></param>
+    [DisplayName("执行作业")]
+    public void RunJob(JobDetailInput input)
+    {
+        if (_schedulerFactory.TryRunJob(input.JobId) != ScheduleResult.Succeed)
+            throw Oops.Oh(ErrorCodeEnum.D1705);
+    }
+
     /// <summary>
     /// 暂停触发器
     /// </summary>

+ 83 - 0
Web/src/api-services/apis/sys-job-api.ts

@@ -590,6 +590,54 @@ export const SysJobApiAxiosParamCreator = function (configuration?: Configuratio
                 options: localVarRequestOptions,
             };
         },
+        /**
+         * 
+         * @summary 执行作业
+         * @param {JobDetailInput} [body] 
+         * @param {*} [options] Override http request option.
+         * @throws {RequiredError}
+         */
+        apiSysJobRunJobPost: async (body?: JobDetailInput, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
+            const localVarPath = `/api/sysJob/runJob`;
+            // use dummy base URL string because the URL constructor only accepts absolute URLs.
+            const localVarUrlObj = new URL(localVarPath, 'https://example.com');
+            let baseOptions;
+            if (configuration) {
+                baseOptions = configuration.baseOptions;
+            }
+            const localVarRequestOptions :AxiosRequestConfig = { method: 'POST', ...baseOptions, ...options};
+            const localVarHeaderParameter = {} as any;
+            const localVarQueryParameter = {} as any;
+
+            // authentication Bearer required
+            // http bearer authentication required
+            if (configuration && configuration.accessToken) {
+                const accessToken = typeof configuration.accessToken === 'function'
+                    ? await configuration.accessToken()
+                    : await configuration.accessToken;
+                localVarHeaderParameter["Authorization"] = "Bearer " + accessToken;
+            }
+
+            localVarHeaderParameter['Content-Type'] = 'application/json-patch+json';
+
+            const query = new URLSearchParams(localVarUrlObj.search);
+            for (const key in localVarQueryParameter) {
+                query.set(key, localVarQueryParameter[key]);
+            }
+            for (const key in options.params) {
+                query.set(key, options.params[key]);
+            }
+            localVarUrlObj.search = (new URLSearchParams(query)).toString();
+            let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
+            localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
+            const needsSerialization = (typeof body !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json';
+            localVarRequestOptions.data =  needsSerialization ? JSON.stringify(body !== undefined ? body : {}) : (body || "");
+
+            return {
+                url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash,
+                options: localVarRequestOptions,
+            };
+        },
         /**
          * 
          * @summary 启动所有作业
@@ -998,6 +1046,20 @@ export const SysJobApiFp = function(configuration?: Configuration) {
                 return axios.request(axiosRequestArgs);
             };
         },
+        /**
+         * 
+         * @summary 执行作业
+         * @param {JobDetailInput} [body] 
+         * @param {*} [options] Override http request option.
+         * @throws {RequiredError}
+         */
+        async apiSysJobRunJobPost(body?: JobDetailInput, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise<AxiosResponse<void>>> {
+            const localVarAxiosArgs = await SysJobApiAxiosParamCreator(configuration).apiSysJobRunJobPost(body, options);
+            return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
+                const axiosRequestArgs :AxiosRequestConfig = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
+                return axios.request(axiosRequestArgs);
+            };
+        },
         /**
          * 
          * @summary 启动所有作业
@@ -1192,6 +1254,16 @@ export const SysJobApiFactory = function (configuration?: Configuration, basePat
         async apiSysJobPersistAllPost(options?: AxiosRequestConfig): Promise<AxiosResponse<void>> {
             return SysJobApiFp(configuration).apiSysJobPersistAllPost(options).then((request) => request(axios, basePath));
         },
+        /**
+         * 
+         * @summary 执行作业
+         * @param {JobDetailInput} [body] 
+         * @param {*} [options] Override http request option.
+         * @throws {RequiredError}
+         */
+        async apiSysJobRunJobPost(body?: JobDetailInput, options?: AxiosRequestConfig): Promise<AxiosResponse<void>> {
+            return SysJobApiFp(configuration).apiSysJobRunJobPost(body, options).then((request) => request(axios, basePath));
+        },
         /**
          * 
          * @summary 启动所有作业
@@ -1379,6 +1451,17 @@ export class SysJobApi extends BaseAPI {
     public async apiSysJobPersistAllPost(options?: AxiosRequestConfig) : Promise<AxiosResponse<void>> {
         return SysJobApiFp(this.configuration).apiSysJobPersistAllPost(options).then((request) => request(this.axios, this.basePath));
     }
+    /**
+     * 
+     * @summary 执行作业
+     * @param {JobDetailInput} [body] 
+     * @param {*} [options] Override http request option.
+     * @throws {RequiredError}
+     * @memberof SysJobApi
+     */
+    public async apiSysJobRunJobPost(body?: JobDetailInput, options?: AxiosRequestConfig) : Promise<AxiosResponse<void>> {
+        return SysJobApiFp(this.configuration).apiSysJobRunJobPost(body, options).then((request) => request(this.axios, this.basePath));
+    }
     /**
      * 
      * @summary 启动所有作业

+ 10 - 1
Web/src/views/system/job/index.vue

@@ -172,11 +172,14 @@
 					</template>
 				</el-table-column>
 				<el-table-column prop="jobDetail.updatedTime" label="更新时间" width="130" align="center" show-overflow-tooltip />
-				<el-table-column label="操作" width="170" fixed="right" align="center" show-overflow-tooltip>
+				<el-table-column label="操作" width="220" fixed="right" align="center" show-overflow-tooltip>
 					<template #default="scope">
 						<el-tooltip content="增加触发器">
 							<el-button size="small" type="primary" icon="ele-CirclePlus" text @click="openAddJobTrigger(scope.row)"> </el-button>
 						</el-tooltip>
+						<el-tooltip content="执行作业">
+							<el-button size="small" type="primary" icon="ele-CircleCheck" text @click="runJob(scope.row)" />
+						</el-tooltip>
 						<el-tooltip content="启动作业">
 							<el-button size="small" type="primary" icon="ele-VideoPlay" text @click="startJob(scope.row)" />
 						</el-tooltip>
@@ -350,6 +353,12 @@ const pauseAllJob = async () => {
 	ElMessage.success('暂停所有作业');
 };
 
+// 执行某个作业
+const runJob = async (row: JobOutput) => {
+	await getAPI(SysJobApi).apiSysJobRunJobPost({ jobId: row.jobDetail?.jobId });
+	ElMessage.success('执行作业');
+};
+
 // 启动某个作业
 const startJob = async (row: JobOutput) => {
 	await getAPI(SysJobApi).apiSysJobStartJobPost({ jobId: row.jobDetail?.jobId });