Repository: SpartnerNL/Laravel-Excel (PHP)

Issue:
[Bug]: Error: Call to undefined method Maatwebsite\Excel\Jobs\AppendQueryToSheet::release()
Hello

### Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

- [X] Yes, it's still reproducable

### What version of Laravel Excel are you using?

3.1.33

### What version of Laravel are you using?

8.60.0

### What version of PHP are you using?

7.4.23

### Describe your issue

There is an issue with Maatwebsite\Excel\Jobs\AppendQueryToSheet

the method release is missing  so it cant be used with WithoutOverlapping middleware :


```
Error: Call to undefined method Maatwebsite\Excel\Jobs\AppendQueryToSheet::release() in /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Middleware/WithoutOverlapping.php:76
Stack trace:
#0 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Queue\Middleware\WithoutOverlapping->handle(Object(Maatwebsite\Excel\Jobs\AppendQueryToSheet), Object(Closure))
#1 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Maatwebsite\Excel\Jobs\AppendQueryToSheet))
#2 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(122): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#3 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(70): Illuminate\Queue\CallQueuedHandler->dispatchThroughMiddleware(Object(Illuminate\Queue\Jobs\RedisJob), Object(Maatwebsite\Excel\Jobs\AppendQueryToSheet))
#4 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(98): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\RedisJob), Array)
#5 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(428): Illuminate\Queue\Jobs\Job->fire()
#6 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(378): Illuminate\Queue\Worker->process('redis', Object(Illuminate\Queue\Jobs\RedisJob), Object(Illuminate\Queue\WorkerOptions))
#7 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(172): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\RedisJob), 'redis', Object(Illuminate\Queue\WorkerOptions))
#8 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(117): Illuminate\Queue\Worker->daemon('redis', 'default', Object(Illuminate\Queue\WorkerOptions))
#9 /var/www/html/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(101): Illuminate\Queue\Console\WorkCommand->runWorker('redis', 'default')
#10 /var/www/html/vendor/laravel/horizon/src/Console/WorkCommand.php(51): Illuminate\Queue\Console\WorkCommand->handle()
#11 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Laravel\Horizon\Console\WorkCommand->handle()
#12 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#13 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure(Object(Closure))
#14 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#15 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(651): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#16 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\Container\Container->call(Array)
#17 /var/www/html/vendor/symfony/console/Command/Command.php(299): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#18 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#19 /var/www/html/vendor/symfony/console/Application.php(978): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 /var/www/html/vendor/symfony/console/Application.php(295): Symfony\Component\Console\Application->doRunCommand(Object(Laravel\Horizon\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 /var/www/html/vendor/symfony/console/Application.php(167): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /var/www/html/vendor/laravel/framework/src/Illuminate/Console/Application.php(92): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 /var/www/html/artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 {main}
```

### How can the issue be reproduced?

Dispatch 2 concurrent exports on the queue, for the same resource to trigger the lock, and use middlewares like this :

```
    /**
     * Get the middleware the job should pass through.
     *
     * @return array
     */
    public function middleware()
    {
        return [
            // 
            (new WithoutOverlapping('job_identifier_like_an_id'))->releaseAfter(30)->expireAfter(600),
        ];
    }
```

The release method will be called on the second job, when the first one has cleared the lock

But that release method does not exist.

### What should be the expected behaviour?

The job is released into the queue correctly.

I don't know if it's supposed to work, of if it's not supported by Laravel-Excel

i think maybe there is a missing trait like InteractsWithQueue

thanks.


Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d81d6cd83..cd7955a54 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
 
 - Change default local_path configuration
 - Fix queueImport function to be able to assert chained jobs
+- Fix missing InteractsWithQueue trait in AppendToSheet jobs
 
 
 ## [3.1.33] - 2021-08-12
