imTigger / laravel-job-status

Add ability to track Job progress, status and result dispatched to Queue.
MIT License
407 stars 60 forks source link

Checking a job status using ajax #18

Closed gasparyanyur closed 6 years ago

gasparyanyur commented 6 years ago

I am sending an ajax request to make a job to delete a folder tree. In FolderTreeJob I have a code look like this

class FolderDeleteJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, Trackable;

    private $node;

    public $count = 0;
    public  $jobDone = 0;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(StorageFiles $node)
    {
        $this->prepareStatus();
        $this->count = $node->count();
        $this->node = $node;
    }

    /**
     * Execute the job.
     *
     * @return bool|array
     */
    public function handle()
    {

        $this->setProgressMax($this->count);

        $node = $this->node;

        $this->delete($node);

        $this->setOutput(['total' => $this->count]);

    }

    private function delete(StorageFiles $file)
    {
        $this->jobDone++;
        foreach ($file->nodes as $node) {
            $this->delete($node);
        }

//        $file->delete();
        $this->setProgressNow($this->jobDone);
    }
}

Than I am sending an ajax request to chekc a job status (get the progress_now value). My controller code is

$job = JobStatus::find($id) But the $job is always null, but I have checked db, there is a row with id (for example id =1)

atlas-wong commented 6 years ago

should use: $job = JobStatus::where('job_id', $id)->first(); instead, the id of jobstatus is not the same as job

imTigger commented 6 years ago

This library do not intend to provide UI/API, as they will be too application-specific. You should use JobStatus model to make further use of the information collected.

yashiroiori commented 5 years ago

You need to send de progress with broadcast into the Job[queue] It's more easy use vue instance of jQuery

In this example the job receives the list of ids to sync from external system to Laravel

Creating job Pass list the Ids to process sync or your data to process but its may have the total data to process image

Job to process image

And the event emiter image

And into vue component to show the progress and catch broadcast progress image