Completed
Push — master ( 4f00d5...2afce4 )
by John
29s queued 13s
created

SyncRankClarification::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 30
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 23
c 1
b 0
f 1
nc 3
nop 0
dl 0
loc 30
rs 9.552
1
<?php
2
3
namespace App\Console\Commands\Scheduling;
4
5
use Illuminate\Console\Command;
6
use App\Models\ContestModel;
7
use App\Models\Eloquent\Contest;
8
use Cache;
9
use Carbon;
10
11
class SyncRankClarification extends Command
12
{
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature='scheduling:syncRankClarification';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description='Scheduling for remote rank and clarification sync';
26
27
    /**
28
     * Create a new command instance.
29
     *
30
     * @return void
31
     */
32
    public function __construct()
33
    {
34
        parent::__construct();
35
    }
36
37
    /**
38
     * Execute the console command.
39
     *
40
     * @return mixed
41
     */
42
    public function handle()
43
    {
44
        $time=Carbon::now();
45
        $this->line("<fg=yellow>[$time] Processing:  </>Sync Remote Contest Rank and Clarification");
46
47
        $contestModel=new ContestModel();
48
        $syncList=$contestModel->runningContest();
49
        foreach ($syncList as $syncContest) {
50
            if (!isset($syncContest['vcid'])) {
51
                $contest=Contest::find($syncContest['cid']);
52
                $contestRankRaw=$contest->rankRefresh();
53
                $cid=$syncContest['cid'];
54
                Cache::tags(['contest', 'rank'])->put($cid, $contestRankRaw);
55
                Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $contestRankRaw);
56
                continue;
57
            }
58
            $className="App\\Babel\\Extension\\hdu\\Synchronizer"; // TODO Add OJ judgement.
59
            $all_data=[
60
                'oj'=>"hdu",
61
                'vcid'=>$syncContest['vcid'],
62
                'gid'=>$syncContest['gid'],
63
                'cid'=>$syncContest['cid'],
64
            ];
65
            $hduSync=new $className($all_data);
66
            $hduSync->crawlRank();
67
            $hduSync->crawlClarification();
68
        }
69
70
        $time=Carbon::now();
71
        $this->line("<fg=green>[$time] Processed:   </>Successfully Synced Remote Contest Rank and Clarification");
72
    }
73
}
74