Hybris (6) Cron Job

Submitted by Lizhe on Fri, 02/01/2019 - 15:36

 

首先新建一个job类

/lizhebuglist/src/name/lizhe/job/SendBuglistMailJob.java

/*
 * [y] hybris Platform
 * 
 * Copyright (c) 2000-2019 SAP SE
 * All rights reserved.
 * 
 * This software is the confidential and proprietary information of SAP 
 * Hybris ("Confidential Information"). You shall not disclose such 
 * Confidential Information and shall use it only in accordance with the 
 * terms of the license agreement you entered into with SAP Hybris.
 */
package name.lizhe.job;

import de.hybris.platform.cronjob.enums.CronJobResult;
import de.hybris.platform.cronjob.enums.CronJobStatus;
import de.hybris.platform.cronjob.model.CronJobModel;
import de.hybris.platform.servicelayer.cronjob.AbstractJobPerformable;
import de.hybris.platform.servicelayer.cronjob.PerformResult;

import java.util.Date;

/**
 *
 */
public class SendBuglistMailJob extends AbstractJobPerformable<CronJobModel>
{
  
 
    @Override
    public PerformResult perform(final CronJobModel cronJob)
    {
        System.out.println("test cron job..."+new Date().toGMTString());
       return new PerformResult(CronJobResult.SUCCESS, CronJobStatus.FINISHED);
    }

}

 

把这个job 注册给 spring ioc 容器

/lizhebuglist/resources/lizhebuglist-spring.xml

<bean id="sendBuglistMailJob" class="name.lizhe.job.SendBuglistMailJob" autowire="byName"/>

 

访问 https://electronics.local:9002/platform/update

把 除了 Create essential data 之外的 所有 checkbox 全部 uncheck , 点击update

20190201034118

 

检查一下

select {code} from {servicelayerjob} where {code} = 'sendBuglistMailJob'

20190201033827

 

20190201033820

 

现在去导入Impex 激活这个job

INSERT_UPDATE CronJob; code[unique=true];job(code);singleExecutable;sessionLanguage(isocode)

; sendBuglistMailCronJob; sendBuglistMailJob;false;de

 

INSERT_UPDATE Trigger;cronjob(code)[unique=true];cronExpression

#% afterEach: impex.getLastImportedItem().setActivationTime(new Date());

; sendBuglistMailCronJob; 0 0 0 * * ?

每隔5秒执行一次:*/5 * * * * ?

每隔1分钟执行一次:0 */1 * * * ?

每天23点执行一次:0 0 23 * * ?

每天凌晨1点执行一次:0 0 1 * * ?

每月1号凌晨1点执行一次:0 0 1 1 * ?

每月最后一天23点执行一次:0 0 23 L * ?

每周星期天凌晨1点实行一次:0 0 1 ? * L

在26分、29分、33分执行一次:0 26,29,33 * * * ?

每天的0点、13点、18点、21点都执行一次:0 0 0,13,18,21 * * ?

 

20190201034540

改成每5秒执行一次, 然后就可以看到

20190201034718