背景
Apache DolphinScheduler 的定时任务配置使用 7 位 Crontab 表达式,分别对应秒、分、小时、日、月、周、年。
我们团队的日常开发工作中,工作流的时序调度一般不需要详细到秒级。但历史上也曾出现过因配置错误而导致故障的情况,比如原本应该每分钟执行一次的工作流被错误配置为每秒执行一次,导致短时间内生成大量工作流实例,影响工作效率。 Apache DolphinScheduler 服务和提交任务的 Hadoop 集群的可用性。
基于此,团队决定对DolphinScheduler的定时任务配置模块中的Crontab表达式进行限制,以防止此类事件在平台层面发生。
解决方案
我们的解决方案是从前端和后端都限制Crontab表达式的第一个位置:
- 前端配置不提供“每秒”选项
- 第一个位置为 * 时服务器端接口返回错误
前端修改
前端项目中,秒、分钟、小时都是统一的模板(CrontabTime),所以增加了一个新文件:dolphinscheduler-ui/src/components/crontab/modules/second.tsx
仅保留两种模式:intervalTime 和 SpecificTime
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import _ from 'lodash' import { defineComponent, onMounted, PropType, ref, toRefs, watch } from 'vue' import { NInputNumber, NRadio, NRadioGroup, NSelect } from 'naive-ui' import { useI18n } from 'vue-i18n' import { ICrontabI18n } from '../types' import { isStr, specificList } from '../common' import styles from '../index.module.scss' const props = { timeMin: { type: Number as PropType<number>, default: 0 }, timeMax: { type: Number as PropType<number>, default: 60 }, intervalPerform: { type: Number as PropType<number>, default: 5 }, intervalStart: { type: Number as PropType<number>, default: 3 }, timeSpecial: { type: Number as PropType<number string>, default: 60 }, timeValue: { type: String as PropType<string>, default: '*' }, timeI18n: { type: Object as PropType<icrontabi18n>, require: true } } export default defineComponent({ name: 'CrontabSecond', props, emits: ['update:timeValue'], setup(props, ctx) { const options = Array.from({ length: 60 }, (x, i) => ({ label: i.toString(), value: i })) const timeRef = ref() const radioRef = ref() const intervalStartRef = ref(props.intervalStart) const intervalPerformRef = ref(props.intervalPerform) const specificTimesRef = ref<array>>([]) /** * Parse parameter value */ const analyticalValue = () => { const $timeVal = props.timeValue // Interval time const $interval = isStr($timeVal, '/') // Specific time const $specific = isStr($timeVal, ',') // Positive integer (times) if ( ($timeVal.length === 1 || $timeVal.length === 2 || $timeVal.length === 4) && _.isInteger(parseInt($timeVal)) ) { radioRef.value = 'specificTime' specificTimesRef.value = [parseInt($timeVal)] return } // Interval times if ($interval) { radioRef.value = 'intervalTime' intervalStartRef.value = parseInt($interval[0]) intervalPerformRef.value = parseInt($interval[1]) timeRef.value = `${intervalStartRef.value}/${intervalPerformRef.value}` return } // Specific times if ($specific) { radioRef.value = 'specificTime' specificTimesRef.value = $specific.map((item) => parseInt(item)) return } } // Interval start time(1) const onIntervalStart = (value: number | null) => { intervalStartRef.value = value || 0 if (radioRef.value === 'intervalTime') { timeRef.value = `${intervalStartRef.value}/${intervalPerformRef.value}` } } // Interval execution time(2) const onIntervalPerform = (value: number | null) => { intervalPerformRef.value = value || 0 if (radioRef.value === 'intervalTime') { timeRef.value = `${intervalStartRef.value}/${intervalPerformRef.value}` } } // Specific time const onSpecificTimes = (arr: Array<number>) => { specificTimesRef.value = arr if (radioRef.value === 'specificTime') { specificReset() } } // Reset interval time const intervalReset = () => { timeRef.value = `${intervalStartRef.value}/${intervalPerformRef.value}` } // Reset specific time const specificReset = () => { let timeValue = '0' if (specificTimesRef.value.length) { timeValue = specificTimesRef.value.join(',') } timeRef.value = timeValue } const updateRadioTime = (value: string) => { switch (value) { case 'intervalTime': intervalReset() break case 'specificTime': specificReset() break } } watch( () => timeRef.value, () => ctx.emit('update:timeValue', timeRef.value.toString()) ) onMounted(() => analyticalValue()) return { options, radioRef, intervalStartRef, intervalPerformRef, specificTimesRef, updateRadioTime, onIntervalStart, onIntervalPerform, onSpecificTimes, ...toRefs(props) } }, render() { const { t } = useI18n() return ( <nradiogroup v-model:value="{this.radioRef}" onupdatevalue="{this.updateRadioTime}"> <div> <h3> Server-side </h3> <p>Add Crontab expression validation (there are two places: one is the new POST interface, and the other is the modified PUT interface), directly add a validation method for these two places to call:<br> </p> <pre class="brush:php;toolbar:false"> if (scheduleParam.getCrontab().startsWith("*")) { logger.error("The crontab must not start with *"); putMsg(result, Status.CRONTAB_EVERY_SECOND_ERROR); return result; }
本文到此结束。
以上是Apache DolphinScheduler 限制二级时序调度的详细内容。更多信息请关注PHP中文网其他相关文章!

JavaScript在网站、移动应用、桌面应用和服务器端编程中均有广泛应用。1)在网站开发中,JavaScript与HTML、CSS一起操作DOM,实现动态效果,并支持如jQuery、React等框架。2)通过ReactNative和Ionic,JavaScript用于开发跨平台移动应用。3)Electron框架使JavaScript能构建桌面应用。4)Node.js让JavaScript在服务器端运行,支持高并发请求。

