A job does not have a thing such as a "scope". They have a lock (Job, Database and None) but that's something else.
So you're actually talking about the scope of the feature that deploys (through a feature event receiver).
Several things have to be noted:
- Web application-scoped features are (by default) automatically activated when the WSP is deployed. That means your feature is activated multiple times, once per content Web application you have in the farm.
- This means multiple instances of your job may be created (e.g. 2 Web applications -> 2 jobs are created in the list of job definitions).
- It's up to you to associate the Web application the feature is activated on to the job you're instantiating. This can be done by setting the
WebApplication property of the job:
public MyJobDefinition(SPWebApplication webApp) : base(GetJobName(webApp), webApp, null, SPJobLockType.Job) { }
- Then, in the
Execute method, you may access the Web app and enumerate (for instance) its site collections to get the job done on each. - You may give a name to your job that reflects the Web app it's associated with.
- You can deactivate the feature on the Web applications you don't want it: don't forget that add code in the feature ER when the feature deactivates to unregister the job for that Web app.
A good sample can be found at https://msdn.microsoft.com/en-us/library/ff798313.aspx.