| Conditions | 10 |
| Paths | 4 |
| Total Lines | 88 |
| Code Lines | 63 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| Bugs | 1 | Features | 2 |
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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 | } |
||
| 137 |