XF 2.0 how to leave the job rebuilding process?

Marcus

Well-known member
return $this->complete() works nice in the regular job, but not in the rebuilding job class. It always fetches the next id, but I really want the whole process to stop. Do you have an idea how to achieve this?

Or do you strongly advice to double-check the ids in the functions' setup, so I do some extensive stuff there to ensure all ids are good.
 
I'm not really sure I follow. $this->complete(); will stop further execution of the job. $this->resume(); will re-queue it.
 
PHP:
protected function rebuildById($id)
{
    $this->complete;

This will just close the job for this $id. It will then immediately continue with the next $id.

I iterate ids as I do not know when the id will stop (I fetch content with guzzle), and guzzle only works how I setup it once per page (if I fetch stuff by guzzle twice I already have an error):
PHP:
protected function getNextIds($start, $batch)
{
    return range($start + 1, $start + 1);
}

That's why it would be so great to stop the process once the results "fade" meaning I do not get any more results for $id. This could be done in the general job function, but I really like the rebuilder job, I want to make use of its nice functionality and visibility in admin control panel.
 
This will just close the job for this $id. It will then immediately continue with the next $id.
Actually that won't do anything. First it would be $this->complete(); rather than $this->complete; and second, you'd have to actually return it e.g. return $this->complete();, and finally you can't really interrupt job execution within a rebuild job. They're geared around a very specific and very common pattern so that will just loop through all IDs until it runs out of IDs for that batch.

That's why it would be so great to stop the process once the results "fade" meaning I do not get any more results for $id. This could be done in the general job function, but I really like the rebuilder job, I want to make use of its nice functionality and visibility in admin control panel.
You would have to use a general job extending AbstractJob rather than AbstractRebuildJob. Doing so will give you more control over what you want to do. If the run() method returns $this->complete(); then it will indeed halt execution entirely.

Just to reiterate, rebuild jobs are normal jobs, but ones that follow a very specific pattern. We have 14 jobs like that in total and they all follow the same pattern. What you're doing is certainly not a familiar pattern so it just doesn't fit there. Rebuild jobs do not have any special functionality or visibility in the Admin CP. Any job can be listed and run from the "Rebuild caches" page, you would just need to add your own job to that page in the tools_rebuild template.
 
Top Bottom