AsyncApexJob record inserted immediately at the end of a transaction or is it possible that there is a delay between those two events? I couldn't find firm guarantee in the documentation on that.
As a specific example, I'm calling an
@future annotated method in the transaction T1 and I'd like to monitor its progress. It returns
void, but I can query the
AsyncApexJob table to try to locate it (provided that there are no similar calls at the same time). Since the
@future job is only queued after a successful transaction, I can only reach it after the transaction T1 ended, so I'd start another transaction T2 immediately after to monitor it.
The question is whether after means immediately at the end, or there can be some delay d before the record can be found in the
Illustrated, if there's no delay, then T2 is guaranteed to see the
AsyncApexJob record as long as it starts after T1
T1 o------> * (AsyncApexJob record inserted by system) T2 o---->
If there is some delay d, then T2 is not guaranteed to see the record if it starts after T2, but before d has passed.
T1 o-----> [--d--]* (AsyncApexJob record inserted by system) T2 o---->