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

WatchableDispatchesJobs   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A dispatch() 0 8 1
A dispatchNow() 0 6 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