Codeworld-cloud-shop XXl-Job Dynamic Task Creation Detail 1– Wet Nurse Level Teaching

preface

In codeWorld-Cloud-Shop xxL-Job Primer, we cover the basics of XXL-Job. If you haven’t already done it, do a little wet nurse teaching before moving on to the next level

To explore problems

Although we demonstrated the basic use of XXL-Job task scheduling in the entry-level teaching, we also realized the superiority of XXL-Job and the simplicity of page operation so that we can directly start and stop tasks on the interface, which made me very comfortable, but the terrible thing came

We had a requirement, for example, in the project

In mall homepage, we have a round figure, so this round of play is to switch from time to time, we may at any time in a specified time figure information update this round of play So the question comes, when we add them by figure will give him to specify a time online and offline, there may be a lot of shuffling figure to add, Do we add a task to xxL-job’s visual interface every time we add a wheel map? So we can keep our hands on it? Also, I have to go online at the time of 2021-01-01:12:05:35, so are we going to write CRON expression to perform the task? Then I think you are really patient, with an offline time attached, online and offline time are different.

So how do we solve this?

Problem solving

First of all, don’t panic. The best way to eliminate fear is to face it, Ollie

First let’s look atThe xxL-job-admin interface is the same as the xxL-job-admin interface. The xxL-job-admin interface is the same as the xxL-job-admin interfaceSo let’s go all the way down to the implementation class method of the add Task interface and we can see that the parameter passed in is this XxlJobInfo

private int id;				/ / the primary key ID
	
	private int jobGroup;		// Primary key ID of the actuator
	private String jobDesc;
	
	private Date addTime;
	private Date updateTime;
	
	private String author;		/ / head
	private String alarmEmail;	// Alarm email

	private String scheduleType;			// Scheduling type
	private String scheduleConf;			// Scheduling configuration, value meaning depends on scheduling type
	private String misfireStrategy;			// Schedule expiration policies

	private String executorRouteStrategy;	// Execute the routing policy
	private String executorHandler;		    // Executor, task Handler name
	private String executorParam;		    // Actuator, task parameters
	private String executorBlockStrategy;	// Block processing policy
	private int executorTimeout;     		// Task execution timeout duration, in seconds
	private int executorFailRetryCount;		// Number of failed retries
	
	private String glueType;		/ / GLUE type # com. XXL. Job. Core. GLUE. GlueTypeEnum
	private String glueSource;		// GLUE source code
	private String glueRemark;		/ / GLUE remark
	private Date glueUpdatetime;	// GLUE update time

	private String childJobId;		// Subtask ID, separated by multiple commas

	private int triggerStatus;		// Scheduling status: 0- Stopped, 1- running
	private long triggerLastTime;	// Last dispatch time
	private long triggerNextTime;	// Next schedule time
Copy the code

There’s a lot of parameter information in there, it’s all very clear so let’s think about it, let’s think about the interface has parameter information and we know it, so we can just call the interface and pass in the parameter information we want, ok? So we don’t have to go to the visual interface for operation, that is not ok?

It seems to mean this, so how should we operate?

Xxl-job is on a different project, and ours is on a different project, so how can we call this interface?

So remote call, and here we’re using RestTemplate to implement the call you can consider using openFeign.

problems

So there’s another problem with this, first we’re going to do it on the interface, right? So what’s the first step to get to the interface? To log in. Yes, the login will not use our interfaces until it is logged in. If it is not logged in, it will be blockedWe can clearly see here that there’s an interceptor set up for the interface so there’s a very clear comment in therePermissionLimit

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface PermissionLimit {
	
	/** * Login intercept (default intercept) */
	boolean limit(a) default true;

	/** * Requires administrator privileges **@return* /
	boolean adminuser(a) default false;

}
Copy the code

There’s a limit property, the default is true, which means if you set limit to true you need to be blocked, you need to be logged in to call it so we thought if you set limit to false, you don’t need to log in to call it yes, we do that here so we need to write a new interface, Then add this annotation to the interface and set it to false

So we’ve basically solved our problem here and the process is

1. Create a new interface based on the xxl-job-admin project, add 'PermissionLimit' and set it to false 2. The RestTemplate is used to make remote calls to add tasksCopy the code

So we will continue the codeWorld-Cloud-Shop xxl-Job dynamic Task creation tutorial in the next section. Ok, that’s the end of this technical analysis? Codeworld-cloud-shop light up the star if you like!!

Welcome to join QQ group (964285437)