1

I think we can stop cronjob by hmc. If except that any ways are there please answer

Lcoder_001
  • 153
  • 4
  • 14

4 Answers4

2

You can find an answer in the more global problematic of how to stop an infinite loop in a thread. (See : https://stackoverflow.com/a/2358169/1140748)

Your job is launched in a dedicated Thread.

The only way you have to stop it is to use a flag that can be set from an outside object.

In your JobPerformable (that extends AbstractJobPerformable) you have to often set this block of code to check if the cron should be stopped :

    if (clearAbortRequestedIfNeeded(cronJobModel)) {
        LOG.error(String.format(MSG_INFO_JOB_ABORTED, cronJobModel.getCode()));
        return new PerformResult(CronJobResult.UNKNOWN, CronJobStatus.ABORTED);
    }

The JobPerformable must be "abortable". To say that put this bloc of code in the JobPerformable implementation :

@Override
public boolean isAbortable()
{
    return true;
}
Community
  • 1
  • 1
alain.janinm
  • 19,951
  • 10
  • 65
  • 112
1

You can always abort your Cronjob from HMC using (Abort Cronjob button), however your job should be an abortable job, if it's not you will not be able to stop it.

enter image description here

Check this tutorial on How to Write an Abortable Job.

Mouad EL Fakir
  • 3,609
  • 2
  • 23
  • 37
1

Actually there are several ways to stop cronjob in Hybris.

First and best approach is to abort it from HMC (now Backoffice Administration Cockpit). For that to be possible cronjob has to be abortable. More on abortable cronjobs here.

You can also abort cronjobs from HAC by going to Monitoring > Cron Jobs. This works more or less the same way it does in the first approach.

There are also some ways to abort/stop/finish cronjob when the first two are not available:

  1. You can remove cronjob by impex import or directly on the database.
  2. You can set cronjob's status to FINISHED by impex import or on database.
  3. You can do both (1. and 2.) also by webservice API I believe. More on webservice API here.

Last but not least, you can abort the cronjob programmatically using:

cronJobService.requestAbortCronJob(myCronJobModel);

In this case cronjob has to be abortable as well.

More on cronjobs here.

qwerty1423
  • 295
  • 5
  • 17
  • I think if the cronjob is not abortable none of those points will make it stop, (removing the cronjob is not appropriate in my opinion, i prefer restart the server rather than removing the cronJob, because the cronJob may hold some historical/interesting information, and i don't want them to be erased). – Mouad EL Fakir Feb 09 '17 at 16:51
  • But I want know without interrupting server how can we stop cronjob ? – Lcoder_001 Feb 11 '17 at 10:55
0

run below impex in hac

update CronJob[batchmode=true];itemtype(code)[unique=true];active;CronJob;false
Maxwell Cheng
  • 1,050
  • 10
  • 17