Sometimes you need to select multiple values and process them in the background upon a button click. As you can see, I can select some items with specific ids and by clicking the Process Them button, I submit them for processing.
Once I submit the data, I use the following table for the process: Name: batch_process ----------- batch_id: PK INTEGER AUTO INCREMENT batch_started: CURRENT TIMESTAMP (Optional Field) batch_ended: TIMESTAMP (Optional Field)
dispatch(function() use ($batch_id,$ids) { foreach($ids as $id){ $log_id = DB::table('processed_items')->insertGetId([ 'batch_id' => $batch_id, 'selected_id' => $id, 'timestamp_started' => date('Y-m-d H:i:s')]); // Do some process on the item having $id $sucess = false; $error_msg = NULL' try { // processItem contains the logic for bulk processes $sucess = prossessItem($id); $error_msg = $sucess ? NULL: "Uknown"; } catch (Exception $e) { $sucess = false; $error_msg = $d->setMessage(); }} $status = $sucess?
First, we managed to implement a mechanism that allows us to easily check what is processed and if the processed item is successful or not from user-initiated batch processes.