|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Scheduling\Schedule; |
|
6
|
|
|
use App\Babel\Babel; |
|
7
|
|
|
use App\Models\Eloquent\JudgeServerModel as EloquentJudgeServerModel; |
|
8
|
|
|
use App\Models\RankModel; |
|
9
|
|
|
use App\Models\SiteMapModel; |
|
10
|
|
|
use App\Models\ContestModel; |
|
11
|
|
|
use App\Models\GroupModel; |
|
12
|
|
|
use App\Models\OJModel; |
|
13
|
|
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel; |
|
14
|
|
|
use Log; |
|
15
|
|
|
use Cache; |
|
16
|
|
|
|
|
17
|
|
|
class Kernel extends ConsoleKernel |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* The Artisan commands provided by your application. |
|
21
|
|
|
* |
|
22
|
|
|
* @var array |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $commands=[ |
|
25
|
|
|
// |
|
26
|
|
|
]; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Define the application's command schedule. |
|
30
|
|
|
* |
|
31
|
|
|
* @param \Illuminate\Console\Scheduling\Schedule $schedule |
|
32
|
|
|
* @return void |
|
33
|
|
|
*/ |
|
34
|
|
|
protected function schedule(Schedule $schedule) |
|
35
|
|
|
{ |
|
36
|
|
|
$schedule->call(function () { |
|
37
|
|
|
$babel=new Babel(); |
|
38
|
|
|
for ($i=1; $i<=12; $i++) { |
|
39
|
|
|
$babel->judge(); |
|
40
|
|
|
sleep(5); |
|
41
|
|
|
} |
|
42
|
|
|
// file_put_contents(storage_path('app/task-schedule.output'),"Successfully Synced Judger"); |
|
43
|
|
|
})->everyMinute()->description("Sync Judger"); |
|
44
|
|
|
|
|
45
|
|
|
$schedule->call(function () { |
|
46
|
|
|
$rankModel=new RankModel(); |
|
47
|
|
|
$rankModel->rankList(); |
|
48
|
|
|
// file_put_contents(storage_path('app/task-schedule.output'),"Successfully Updated Rank"); |
|
49
|
|
|
})->dailyAt('02:00')->description("Update Rank"); |
|
50
|
|
|
|
|
51
|
|
|
$schedule->call(function () { |
|
52
|
|
|
$siteMapModel=new SiteMapModel(); |
|
|
|
|
|
|
53
|
|
|
// file_put_contents(storage_path('app/task-schedule.output'),"Successfully Updated SiteMap"); |
|
54
|
|
|
})->dailyAt('02:00')->description("Update SiteMap"); |
|
55
|
|
|
|
|
56
|
|
|
$schedule->call(function () { |
|
57
|
|
|
$groupModel=new GroupModel(); |
|
58
|
|
|
$groupModel->cacheTrendingGroups(); |
|
59
|
|
|
// file_put_contents(storage_path('app/task-schedule.output'),"Successfully Cached Trending Groups"); |
|
60
|
|
|
})->dailyAt('03:00')->description("Update Trending Groups"); |
|
61
|
|
|
|
|
62
|
|
|
$schedule->call(function () { |
|
63
|
|
|
$contestModel = new ContestModel(); |
|
64
|
|
|
$syncList = $contestModel->runningContest(); |
|
65
|
|
|
foreach ($syncList as $syncContest) { |
|
66
|
|
|
if (!isset($syncContest['vcid'])) { |
|
67
|
|
|
$contestRankRaw=$contestModel->contestRankCache($syncContest['cid']); |
|
68
|
|
|
$cid=$syncContest['cid']; |
|
69
|
|
|
Cache::tags(['contest', 'rank'])->put($cid, $contestRankRaw); |
|
70
|
|
|
Cache::tags(['contest', 'rank'])->put("contestAdmin$cid", $contestRankRaw); |
|
71
|
|
|
continue ; |
|
72
|
|
|
} |
|
73
|
|
|
$className = "App\\Babel\\Extension\\hdu\\Synchronizer"; // TODO Add OJ judgement. |
|
74
|
|
|
$all_data = [ |
|
75
|
|
|
'oj'=>"hdu", |
|
76
|
|
|
'vcid'=>$syncContest['vcid'], |
|
77
|
|
|
'gid'=>$syncContest['gid'], |
|
78
|
|
|
'cid'=>$syncContest['cid'], |
|
79
|
|
|
]; |
|
80
|
|
|
$hduSync = new $className($all_data); |
|
81
|
|
|
$hduSync->crawlRank(); |
|
82
|
|
|
$hduSync->crawlClarification(); |
|
83
|
|
|
} |
|
84
|
|
|
// file_put_contents(storage_path('app/task-schedule.output'),"Successfully Synced Remote Rank and Clarification"); |
|
85
|
|
|
})->everyMinute()->description("Sync Remote Rank and Clarification"); |
|
86
|
|
|
|
|
87
|
|
|
$schedule->call(function () { |
|
88
|
|
|
$contestModel = new ContestModel(); |
|
89
|
|
|
$syncList = $contestModel->runningContest(); |
|
90
|
|
|
foreach ($syncList as $syncContest) { |
|
91
|
|
|
if (isset($syncContest['crawled'])) { |
|
92
|
|
|
if (!$syncContest['crawled']) { |
|
93
|
|
|
$className = "App\\Babel\\Extension\\hdu\\Synchronizer"; |
|
94
|
|
|
$all_data = [ |
|
95
|
|
|
'oj'=>"hdu", |
|
96
|
|
|
'vcid'=>$syncContest['vcid'], |
|
97
|
|
|
'gid'=>$syncContest['gid'], |
|
98
|
|
|
'cid'=>$syncContest['cid'], |
|
99
|
|
|
]; |
|
100
|
|
|
$hduSync = new $className($all_data); |
|
101
|
|
|
$hduSync->scheduleCrawl(); |
|
102
|
|
|
$contestModel->updateCrawlStatus($syncContest['cid']); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
})->everyMinute()->description("Sync Contest Problem"); |
|
107
|
|
|
|
|
108
|
|
|
$schedule->call(function () { |
|
109
|
|
|
$oidList=EloquentJudgeServerModel::column('oid'); |
|
110
|
|
|
$babel=new Babel(); |
|
111
|
|
|
foreach ($oidList as $oid) { |
|
112
|
|
|
$babel->monitor(["name"=>OJMOdel::ocode($oid)]); |
|
113
|
|
|
} |
|
114
|
|
|
})->everyMinute()->description("Update Judge Server Status"); |
|
115
|
|
|
|
|
116
|
|
|
if (!env("APP_DEBUG")) { |
|
117
|
|
|
$schedule->command('backup:run')->weekly()->description("BackUp Site"); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
if (!env("APP_DEBUG")) { |
|
121
|
|
|
$schedule->command('backup:run --only-db')->dailyAt('00:30')->description("BackUp DataBase"); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Register the commands for the application. |
|
127
|
|
|
* |
|
128
|
|
|
* @return void |
|
129
|
|
|
*/ |
|
130
|
|
|
protected function commands() |
|
131
|
|
|
{ |
|
132
|
|
|
$this->load(__DIR__.'/Commands'); |
|
133
|
|
|
|
|
134
|
|
|
require base_path('routes/console.php'); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|