Uploaded image for project: 'OFBiz'
  1. OFBiz
  2. OFBIZ-10865

Allow prioritization of background jobs

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • None
    • framework
    • None
    • Patch

    Description

      As discussed on the dev list [1], allow Jobs to specify a priority and be queued accordingly by the JobPoller so that important jobs can be prioritized over normal jobs, and low priority jobs can be left until last.

      This is a first pass implementation with just the main changes. We will still need to allow the priority to be set in the JobManager and LocalDispatcher's "schedule" methods before jobs generated at runtime can be prioritized. IMO the existing schedule methods are a mess and need to be converted into a builder pattern before adding any more job attributes. The new priority field also needs to be added to the webtools UI wherever appropriate.

      Changes are as follows:

      • Add a "priority" field to JobSandbox entity (numeric/Long)
      • Add JobPriority constants class containing fields LOW (0), NORMAL (50) and HIGH (100)
      • Add getPriority method to the Job interface and implement methods for AbstractJob (returns NORMAL), PersistedServiceJob (returns JobSandbox.priority) and PurgeJob (returns LOW)
      • Change the JobPoller executor's queue to use PriorityBlockingQueue (unbounded) instead of LinkedBlockingQueue (bounded)
      • Implement custom Comparator for the priority queue to sort by priority descending and then runTime ascending
      • Change the poll size per poll to be (queueSize() - queue.size) instead of queue.remainingCapacity() due to the new queue being unbounded
      • I've also opted to limit the database poll query to the poll size using maxRows() because it seemed dangerous to me to use an unconstrained query on this table
      • Ensured recurring jobs receive the default (NORMAL) priority when being rescheduled so that they're sorted correctly on the next time they show up in the database poll
      • Ensured jobs generated at runtime are given a default priority of NORMAL

      [1] https://lists.apache.org/thread.html/f9107f8ca9a17a2df731337fc3d9766ebad33467fea4393fb069552d@%3Cdev.ofbiz.apache.org%3E

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            lektran Scott Gray
            lektran Scott Gray
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment