首页 > 解决方案 > Laravel 延迟作业不适用于批处理

问题描述

我正在尝试延迟添加到我的 Laravel 应用程序中的批处理中的作业,但是在尝试添加延迟的作业时出错,我的代码中缺少什么?

/**
 * Create chunked CSVs
 */
protected function createChunkedCSVs(Request $request)
{

    try {

      // get the CSV we stored
      $data = file($request->csv);

      // chunk the CSV into smaller csv's
      $chunks = array_chunk($data, 1000);

      // header and batch
      $header = [];
      $batch  = Bus::batch([])->dispatch();

      // latest form release
      $release = $this->getApplicationFormVersion();

      // begin chunking
      foreach ($chunks as $key => $chunk) {
        $data = array_map('str_getcsv', $chunk);

        if ($key === 0) {
          $header = $data[0];
          unset($data[0]);
        }

        $batch->add(new CustomersCsvProcess($data, $header, $release)->delay(Carbon::now()->addMinutes(5)));
      }

      // return the batch
      return $batch;

    } catch (\Exception $e) {

      return null;

    }

}

标签: phplaravel

解决方案


推荐阅读