Completed
Pull Request — master (#23)
by
unknown
02:16
created

WatchableDispatchesJobs::dispatchNow()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Maqe\Qwatcher\Traits;
4
5
use DB;
6
use Illuminate\Contracts\Bus\Dispatcher;
7
use Maqe\Qwatcher\Facades\Qwatch;
8
use Maqe\Qwatcher\Tracks\QueueTracks;
9
10
trait WatchableDispatchesJobs
11
{
12
    /**
13
     * Dispatch a job to its appropriate handler.
14
     *
15
     * @param  mixed  $job
16
     * @return mixed
17
     */
18
    public function dispatch($job, array $meta = [])
19
    {
20
        $id = app(Dispatcher::class)->dispatch($job);
21
22
        Qwatch::tracks(new QueueTracks($id, $job, $meta));
23
24
        return $id;
25
    }
26
27
    /**
28
     * Dispatch a command to its appropriate handler in the current process.
29
     *
30
     * @param  mixed  $job
31
     * @return mixed
32
     */
33
    public function dispatchNow($job)
34
    {
35
        Qwatch::queued($job);
36
37
        return app(Dispatcher::class)->dispatchNow($job);
38
    }
39
}
40