掲示板

Quartz Trigger is fired in DB but the Scheduler Job doesn't run at server

thumbnail
8年前 に Ashish Agarwal によって更新されました。

Quartz Trigger is fired in DB but the Scheduler Job doesn't run at server

New Member 投稿: 13 参加年月日: 15/07/07 最新の投稿
I have a scheduler written as a portlet and the portlet is being registered on the server and the scheduler configuration is also being persisted to Quartz tables. Below is my code: (The property scheduler.enabled is set to true for QuartzSchedulerEngine)

package com.test.scheduler;

import javax.portlet.PortletException;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.messaging.Message;
import com.liferay.portal.kernel.messaging.MessageListener;
import com.liferay.portal.kernel.messaging.MessageListenerException;
import com.liferay.portal.kernel.scheduler.SchedulerEngineUtil;
import com.liferay.portal.kernel.scheduler.SchedulerEntry;
import com.liferay.portal.kernel.scheduler.SchedulerEntryImpl;
import com.liferay.portal.kernel.scheduler.StorageType;
import com.liferay.portal.kernel.scheduler.TriggerType;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.model.Portlet;
import com.liferay.portal.service.PortletLocalServiceUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;

public class TestScheduler extends MVCPortlet implements
		MessageListener {

	private static final Log LOGGER = LogFactoryUtil
			.getLog(TestScheduler.class);

	private static String schedulerName;
	private static String cronTrigger;

	static {
		schedulerName = TestScheduler.class.getName();
		cronTrigger = "0 0/1 * * * ?";
	}

	@Override
	public void init() throws PortletException {
		super.init();
		LOGGER.info("Inside init method...");

		Portlet portlet = PortletLocalServiceUtil
				.getPortletById("1_WAR_test");

		SchedulerEntry entry = new SchedulerEntryImpl() {
			{
				setEventListenerClass(schedulerName);
				setTriggerType(TriggerType.CRON);
				setTriggerValue(cronTrigger);
			}
		};
		entry.setContextPath(portlet.getContextPath());

		LOGGER.info("Scheduler Entry: " + entry.toString());

		try {
			SchedulerEngineUtil.schedule(entry, StorageType.PERSISTED,
					portlet.getPortletId(), 0);
		} catch (Exception e) {
			e.printStackTrace();
		}
		LOGGER.info("Test Scheduler is scheduled from portlet");
	}

	public void receive(Message message) throws MessageListenerException {

		LOGGER.info("Test Scheduler initialized.");
	}

}


Here the Scheduler details are saved in the QUARTZ_CRON_TRIGGERS and the trigger is fired at every minute as per the CRON expression, but the trigger generates a record in QUARTZ_FIRED_TRIGGERS table and the record goes away and the Scheduler class above doesn't get fired at all at the server.

Am I doing something wrong?
thumbnail
8年前 に David H Nebinger によって更新されました。

RE: Quartz Trigger is fired in DB but the Scheduler Job doesn't run at serv

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
Yes, you cannot implement in your portlet class.

At runtime Liferay will instantiate a new instance of the class using the default constructor and then invoke the scheduler to do the task.

You have things all mixed together so there won't be any clear way for the class to be instantiated in response to the timer message.
thumbnail
8年前 に Ashish Agarwal によって更新されました。

RE: Quartz Trigger is fired in DB but the Scheduler Job doesn't run at serv (回答)

New Member 投稿: 13 参加年月日: 15/07/07 最新の投稿
It is working as I have coded it.

I had some configuration missed due to which the class was not being instantiated.

It works fine but I will be going through the approach to keep the Scheduler and portlet in different classes.
7年前 に Abhishek sharma によって更新されました。

RE: Quartz Trigger is fired in DB but the Scheduler Job doesn't run at serv

Junior Member 投稿: 71 参加年月日: 14/02/18 最新の投稿
Hi Ashish,

Can you please have a look on below url regarding the same issue and solve my query ,Thanks in advance

https://web.liferay.com/community/forums/-/message_boards/message/81214281