OK, lucky for you I happened to have a dev environment with a million Asset
so I could launch a job, have it run, then change the code and (deploy) the changed code to see if the batchable uses the 'new" logic.
And the answer is ....
YES, deploying a change in logic to the batchable's execute()
will pick up the changes after the deployment while the job is running.
Proof point:
- Batchable (original version) published a platform event on each
execute()
that was subscribed by a NOP trigger
- Batchable (new version) did not publish the platform event
After deploying the new version, the query:
select position, tip, name from EventBusSubscriber where name ='MyNopTrigger'
stopped incrementing the values of Tip and Position, indicating that publishing had stopped
What I did not try:
- Changing the
start()
method to select a different set of records - I sincerely doubt this would have an effect as the Apex Jobs monitoring page did not restart the query upon deploying the new version
- Changing the
finish()
method to do something different than the original. I suspect that since the execute()
did show the behavior change, by the time finish()
executed, it to (as a separate transaction) would show the behavior change of a new version.
Code used:
public with sharing class SfseInflightSchedulable implements System.schedulable, Database.Batchable<SObject> {
public void execute(SchedulableContext sc) {
Database.executeBatch(new SfseInflightSchedulable(),10);
}
public Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator([Select Id from Asset]);
}
public void execute(Database.BatchableContext bc, List<Object> assets) {
// start by running to publish Platform Event that can be monitored
EventBus.publish(new MyPlatformEvent__e());
// after batch is running, redeploy by commenting out the publish
}
public void finish(Database.BatchableContext bc) {
}
}