Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Andrzej Drozdowski
cron text format for scheduled job - chosen week days
April 11, 2013 8:14 AM
Answer

Andrzej Drozdowski

Rank: Junior Member

Posts: 25

Join Date: September 3, 2010

Recent Posts

Hi
I would like to schedule a job programitically. I want it runs few times a week for example at 5AM on Mondays and Wednesdays.
I have tried to use cron text: 0 0 5 * * 1,3 * but it does not work. The job seems to run every minute.
Then I tried 0 10 5 * * ? * and the job is scheduled properly - every day.

Does anybody knows the right format to choose week days?

My code:
 1
 2        MessageBusUtil.registerMessageListener(
 3                DestinationNames.SCHEDULER_DISPATCH, new ImportJob());
 4
 5        String cronText = "0 " + minuteCron + " " + hourCron + " * * "
 6                + weekdaysCron + " *";
 7        Trigger trigger = new CronTrigger("Import Job", "Import", new Date(),
 8                null, cronText);
 9
10        Message message = new Message();
11
12        try {
13            SchedulerEngineUtil.schedule(trigger, StorageType.PERSISTED,
14                    "Import Job", DestinationNames.SCHEDULER_DISPATCH, message,
15                    10);
16        } catch (SchedulerException e) {
17            log.error("cannot schedule the job", e);
18        }


Liferay 6.1

Thank You
A.D.
David H Nebinger
RE: cron text format for scheduled job - chosen week days
April 11, 2013 8:20 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6704

Join Date: September 1, 2006

Recent Posts

Usually you should include a 'no specific value' reference (the ? character) in your expression.

Try "0 0 5 ? * 1,3 *".
Andrzej Drozdowski
RE: cron text format for scheduled job - chosen week days
April 11, 2013 9:14 AM
Answer

Andrzej Drozdowski

Rank: Junior Member

Posts: 25

Join Date: September 3, 2010

Recent Posts

Thank You!

I used your cron text. The job is scheduled as defined (next monday), and the information is saved properly in database but it also runs every minute.
What could be the reason?

And another question.
I would like to delete the job. My cod is:
1
2            SchedulerEngineUtil.delete("Import Job", "Import",
3                    StorageType.PERSISTED);

The schedule is not deleted - is still in database table.
How should I delete the schedule?

Regards,
A.D.
David H Nebinger
RE: cron text format for scheduled job - chosen week days
April 11, 2013 9:32 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6704

Join Date: September 1, 2006

Recent Posts

The cron schedule is right, but if it is also going every minute I'm wondering if perhaps you have an older scheduled task defined for that (either in the database or liferay-portlet.xml or what not).
Andrzej Drozdowski
RE: cron text format for scheduled job - chosen week days
April 19, 2013 8:24 AM
Answer

Andrzej Drozdowski

Rank: Junior Member

Posts: 25

Join Date: September 3, 2010

Recent Posts

Hi,
Despite many attempts I cannot make it to work.

I have tried also with:
 1
 2        SchedulerEntry schedulerEntry = new SchedulerEntryImpl();
 3        schedulerEntry.setEventListenerClass(ImportJob.class.getName());
 4        schedulerEntry.setTriggerValue(cronText);
 5        schedulerEntry.setTriggerType(TriggerType.CRON);
 6        schedulerEntry.setDescription("job description");
 7
 8        try {
 9            SchedulerEngineUtil.schedule(new ImporterSchedulesEntry(cronText),
10                    StorageType.PERSISTED, null, 0);


It looks like quartz is not triggering the job.
I have looked into quartz tables - job and cron records are OK.
SchedulerEngineUtil.getNextFireTime() shows proper time.

When time is up nothing happens.

Please hint me, what could be the reason.
Any help will be appreciated.

Regards
A.D