I made a custom application with a Queue extension task for a client. Before calling it, I set a custom flag for a specific member, whose ID I also pass as the $data['member_id'] variable.
Then, in the postComplete() function, I reset the flag for the member once the task is done running:
/**
* Perform post-completion processing
*
* @param array $data Data returned from preQueueData
* @param bool $processed Was anything processed or not? If preQueueData returns NULL, this will be FALSE.
* @return void
*/
public function postComplete( $data, $processed = TRUE )
{
$data = json_decode( $data['data'], TRUE );
# Once the task is complete update the member status to READY
$member = Member::load( $data['member_id'] );
$member->custom_flag_field = Suggestion::STATUS_READY;
$member->save();
}
The code above works just fine as long as there is any data to process for the member. However, when the member has nothing to parse, and preQueueData() returns NULL, the postComplete() function doesn't have any data on which member to reset the flag for.
The Task::queue() function should be updated to at least still pass the original $data variable values instead of NULL (or an empty array in v5). This is the current code:
I store the original values in $oldData and pass that variable to both preQueueData() and postComplete().
If $data ends up being NULL, it properly passes the original values at least, if $data is a proper array instead, the code keeps processing everything else as usual.
===
The code is slightly different in v5, where an empty array is passed instead of NULL, but the change is also still relevant for it.
I made a custom application with a Queue extension task for a client. Before calling it, I set a custom flag for a specific member, whose ID I also pass as the $data['member_id'] variable.
Then, in the postComplete() function, I reset the flag for the member once the task is done running:
The code above works just fine as long as there is any data to process for the member. However, when the member has nothing to parse, and preQueueData() returns NULL, the postComplete() function doesn't have any data on which member to reset the flag for.
The Task::queue() function should be updated to at least still pass the original $data variable values instead of NULL (or an empty array in v5). This is the current code:
Here's my suggested change:
I store the original values in $oldData and pass that variable to both preQueueData() and postComplete().
If $data ends up being NULL, it properly passes the original values at least, if $data is a proper array instead, the code keeps processing everything else as usual.
===
The code is slightly different in v5, where an empty array is passed instead of NULL, but the change is also still relevant for it.
Länk till full forum post