jesse_orange_newable
1 month ago
376
2
Laravel

Undefined properties in Job

Posted 1 month ago by jesse_orange_newable

I am using DocuSign within my application and I created a job to accomplish polling, that is, checking whether a document was updated without using a webhook.

The job is called PollDocuSignEnvelopes and makes a call to the DocuSign API to check for changes.

Here is the code:


<?php

namespace App\Jobs;

use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\CompanyRegistration;
use App\DocuSign\DocuSign as DocuSignWrapper;
use App\Notifications\RegistrationFormSigned;

class PollDocuSignEnvelopes implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * The number of times the job may be attempted.
     *
     * @var int
     */
    public $tries = 2;

    /**
     * The instance of DocuSignWrapper
     *
     * @var DocuSign
     */
    public $docusignWrapper;

    /**
     * Create a new job instance
     *
     * @param \App\DocuSign\DocuSign $docusignWrapper
     */
    public function __construct()
    {
        $this->docuSignWrapper = new DocuSignWrapper;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        // Retrieve the application forms that have been sent
        $envelopeIds = CompanyRegistration::select('envelope_id')
            ->whereNotNull('envelope_id')
            ->pluck('envelope_id')
            ->toArray();

        $envelopes = $this->docuSignWrapper->pollEnvelopeChanges($envelopeIds);

        foreach ($envelopes as $envelope) {
            $registration = CompanyRegistration::where('envelope_id', $envelope['envelope_id'])
                ->first()
                ->update([
                    'envelope_status' => $envelope['status'],
                ]);

            // If the status comes back as completed, notify the creator
            if ($registration->is_completed) {
                $registration->user->notify(new RegistrationFormSigned($registration));
            }
        }
    }

    /**
     * The job failed to process.
     *
     * @param  Exception $exception
     * @return void
     */
    public function failed(Exception $exception)
    {
        // Send user notification of failure, etc...
    }
}

However, apparently DocuSignWrapper is undefined even though I'm clearly setting it? Am I not supposed to new up classes in the __construct() method?


ErrorException: Undefined property: App\Jobs\PollDocuSignEnvelopes::$docuSignWrapper in /homepages/6/d142103519/htdocs/development-sites/ita-portal/app/Jobs/PollDocuSignEnvelopes.php:56
Stack trace:
#0 /homepages/6/d142103519/htdocs/development-sites/ita-portal/app/Jobs/PollDocuSignEnvelopes.php(56): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined prope...', '/homepages/6/d1...', 56, Array)
#1 [internal function]: App\Jobs\PollDocuSignEnvelopes->handle()
#2 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#3 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Container/Util.php(36): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#4 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\Container\Util::unwrapIfClosure(Object(Closure))
#5 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#6 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Container/Container.php(590): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#7 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(94): Illuminate\Container\Container->call(Array)
#8 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(130): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(App\Jobs\PollDocuSignEnvelopes))
#9 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(105): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(App\Jobs\PollDocuSignEnvelopes))
#10 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(98): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#11 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(83): Illuminate\Bus\Dispatcher->dispatchNow(Object(App\Jobs\PollDocuSignEnvelopes), false)
#12 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(130): Illuminate\Queue\CallQueuedHandler->Illuminate\Queue\{closure}(Object(App\Jobs\PollDocuSignEnvelopes))
#13 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(105): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(App\Jobs\PollDocuSignEnvelopes))
#14 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(85): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#15 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(59): Illuminate\Queue\CallQueuedHandler->dispatchThroughMiddleware(Object(Illuminate\Queue\Jobs\DatabaseJob), Object(App\Jobs\PollDocuSignEnvelopes))
#16 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(88): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#17 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(368): Illuminate\Queue\Jobs\Job->fire()
#18 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(314): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#19 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(134): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#20 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(112): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#21 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(96): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#22 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#23 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#24 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Container/Util.php(36): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#25 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\Container\Util::unwrapIfClosure(Object(Closure))
#26 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#27 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Container/Container.php(590): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#28 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Console/Command.php(134): Illuminate\Container\Container->call(Array)
#29 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/symfony/console/Command/Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#30 /homepages/6/d142103519/htdocs/development-sites/ita-portal/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))
#31 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/symfony/console/Application.php(1001): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#32 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/symfony/console/Application.php(271): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#33 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/symfony/console/Application.php(147): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#34 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Console/Application.php(93): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#35 /homepages/6/d142103519/htdocs/development-sites/ita-portal/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(131): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#36 /homepages/6/d142103519/htdocs/development-sites/ita-portal/artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#37 {main}

Please sign in or create an account to participate in this conversation.