Customizing Jobs


To create a custom job follow the steps explained below:

  1. Create a custom job file in citrix.cpbm.custom.common bundle.
  2. In the newly created custom job file, extend AbstractPortalJob and provide an implementation for the abstract run method.
    Below example shows the creation of custom job called "ResetLoginFailedAttempts" which will reset the login failed attempts for any user to 0 if the value exceeds 1, the logic for the same was implemented in run method.
    package com.citrix.cpbm.custom.job;  import java.util.List;  import org.quartz.JobExecutionContext;  import org.quartz.JobExecutionException;  import com.vmops.admin.jobs.AbstractPortalJob;  import com.vmops.model.User;  import com.vmops.model.UserAlertPreferences;  import com.vmops.service.UserAlertPreferencesService;  import com.vmops.service.UserService;  public class ResetLoginFailedAttemptsJob extends AbstractPortalJob {  	@Override  	public void run(JobExecutionContext context) throws JobExecutionException {  		System.err.println("@@@@@@@@@@@@@@@@@@ in custom job");  		List<User> usersList = userService.listUsers(0, 1000, null, null, true, null);  		for(User user : usersList){  			int loginAttempt = user.getFailedLoginAttempts();  			if(loginAttempt>1){  				user.setFailedLoginAttempts(0);  				userService.update(user);  			}  		}  }	}  
  3. Create a bean for the newly created custom job implementation class in applicationContext-Jobs.xml file present in src/main/resources/META-INF/spring.
    Below is the bean added for the above created custom job - "ResetLoginFailedAttempts".
    <bean name="resetLoginFailedAttemptsJob" class="org.springframework.scheduling.quartz.JobDetailBean">      <property name="jobClass" value="com.citrix.cpbm.custom.job.ResetLoginFailedAttemptsJob"/>      <property name="requestsRecovery" value="false"/>      <property name="volatility" value="false" />    </bean>  
  4. Create a trigger bean for the newly created custom job and specify job reference, time interval and other parameters.
    Below is the trigger bean created for the above custom job.
    <bean id="resetLoginFailedAttemptsJobTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">      <property name="jobDetail" ref="resetLoginFailedAttemptsJob" />       <property name="startDelay" value="10000" />      <property name="repeatInterval" value="1200000" />      <property name="volatility" value="false" />       <property name="misfireInstructionName" value="MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT"></property>    </bean>  
  5. Add the newly created trigger reference in applicationContext-scheduler.xml file present in src/main/resources/META-INF/spring under "triggers" property list.
    Below sample shows the adding of trigger reference:
    <ref bean="resetLoginFailedAttemptsJobTrigger"/>
또 다른 질문이 있으십니까? 문의 등록


Adding comment, please wait....

Provide Feedback on Article:

Zendesk 제공