Skip to content

Commit

Permalink
Add task:check command
Browse files Browse the repository at this point in the history
  • Loading branch information
jyhsu2000 committed Sep 10, 2020
1 parent 3241da6 commit b136c40
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions app/Console/Commands/TaskCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace App\Console\Commands;

use App\Services\TaskService;
use App\Student;
use Illuminate\Console\Command;

class TaskCheck extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'task:check {nid?}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Check task progress of student(s)';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$nid = strtoupper($this->argument('nid'));
$studentQuery = Student::query();
if ($nid) {
$this->info('Query student with NID: ' . $nid);
$studentQuery->where('nid', $nid);
}
$studentCount = $studentQuery->count();
if ($studentCount == 0) {
$this->error('No students found');

return;
}
$taskService = app(TaskService::class);
$this->info('Starting checking...');
$bar = $this->output->createProgressBar($studentCount);
$bar->setFormat("%current%/%max% [%bar%] %percent:3s%% %message%");
$bar->start();

$studentQuery->chunk(10, function ($students) use ($taskService, &$bar) {
/** @var Student $student */
foreach ($students as $student) {
$bar->setMessage('Checking Student: ' . $student->display_name);
$taskService->checkProgress($student);
$bar->advance();
}
});
$bar->setMessage('');
$bar->finish();
$this->info('');
$this->info('Checking finished');
}
}

0 comments on commit b136c40

Please sign in to comment.