In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to simpleTrigger xxl-job and dynamically create task extensions. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Business scenario
On the demand, it is required to realize the simpleTrigger task of quartz, and at the same time, it also needs to create the task dynamically rather than on the control panel. Referring to the official documents of xxl-job, it is found that simpelTrigger is still lying in to do list, while dynamic creation can call JobInfoController's add and start interfaces (but there is a drawback. Start/stop/remove and other methods only require the transmission of id, which can be implemented by your own extension interface), and you also need to release login permissions. Then the old man went up and went on the shuttle and started to work.
Job_info field adjustment description: CREATE TABLE `int (11) NOT NULL AUTO_INCREMENT, `job_ group` int (11) NOT NULL COMMENT 'executor key ID', `job_ cron`varchar (12885) DEFAULT NULL COMMENT' task executes CRON', `job_ times` varchar, `update_ time`datetime DEFAULT NULL, `author`varchar (64) DEFAULT NULL COMMENT 'author', `alarm_ email` varchar (255) DEFAULT NULL COMMENT 'alarm email' `varchar varchar (50) DEFAULT NULL COMMENT 'executor routing policy', `executor_ handler` varchar 'executor task handler', `executor_ param`varchar (512) DEFAULT NULL COMMENT' executor task parameter', `executor_block_ containgy`varchar (50) DEFAULT NULL COMMENT 'blocking processing policy', `executor_ timeout`int (11) NOT NULL DEFAULT'0' COMMENT 'task execution timeout Unit second', 'executor_fail_retry_ count` int (11) NOT NULL DEFAULT' 0' COMMENT 'failed retries', 'glue_ type` varchar (50) NOT NULL COMMENT' GLUE type', 'glue_ source`mediumtext COMMENT' GLUE source code', `glue_ remark` varchar (128) DEFAULT NULL COMMENT 'GLUE remarks', `glue_ updatetime`datetime DEFAULT NULL COMMENT 'GLUE update time', `child_ jobid`varchar 'subtask ID Multiple commas separated', `ext_ reamrk` varchar (25525) DEFAULT NULL, `job_repeat_ time`bigint (20) DEFAULT NULL COMMENT 'trigger start time in milliseconds, `job_end_ time`datetime DEFAULT NULL COMMENT' trigger end time', `job_repeat_ count`bigint'- 1 'COMMENT' simple_trigger execution times', `job_repeat_ interval`bigint (12) DEFAULT NULL COMMENT 'simple_trigger interval unit millisecond' PRIMARY KEY (`id`) USING BTREE) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
Job_cron is set to empty and simpleTrigger is supported
Ext_reamrk custom extension field, according to which you can select job to avoid having only id as a parameter in the start/stop/remove interface.
The number of times job_repeat_count,simplerTrigger is executed. By default,-1 means unlimited times. If 0, it is executed once.
Interval between each execution of job_repeat_interval,simplerTrigger (in milliseconds)
Interval between job_start_time,trigger start time and current time (in milliseconds)
Job_end_time,trigger end time
Rewrite startup task
When xxl-job creates a new task, it only saves the job data to the database, creates jobDetail and trigger only when it starts, and scheduler starts job.
Override the addJob method of XxlJobDynamicScheduler: build the trigger of cron or the trigger of simple based on the values in jobInfo.
Public static boolean addJob (XxlJobInfo xxlJobInfo) throws SchedulerException {String jobName = String.valueOf (xxlJobInfo.getId ()); String cronExpression = xxlJobInfo.getJobCron (); Integer jobRepeatCount = xxlJobInfo.getJobRepeatCount (); Long jobRepeatInterval = xxlJobInfo.getJobRepeatInterval (); / / 1, job key TriggerKey triggerKey = TriggerKey.triggerKey (jobName); JobKey jobKey = new JobKey (jobName) / / 2, valid trigger if (scheduler.checkExists (triggerKey)) {return true;} / / 3.1, corn trigger Trigger trigger = null; if (! StringUtils.isEmpty (cronExpression)) {CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule (cronExpression). WithMisfireHandlingInstructionDoNothing () / / withMisfireHandlingInstructionDoNothing ignores scheduling TriggerBuilder builder = TriggerBuilder.newTrigger (). WithIdentity (triggerKey) .withschedule (cronScheduleBuilder) .endat (xxlJobInfo.getJobEndTime ()); Optional.ofNullable (xxlJobInfo.getJobStartTime ()) .ifPresent (start-> builder.startAt (new Date (System.currentTimeMillis () + start) Trigger = builder.build ();} else / / 3.2and simple trigger if (Objects.nonNull (jobRepeatInterval) & & Objects.nonNull (jobRepeatCount)) {SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule () .withIntervalInMillisec onds (jobRepeatInterval) .withRepeatCount (jobRepeatCount) TriggerBuilder builder = TriggerBuilder.newTrigger () .withIdentity (triggerKey) .withschedule (simpleScheduleBuilder) .endat (xxlJobInfo.getJobEndTime ()); Optional.ofNullable (xxlJobInfo.getJobStartTime ()) .ifPresent (start-> builder.startAt (new Date (System.currentTimeMillis () + start)); trigger = builder.build () Valid trigger if (Objects.isNull (trigger)) {return true;} / / 4, job detail Class
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.