Completed
Push — master ( a4261d...fc5e52 )
by John
14s
created

Kernel::schedule()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 62
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
cc 5
eloc 44
nc 4
nop 1
dl 0
loc 62
rs 8.9048
c 4
b 0
f 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace App\Console;
4
5
use Illuminate\Console\Scheduling\Schedule;
6
use App\Babel\Babel;
7
use App\Babel\Extension\hdu;
0 ignored issues
show
Bug introduced by
The type App\Babel\Extension\hdu was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use App\Models\RankModel;
9
use App\Models\SiteMapModel;
10
use App\Models\ContestModel;
11
use App\Models\GroupModel;
12
use App\Models\JudgerModel;
13
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
14
15
class Kernel extends ConsoleKernel
16
{
17
    /**
18
     * The Artisan commands provided by your application.
19
     *
20
     * @var array
21
     */
22
    protected $commands=[
23
        //
24
    ];
25
26
    /**
27
     * Define the application's command schedule.
28
     *
29
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
30
     * @return void
31
     */
32
    protected function schedule(Schedule $schedule)
33
    {
34
        $schedule->call(function () {
35
            $babel=new Babel();
36
            for ($i=1; $i<=12; $i++) {
37
                $babel->judge();
38
                sleep(5);
39
            }
40
            file_put_contents(storage_path('app/task-schedule.output'),"Successfully Synced Judger");
41
        })->everyMinute()->description("Sync Judger");
42
43
        $schedule->call(function () {
44
            $rankModel=new RankModel();
45
            $rankModel->rankList();
46
            file_put_contents(storage_path('app/task-schedule.output'),"Successfully Updated Rank");
47
        })->dailyAt('02:00')->description("Update Rank");
48
49
        $schedule->call(function () {
50
            $siteMapModel=new SiteMapModel();
0 ignored issues
show
Unused Code introduced by
The assignment to $siteMapModel is dead and can be removed.
Loading history...
51
            file_put_contents(storage_path('app/task-schedule.output'),"Successfully Updated SiteMap");
52
        })->dailyAt('02:00')->description("Update SiteMap");
53
54
        $schedule->call(function () {
55
            $groupModel=new GroupModel();
56
            $groupModel->cacheTrendingGroups();
57
            file_put_contents(storage_path('app/task-schedule.output'),"Successfully Cached Trending Groups");
58
        })->dailyAt('03:00')->description("Update Trending Groups");
59
60
        $schedule->call(function() {
61
            $contestModel = new ContestModel();
62
            $syncList = $contestModel->runningContest();
63
            foreach($syncList as $syncContest) {
64
                $className = "App\\Babel\\Extension\\hdu\\Synchronizer";  // TODO Add OJ judgement.
65
                $all_data = [
66
                    'oj'=>"hdu",
67
                    'vcid'=>$syncContest['vcid'],
68
                    'gid'=>$syncContest['gid']
69
                ];
70
                $hduSync = new $className($all_data);
71
                $hduSync->crawlRank();
72
                $hduSync->crawlClarification();
73
            }
74
            file_put_contents(storage_path('app/task-schedule.output'),"Successfully Synced Remote Rank and Clarification");
75
        })->everyMinute()->description("Sync Remote Rank and Clarification");
76
77
        // TODO it depends on the front interface.
78
        // $schedule->call(function() {
79
80
        // })->everyMinute()->description("Sync Remote Problem");
81
82
        $schedule->call(function () {
83
            $judgerModel=new JudgerModel();
84
            $judgerModel->updateServerStatus(1);
85
            file_put_contents(storage_path('app/task-schedule.output'),"Successfully Updated Judge Server Status");
86
        })->everyMinute()->description("Update Judge Server Status");
87
88
        if (!env("APP_DEBUG")) {
89
            $schedule->command('backup:run')->weekly()->description("BackUp Site");
90
        }
91
92
        if (!env("APP_DEBUG")) {
93
            $schedule->command('backup:run --only-db')->dailyAt('00:30')->description("BackUp DataBase");
94
        }
95
    }
96
97
    /**
98
     * Register the commands for the application.
99
     *
100
     * @return void
101
     */
102
    protected function commands()
103
    {
104
        $this->load(__DIR__.'/Commands');
105
106
        require base_path('routes/console.php');
107
    }
108
}
109