Forums de discussion

Schedule start time of a background job

thumbnail
Rishi Dev Gupta, modifié il y a 14 années.

Schedule start time of a background job

Expert Publications: 255 Date d'inscription: 23/11/08 Publications récentes
Hi all

LFR 5.2.3 (tomcat bundle)

I need to schedule a job to work only at 1 am in morning. I can give the interval time of 24 hours but cannot find location where to specify the schedule start time for job. does liferay provide functionality to schedule a job for a particular time irrespective of when the server is started.
thumbnail
Sandeep Nair, modifié il y a 14 années.

RE: Schedule start time of a background job

Liferay Legend Publications: 1744 Date d'inscription: 06/11/08 Publications récentes
Which jobs do you want to set interval. Like there are many jobs whose interval can be set. i just grabbed some of the jobs properties from portal.properties


message.boards.expire.ban.job.interval=120
blogs.trackback.verifier.job.interval=5
announcements.entry.check.interval=15
journal.article.check.interval=15


Interval values are set in 1 minute increments

Regards,
Sandeep
thumbnail
Rishi Dev Gupta, modifié il y a 14 années.

RE: Schedule start time of a background job

Expert Publications: 255 Date d'inscription: 23/11/08 Publications récentes
I am not working on any of the Liferay default portlets.
I have custom portlet with a particular set of activities that need to be scheduled at night only.
thumbnail
Sandeep Nair, modifié il y a 14 années.

RE: Schedule start time of a background job

Liferay Legend Publications: 1744 Date d'inscription: 06/11/08 Publications récentes
Hi,

Create classes that implements Scheduler and IntervalJob Respectively. In the class which implement IntervalJob, set the interval, recommended way from property. Add scheduler class in portal-ext.properties

#
    # Input a list of comma delimited class names that implement
    # com.liferay.portal.kernel.job.Scheduler. These classes allow jobs to be
    # scheduled on startup. These classes are not associated to any one portlet.
    #
    scheduler.classes=


For ready reference you can see AnnouncementsScheduler and CheckEntryJob

Regards,
Sandeep
thumbnail
Rishi Dev Gupta, modifié il y a 14 années.

RE: Schedule start time of a background job

Expert Publications: 255 Date d'inscription: 23/11/08 Publications récentes
I have checked that code and it is almost similar what we have implemented except that I have created a portlet scheduler.

It tells after what interval the job should run but it does not specify at what time scheduler should start executing the job in my case the job should run at interval of 24 hrs but it should execute only at 1am daily only irrespective when server is started.

Because right now the scheduler behavior is that if server is started say 10 am the scheduler will run next day at 10 am which it should not because here it should run at 1am only
thumbnail
Sandeep Nair, modifié il y a 14 années.

RE: Schedule start time of a background job

Liferay Legend Publications: 1744 Date d'inscription: 06/11/08 Publications récentes
Hi Rishi,

I got your point. The thing is Liferay internally uses JobSchedulerImpl to set the startTime. You can see the file for how starttime is set. It uses currentTime + 1 minute as start time if its Tomcat and currentTime + 3min if its not. I guess you have to create a class like that, in which you specify whatever start time you want.

Regards,
Sandeep
thumbnail
Javier Bautista, modifié il y a 13 années.

RE: Schedule start time of a background job

New Member Publications: 2 Date d'inscription: 21/05/09 Publications récentes
Hi,

If you have an EXT environment you can override the implementation of JobSchedulerImpl and add a new method "schedule" with an extra Date parameter for specify the startTime:

You have to override this classes to add the new method or its signature:
  • JobSchedulerImpl
  • JobScheduler (interface)
  • JobSchedulerUtil


Then in the ext-spring.xml you have to change the reference of the bean to your new classes:

<bean id="your.package.portal.kernel.job.JobSchedulerUtil" class="your.package.portal.kernel.job.JobSchedulerUtil">
		<property name="jobScheduler">
			<bean class="your.package.portal.job.JobSchedulerImpl">
				<property name="scheduler">
					<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
						<property name="quartzProperties">
							<props>
								<prop key="org.quartz.threadPool.threadCount">3</prop>
							</props>
						</property>
					</bean>
				</property>
			</bean>
		</property>
	</bean>



Regards,
Javier Bautista