hybris cornjob

Defining the Job

Create a new java class SendRankingJob in the package de/hybris/platform/cuppytrail/jobs:

src/de/hybris/platform/cuppytrail/jobs/SendRankingJob.java
/*
  * [y] hybris Platform
  *
  * Copyright (c) 2000-2011 hybris AG
  * All rights reserved.
  *
  * This software is the confidential and proprietary information of 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 hybris.
  *
  *
  */
package de.hybris.platform.cuppytrail.jobs;
 
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.cuppy.model.PlayerModel;
import de.hybris.platform.cuppy.services.MailService;
import de.hybris.platform.cuppy.services.PlayerService;
import de.hybris.platform.cuppy.services.RankingData;
import de.hybris.platform.servicelayer.cronjob.AbstractJobPerformable;
import de.hybris.platform.servicelayer.cronjob.PerformResult;
 
import java.util.List;
 
import org.apache.log4j.Logger;
 
 
public class SendRankingJob extends AbstractJobPerformable<CronJobModel>
{
     private static final Logger LOG = Logger.getLogger(SendRankingJob. class );
 
     private PlayerService playerService;
     private MailService mailService;
 
     @Override
     public PerformResult perform( final CronJobModel cronJob)
     {
         LOG.info( "Sending ranking mails" );
         final List<RankingData> rankings = playerService.getRankings();
 
         if (rankings.isEmpty())
         {
             LOG.info( "No competitions have changed, skipping send of ranking mails" );
             return new PerformResult(CronJobResult.SUCCESS, CronJobStatus.FINISHED);
         }
 
         for ( final PlayerModel player : playerService.getAllPlayers())
         {
             final List<RankingData> playerRankings = playerService.filterRankingsForPlayer(rankings, player);
             if (!playerRankings.isEmpty() && player.isSendNewsletter())
             {
                 mailService.sendRankingMail(player, playerRankings);
             }
         }
         return new PerformResult(CronJobResult.SUCCESS, CronJobStatus.FINISHED);
     }
 
     public void setPlayerService( final PlayerService playerService)
     {
         this .playerService = playerService;
     }
 
     public void setMailService( final MailService trailMailService)
     {
         this .mailService = trailMailService;
     }
}



The new JobPerformable has to be defined as a Spring bean in cuppytrail-spring.xml.
Add the following line at the bottom of the file, but inside the beans-tag:

resources/cuppytrail-spring.xml
<bean id= "sendRankingJob" class = "de.hybris.platform.cuppytrail.jobs.SendRankingJob" autowire= "byName" />

Rebuild the hybris Platform by calling ant in the $/{HYBRIS_BIN_DIR}/platform directory.
(警告) Run a system update with only essential data checked - during the phase of essential data creation, for each Spring definition of a class implementing the JobPerformable interface, a ServicelayerJob instance gets created and the code attribute of the job is set to the name of the Spring bean.

You can check in the FlexibleSearch console: http://localhost:9001/console/flexsearch that the new item was created by executing the following query:

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

Create the CronJob and the Trigger

To create the CronJob and the Trigger, you can either:

  • You can go in the hybris Admin Console to the Console tab select ImpEx Import and execute the following impex-script there by clicking on the Import Content button

    INSERT_UPDATE CronJob; code[unique= true ];job(code);singleExecutable;sessionLanguage(isocode)
    ;sendRankingCronJob;sendRankingJob; false ;de
     
    INSERT_UPDATE Trigger;cronjob(code)[unique= true ];cronExpression
    #% afterEach: impex.getLastImportedItem().setActivationTime( new Date());
    ; sendRankingCronJob; 0 0 0 * * ?

    A cron expression is a string comprised of 6 or 7 fields separated by white space. Fields can contain any of the allowed values, along with various combinations of allowed special characters for that field.

     
  • Seconds

    YES

    0-59

    , - * /

    Minutes

    YES

    0-59

    , - * /

    Hours

    YES

    0-23

    , - * /

    Day of month

    YES

    1-31

    , - * ? / L W

    Month

    YES

    1-12 or JAN-DEC

    , - * /

    Day of week

    YES

    1-7 or SUN-SAT

    , - * ? / L #

    Year

    NO

    empty, 1970-2099

    , - * /

    Quartz cron trigger is used, see Quartz Scheduler for more details.
    Any changes you are making for testing can easily be redeployed or reexecuted.

  • OR create the file resources/impex/essentialdataJobs.impex with the same content. Further changes are only taken into account after a server-restart and a system update (with only essential data checked). Changes made to resources after being loaded as classloader-resources are not visible.

Test the job

    • Simply log in into the hmc
    • Open the cuppy-section and edit a player
      • Set the newsletter-attribute to true
      • Change the eMail address of this player to your email address (if you set up email previously)
    • Execute the job manually
      • In the left tree, go to System | CronJobs
      • Select sendRankingCronJob
      • Click 'Start CronJob now'

转载于:https://www.cnblogs.com/wahaha603/p/7262638.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值