UploadFile   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 8

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 8
dl 0
loc 68
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handle() 0 4 1
A release() 0 14 2
1
<?php
2
namespace STS\StorageConnect\Jobs;
3
4
use Illuminate\Bus\Queueable;
5
use Illuminate\Contracts\Queue\ShouldQueue;
6
use Illuminate\Foundation\Bus\Dispatchable;
7
use Illuminate\Queue\InteractsWithQueue;
8
use Illuminate\Queue\SerializesModels;
9
use STS\Backoff\Backoff;
10
use STS\Backoff\Strategies\PolynomialStrategy;
11
use STS\StorageConnect\Models\CloudStorage;
12
13
/**
14
 * Class UploadFile
15
 * @package STS\StorageConnect\Jobs
16
 */
17
class UploadFile implements ShouldQueue
18
{
19
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
20
21
    /**
22
     * @var string
23
     */
24
    protected $source;
25
    /**
26
     * @var string
27
     */
28
    protected $destinationPath;
29
    /**
30
     * @var CloudStorage
31
     */
32
    protected $storage;
33
34
    /**
35
     * @var int
36
     */
37
    public $tries = 5;
38
39
    /**
40
     * @var int
41
     */
42
    public $timeout = 900;
43
44
    /**
45
     * UploadFile constructor.
46
     *
47
     * @param $source
48
     * @param $destinationPath
49
     * @param CloudStorage $storage
50
     */
51
    public function __construct($source, $destinationPath, CloudStorage $storage)
52
    {
53
        $this->source = $source;
54
        $this->destinationPath = $destinationPath;
55
        $this->storage = $storage;
56
    }
57
58
    /**
59
     *
60
     * @throws \STS\StorageConnect\Exceptions\StorageUnavailableException
61
     */
62
    public function handle()
63
    {
64
        $this->storage->upload($this->source, $this->destinationPath, false, $this);
65
    }
66
67
    /**
68
     *
69
     */
70
    public function release()
71
    {
72
        if(!$this->job) {
73
            return;
74
        }
75
76
        $this->job->release(
77
            (new Backoff)
78
                ->setStrategy(new PolynomialStrategy(5, 3))
79
                ->setWaitCap(900)
80
                ->setJitter(true)
81
                ->getWaitTime($this->job->attempts())
82
        );
83
    }
84
}
85