This task is currently a draft. I would like to hear opinions:
- Does it make sence?
- Is this something we think we want to do?
- Should this be an RFC?
Problem
The current system for submitting and executing jobs has the following issues:
- The interface for job submission is unclear. JobQueue::push accepts any instance of IJobSpecification, which could be an instance of JobSpecification, a simple wrapper for the job parameters, or an instantiated Job. The latter is an artifact from before IJobSpecification existed.
- Job construction is overly flexible. Before each job was bound to an instance of Title. However, for a lot of jobs that is not the case, so GenericParameterJob was introduced. The constructor of the former accepts a title, while the latter does not. This makes it hard to create a generic factory for all the jobs.
- There is no way to inject service classes into Jobs.
- Some of the initialization done in job constructors is unnecessary on the submission side, while some is unnecessary on the execution side.
Proposal
- Jobs could only be submitted as a JobSpecification.
- Title has no special treatment within jobqueue infracture. Jobs bound to a page title should set it via parameters just like any other parameter, so all jobs become GenericParameterJob.
- Static Job::factory is removed, jobs are constructed via JobFactory service class.
- $wgJobClasses configuration is removed or it's semantics is changed. It's replaced with a series of object specifications for ObjectFactory with required service classes. All service classes are injected into Job instance.
- Job instances are only constructed on the execution side when they are actually needed.
Steps
- Pushing instances of a Job into the JobQueue becomes deprecated in favor of JobSpecification.
- Once no Job instances are pushed into the queue anymore, Job stops being IJobSpecification - this will completely decouple pushing and popping the jobs. Also, prevents from calling Job constructor and Job::factory from random places.
- JobSpecification::getTitle becomes deprecated, the constructor still supports providing the title for convenience, but namespace/dbkey are passed through params. This ensures that all the pushed jobs have all the necessary information for execution within the parameters.
- All the static helper methods for constructing specific kinds of jobs start returning a JobSpecification. Prior to that relying on the fact it's a Job is deprecated.
- Now the individual job constructor is called from a single place so special constructors with Title can be deprecated and removed. All jobs become a GenericParameterJob
- Job::factory is deprecated, JobFactory service class is created to encapsulate Job deserialization.
- $wgJobClasses is deprecated, or just the format is changed to accept ObjectFactory spec. All services needed for the job are declared there. The spec is modified in the JobFactory in order to include ‘params’.
Steps 1-6 are needed for:
- Prohibit construction of full Job instances just for submitting them. In DI world this would be wasteful since all the service objects are needed only during job execution and not during job submission.
- Consolidate all the Job construction and get all the constructor in line, so that they could be built with object spec.
These are moving us towards step 7, however each of these steps would be an improvement over the current system.