This issue has been created
 
 
XWiki Platform / cid:jira-generated-image-avatar-f858c3f0-4d77-49a2-b640-40a938ad0efc XWIKI-25288 Open

Only the first scheduler job of a page gets its status saved and is registered automatically

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-b2d94837-17a2-42a1-97aa-82e45bfb3ec8 Vincent Massol created this issue on 14/Oct/26 10:42
 
Summary: Only the first scheduler job of a page gets its status saved and is registered automatically
Issue Type: cid:jira-generated-image-avatar-f858c3f0-4d77-49a2-b640-40a938ad0efc Bug
Affects Versions: 17.10.0
Assignee: Unassigned
Components: Scheduler
Created: 14/Oct/26 10:42
Priority: cid:jira-generated-image-static-major-0ee03052-20cb-41c7-9901-d803bb5940a5 Major
Reporter: Vincent Massol
Description:

A page can hold several XWiki.SchedulerJobClass objects, and the scheduler script API supports it ($xwiki.scheduler.scheduleJobs($doc) schedules all of them). However the scheduler only handles the first job object of a page correctly:

  • The status of any job is saved on the first job of the page. Scheduling, pausing, resuming or unscheduling the 2nd job of a page writes the new status (Normal, Paused, None) in the status property of the 1st job object, and leaves the status of the 2nd job unchanged.
  • Only the first job of the page is registered automatically. When a page holding several jobs with the Normal or Paused status is created, only its first job is registered in the scheduler. The same happens at startup when the existing jobs are restored, so a 2nd job scheduled with scheduleJobs silently stops running after a restart. Deleting or modifying a job other than the first one is not taken into account either.

Steps to reproduce

  1. Create a page with 2 XWiki.SchedulerJobClass objects, the 1st one with the status None and the 2nd one with an empty status
  2. Schedule the 2nd job, e.g. with $xwiki.scheduler.scheduleJob($doc.getObject('XWiki.SchedulerJobClass', 1))
  3. Look at the objects of the page: the 1st job now has the Normal status while it's not scheduled, and the 2nd job, which is scheduled, still has an empty status
  4. Restart XWiki: the 2nd job is not scheduled anymore

Cause

SchedulerPlugin#saveStatus() saves the status on jobHolder.getXObject(XWIKI_JOB_CLASSREFERENCE), i.e. the first job object of the page, instead of the object it was given. SchedulerPlugin#register(XWikiDocument) (startup) and SchedulerPlugin#onDocumentEvent() (page created/updated/deleted) also only look at the first job object of the page.

Both behaviours were verified with unit tests based on an in-memory Quartz scheduler.