Message Boards
Problem usin Scheduler in Liferay 7.2
Problem usin Scheduler in Liferay 7.2
Junior Member Posts: 25 Join Date: 3/14/19 Recent PostsHello everyone,
I m trying to use scheduler and javamail in liferay to send mail on specific date. The mail part is working great but i m facing some issues with the quartz Scheduler system. I m actually creating a trigger and starting a job at specific time, then i get my data from Message in the do receive and send a mail. I first got an error with deserialization of my MailMessage Type, this error showed up on the exact time of the job triggering date. After adding
json.deserialization.whitelist.class.names=javax.mail.internet.InternetAddress,com.liferay.mail.kernel.model.MailMessage,com.liferay.portal.kernel.messaging.Message
in my port-ext.properties the error disapeared but my doReceive seem to not work now. in the database, the job entry is disapearing at the triggering time. I don't have any error or log showing up. Here is my code :
Listener :
@Component(
immediate = true, property = {"cron.expression=0 0 0 * * ?"},
service = MailSchedulerImpl.class
)
public class MailSchedulerImpl extends BaseMessageListener {/**
* doReceive: This is where the magic happens, this is where you want to do the work for
* the scheduled job.
* @param message This is the message object tied to the job. If you stored data with the
* job, the message will contain that data.
* @throws Exception In case there is some sort of error processing the task.
*/
@Override
protected void doReceive(Message message) throws Exception {
System.out.println("Je passe bien ici ");
MailMessage m = (MailMessage) message.get("mail");
MailServiceUtil.sendEmail(m);
_log.info("Scheduled task executed...");
}
Trigger creation :
Calendar mCal = Calendar.getInstance();
Date dateEnvoie = newsletter.getDateEnvoie();
mCal.setTime(dateEnvoie);
System.out.println(dateEnvoie);String jobCronPattern = SchedulerEngineHelperUtil.getCronText(mCal, false);
ServiceContext actionRequest = ServiceContextThreadLocal.getServiceContext();
System.out.println(jobCronPattern);
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
Trigger trigger = TriggerFactoryUtil.createTrigger(MailSchedulerImpl.class.getName(), "mail_"+newsletter.getNewsletterId(), jobCronPattern);
Message message = new Message();
message.put("mail", mailMessage);
message.put(SchedulerEngine.JOB_NAME,MailSchedulerImpl.class.getName());
message.setDestinationName(DestinationNames.SCHEDULER_DISPATCH);
SchedulerEngineHelperUtil.schedule(trigger, StorageType.PERSISTED, trigger.getJobName() + newsletter.getNewsletterId(), DestinationNames.SCHEDULER_DISPATCH, message, 5);
SchedulerEngineHelperUtil.start();