Python更适合数据科学和自动化,JavaScript更适合前端和全栈开发。1.Python在数据科学和机器学习中表现出色,使用NumPy、Pandas等库进行数据处理和建模。2.Python在自动化和脚本编写方面简洁高效。3.JavaScript在前端开发中不可或缺,用于构建动态网页和单页面应用。4.JavaScript通过Node.js在后端开发中发挥作用,支持全栈开发。

C和C 在JavaScript引擎中扮演了至关重要的角色,主要用于实现解释器和JIT编译器。 1)C 用于解析JavaScript源码并生成抽象语法树。 2)C 负责生成和执行字节码。 3)C 实现JIT编译器,在运行时优化和编译热点代码,显着提高JavaScript的执行效率。

JavaScript在现实世界中的应用包括前端和后端开发。1)通过构建TODO列表应用展示前端应用,涉及DOM操作和事件处理。2)通过Node.js和Express构建RESTfulAPI展示后端应用。

JavaScript在Web开发中的主要用途包括客户端交互、表单验证和异步通信。1)通过DOM操作实现动态内容更新和用户交互;2)在用户提交数据前进行客户端验证,提高用户体验;3)通过AJAX技术实现与服务器的无刷新通信。

理解JavaScript引擎内部工作原理对开发者重要,因为它能帮助编写更高效的代码并理解性能瓶颈和优化策略。1)引擎的工作流程包括解析、编译和执行三个阶段;2)执行过程中,引擎会进行动态优化,如内联缓存和隐藏类;3)最佳实践包括避免全局变量、优化循环、使用const和let,以及避免过度使用闭包。

Python更适合初学者,学习曲线平缓,语法简洁;JavaScript适合前端开发,学习曲线较陡,语法灵活。1.Python语法直观,适用于数据科学和后端开发。2.JavaScript灵活,广泛用于前端和服务器端编程。

Python和JavaScript在社区、库和资源方面的对比各有优劣。1)Python社区友好,适合初学者,但前端开发资源不如JavaScript丰富。2)Python在数据科学和机器学习库方面强大,JavaScript则在前端开发库和框架上更胜一筹。3)两者的学习资源都丰富,但Python适合从官方文档开始,JavaScript则以MDNWebDocs为佳。选择应基于项目需求和个人兴趣。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

Atom编辑器mac版下载
最流行的的开源编辑器

SublimeText3 Linux新版
SublimeText3 Linux最新版

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

禅工作室 13.0.1
功能强大的PHP集成开发环境

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。