diff --git a/src/Jobs/AppendDataToSheet.php b/src/Jobs/AppendDataToSheet.php
index c6f11d15a..c1c294314 100644
--- a/src/Jobs/AppendDataToSheet.php
+++ b/src/Jobs/AppendDataToSheet.php
@@ -5,13 +5,14 @@
 use Illuminate\Bus\Queueable;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Queue\InteractsWithQueue;
 use Maatwebsite\Excel\Files\TemporaryFile;
 use Maatwebsite\Excel\Jobs\Middleware\LocalizeJob;
 use Maatwebsite\Excel\Writer;
 
 class AppendDataToSheet implements ShouldQueue
 {
-    use Queueable, Dispatchable, ProxyFailures;
+    use Queueable, Dispatchable, ProxyFailures, InteractsWithQueue;
 
     /**
      * @var array
@@ -39,11 +40,11 @@ class AppendDataToSheet implements ShouldQueue
     public $sheetExport;
 
     /**
-     * @param object        $sheetExport
-     * @param TemporaryFile $temporaryFile
-     * @param string        $writerType
-     * @param int           $sheetIndex
-     * @param array         $data
+     * @param  object  $sheetExport
+     * @param  TemporaryFile  $temporaryFile
+     * @param  string  $writerType
+     * @param  int  $sheetIndex
+     * @param  array  $data
      */
     public function __construct($sheetExport, TemporaryFile $temporaryFile, string $writerType, int $sheetIndex, array $data)
     {
@@ -65,7 +66,7 @@ public function middleware()
     }
 
     /**
-     * @param Writer $writer
+     * @param  Writer  $writer
      *
      * @throws \PhpOffice\PhpSpreadsheet\Exception
      * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
diff --git a/src/Jobs/AppendQueryToSheet.php b/src/Jobs/AppendQueryToSheet.php
index e1dd212cb..87433a2d2 100644
--- a/src/Jobs/AppendQueryToSheet.php
+++ b/src/Jobs/AppendQueryToSheet.php
@@ -5,6 +5,7 @@
 use Illuminate\Bus\Queueable;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Queue\InteractsWithQueue;
 use Maatwebsite\Excel\Concerns\FromQuery;
 use Maatwebsite\Excel\Files\TemporaryFile;
 use Maatwebsite\Excel\Jobs\Middleware\LocalizeJob;
@@ -12,7 +13,7 @@
 
 class AppendQueryToSheet implements ShouldQueue
 {
-    use Queueable, Dispatchable, ProxyFailures;
+    use Queueable, Dispatchable, ProxyFailures, InteractsWithQueue;
 
     /**
      * @var TemporaryFile
@@ -45,12 +46,12 @@ class AppendQueryToSheet implements ShouldQueue
     public $chunkSize;
 
     /**
-     * @param FromQuery       $sheetExport
-     * @param TemporaryFile   $temporaryFile
-     * @param string          $writerType
-     * @param int             $sheetIndex
-     * @param int             $page
-     * @param int             $chunkSize
+     * @param  FromQuery  $sheetExport
+     * @param  TemporaryFile  $temporaryFile
+     * @param  string  $writerType
+     * @param  int  $sheetIndex
+     * @param  int  $page
+     * @param  int  $chunkSize
      */
     public function __construct(
         FromQuery $sheetExport,
@@ -79,7 +80,7 @@ public function middleware()
     }
 
     /**
-     * @param Writer $writer
+     * @param  Writer  $writer
      *
      * @throws \PhpOffice\PhpSpreadsheet\Exception
      * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
diff --git a/src/Jobs/AppendViewToSheet.php b/src/Jobs/AppendViewToSheet.php
index 1f82ed91a..a7d2c09e2 100644
--- a/src/Jobs/AppendViewToSheet.php
+++ b/src/Jobs/AppendViewToSheet.php
@@ -5,6 +5,7 @@
 use Illuminate\Bus\Queueable;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Queue\InteractsWithQueue;
 use Maatwebsite\Excel\Concerns\FromView;
 use Maatwebsite\Excel\Files\TemporaryFile;
 use Maatwebsite\Excel\Jobs\Middleware\LocalizeJob;
@@ -12,7 +13,7 @@
 
 class AppendViewToSheet implements ShouldQueue
 {
-    use Queueable, Dispatchable;
+    use Queueable, Dispatchable, InteractsWithQueue;
 
     /**
      * @var TemporaryFile
@@ -35,11 +36,11 @@ class AppendViewToSheet implements ShouldQueue
     public $sheetExport;
 
     /**
-     * @param FromView        $sheetExport
-     * @param TemporaryFile $temporaryFile
-     * @param string        $writerType
-     * @param int           $sheetIndex
-     * @param array         $data
+     * @param  FromView  $sheetExport
+     * @param  TemporaryFile  $temporaryFile
+     * @param  string  $writerType
+     * @param  int  $sheetIndex
+     * @param  array  $data
      */
     public function __construct(FromView $sheetExport, TemporaryFile $temporaryFile, string $writerType, int $sheetIndex)
     {
@@ -60,7 +61,7 @@ public function middleware()
     }
 
     /**
-     * @param Writer $writer
+     * @param  Writer  $writer
      *
      * @throws \PhpOffice\PhpSpreadsheet\Exception
      * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception


Test patch:
diff --git a/tests/InteractsWithQueueTest.php b/tests/InteractsWithQueueTest.php
new file mode 100644
index 000000000..d003693f1
--- /dev/null
+++ b/tests/InteractsWithQueueTest.php
@@ -0,0 +1,52 @@
+<?php
+
+namespace Maatwebsite\Excel\Tests;
+
+use Illuminate\Queue\InteractsWithQueue;
+use Maatwebsite\Excel\Jobs\AppendDataToSheet;
+use Maatwebsite\Excel\Jobs\AppendQueryToSheet;
+use Maatwebsite\Excel\Jobs\AppendViewToSheet;
+use Maatwebsite\Excel\Jobs\ReadChunk;
+
+class InteractsWithQueueTest extends TestCase
+{
+    /**
+     * Setup the test environment.
+     */
+    protected function setUp(): void
+    {
+        parent::setUp();
+    }
+
+    /**
+     * @test
+     */
+    public function read_chunk_job_can_interact_with_queue()
+    {
+        $this->assertContains(InteractsWithQueue::class, class_uses(ReadChunk::class));
+    }
+
+    /**
+     * @test
+     */
+    public function append_data_to_sheet_job_can_interact_with_queue()
+    {
+        $this->assertContains(InteractsWithQueue::class, class_uses(AppendDataToSheet::class));
+    }
+
+    /**
+     * @test
+     */
+    public function append_query_to_sheet_job_can_interact_with_queue()
+    {
+        $this->assertContains(InteractsWithQueue::class, class_uses(AppendQueryToSheet::class));
+    }
+
+    /**
+     * @test
+     */
+    public function append_view_to_sheet_job_can_interact_with_queue()
+    {
+        $this->assertContains(InteractsWithQueue::class, class_uses(AppendViewToSheet::class));
+    }
+}
diff --git a/tests/ReadChunkTest.php b/tests/ReadChunkTest.php
deleted file mode 100644
index e30598756..000000000
--- a/tests/ReadChunkTest.php
+++ /dev/null
@@ -1,25 +0,0 @@
-<?php
-
-namespace Maatwebsite\Excel\Tests;
-
-use Illuminate\Queue\InteractsWithQueue;
-use Maatwebsite\Excel\Jobs\ReadChunk;
-
-class ReadChunkTest extends TestCase
-{
-    /**
-     * Setup the test environment.
-     */
-    protected function setUp(): void
-    {
-        parent::setUp();
-    }
-
-    /**
-     * @test
-     */
-    public function read_chunk_job_can_interact_with_queue()
-    {
-        $this->assertContains(InteractsWithQueue::class, class_uses(ReadChunk::class));
-    }
-}