Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INT-15296: webservice to retrieve proccesor status for course and con…
…tent events on ally
- Loading branch information
Diego Casas
committed
Nov 19, 2019
1 parent
4b2ffc5
commit 3875952
Showing
10 changed files
with
204 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Gets the queue status. | ||
* | ||
* @package tool_ally | ||
* @copyright Copyright (c) 2019 Blackboard Inc. (http://www.blackboard.com) | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace tool_ally\webservice; | ||
|
||
use tool_ally\push_config; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Gets the queue status. | ||
* | ||
* @package tool_ally | ||
* @copyright Copyright (c) 2019 Blackboard Inc. (http://www.blackboard.com) | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class processors_status extends loggable_external_api { | ||
/** | ||
* @return \external_function_parameters | ||
*/ | ||
public static function service_parameters() { | ||
return new \external_function_parameters([]); | ||
} | ||
|
||
/** | ||
* @return \external_single_structure | ||
*/ | ||
public static function service_returns() { | ||
return new \external_single_structure([ | ||
'is_valid' => new \external_value(PARAM_BOOL, 'Is the configuration valid?'), | ||
'is_cli_only' => new \external_value(PARAM_BOOL, 'is the processor set to push only?'), | ||
'when_cli_only_on' => new \external_value(PARAM_INT, 'When the cli went On'), | ||
'when_cli_only_off' => new \external_value(PARAM_INT, 'when the cli went Off'), | ||
'content_events' => new \external_value(PARAM_INT, 'Amount of content events in the queue'), | ||
'oldest_content_event' => new \external_value(PARAM_INT, 'timestamp for oldest content event queued'), | ||
'course_events' => new \external_value(PARAM_INT, 'Amount of course events in the queue'), | ||
'oldest_course_event' => new \external_value(PARAM_INT, 'timestamp for oldest course event queued') | ||
]); | ||
} | ||
|
||
/** | ||
* @param int $id Course id. | ||
* @return array | ||
*/ | ||
public static function execute_service() { | ||
global $DB; | ||
|
||
$config = new push_config(); | ||
$contentquery = $DB->get_record('tool_ally_content_queue', [], 'count(id) as amount, min(eventtime) as oldest'); | ||
$contentqueue = self::cast($contentquery); | ||
$deletedquery = $DB->get_record('tool_ally_deleted_content', [], 'count(id) as amount, min(timedeleted) as oldest'); | ||
$deletedqueue = self::cast($deletedquery); | ||
$coursequery = $DB->get_record('tool_ally_course_event', [], 'count(id) as amount, min(time) as oldest'); | ||
$coursequeue = self::cast($coursequery); | ||
$oldestcontent = null; | ||
if ($contentqueue->oldest != null && $deletedqueue->oldest != null) { | ||
$oldestcontent = $contentqueue->oldest < $deletedqueue->oldest ? $contentqueue->oldest : $deletedqueue->oldest; | ||
} else if ($contentqueue->oldest == null && $deletedqueue->oldest != null) { | ||
$oldestcontent = $deletedqueue ->oldest; | ||
} else if ($contentqueue->oldest != null && $deletedqueue->oldest == null) { | ||
$oldestcontent = $contentqueue ->oldest; | ||
} | ||
return (object)[ | ||
'is_valid' => $config->is_valid(), | ||
'is_cli_only' => $config->is_cli_only(), | ||
'when_cli_only_on' => (int) get_config('tool_ally', 'push_cli_only_on'), | ||
'when_cli_only_off' => (int) get_config('tool_ally', 'push_cli_only_off'), | ||
'content_events' => $contentqueue->amount + $deletedqueue->amount, | ||
'oldest_content_event' => $oldestcontent, | ||
'course_events' => $coursequeue->amount, | ||
'oldest_course_event' => $coursequeue->oldest, | ||
]; | ||
} | ||
public static function cast($queue) { | ||
$queue->amount = (int) $queue->amount; | ||
$queue->oldest = (int) $queue->oldest; | ||
return $queue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Test for Process status webservice. | ||
* | ||
* @package tool_ally | ||
* @copyright Copyright (c) 2019 Blackboard Inc. (http://www.blackboard.com) | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
use tool_ally\webservice\processors_status; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once(__DIR__.'/abstract_testcase.php'); | ||
|
||
/** | ||
* Test for content webservice. | ||
* | ||
* @package tool_ally | ||
* @copyright Copyright (c) 2019 Blackboard Inc. (http://www.blackboard.com) | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class tool_ally_webservice_processor_status_testcase extends tool_ally_abstract_testcase { | ||
public function test_service_return() { | ||
$returns = processors_status::service_returns(); | ||
$this->assertTrue($returns instanceof external_single_structure); | ||
} | ||
public function test_service() { | ||
|
||
// Save timestamp to compare to oldest event created. | ||
$basetime = time(); | ||
$this->resetAfterTest(); | ||
$this->setAdminUser(); | ||
|
||
set_config('push_cli_only', 1, 'tool_ally'); | ||
// Trigger 3 course event. | ||
$course = $this->getDataGenerator()->create_course(); | ||
$coursetime = time(); | ||
$this->getDataGenerator()->create_course(); | ||
$this->getDataGenerator()->create_course(); | ||
$section = $this->getDataGenerator()->create_course_section( | ||
['section' => 1, 'course' => $course]); | ||
// Trigger 3 content event. | ||
course_update_section($course, $section, ['summary' => 'test string']); | ||
$contenttime = time(); | ||
course_update_section($course, $section, ['summary' => 'test string1']); | ||
course_update_section($course, $section, ['summary' => 'test string2']); | ||
|
||
$returns = processors_status::execute_service(); | ||
$this->assertObjectHasAttribute('is_valid', $returns); | ||
$this->assertTrue($returns->is_valid == false); | ||
$this->assertObjectHasAttribute('is_cli_only', $returns); | ||
$this->assertTrue($returns->is_cli_only == 1); | ||
$this->assertObjectHasAttribute('when_cli_only_on', $returns); | ||
$this->assertObjectHasAttribute('when_cli_only_off', $returns); | ||
$this->assertObjectHasAttribute('content_events', $returns); | ||
$this->assertEquals(3, $returns->content_events); | ||
$this->assertObjectHasAttribute('oldest_content_event', $returns); | ||
$this->assertTrue(($basetime <= $returns->oldest_content_event) && ($returns->oldest_content_event <= $contenttime)); | ||
$this->assertObjectHasAttribute('course_events', $returns); | ||
$this->assertEquals(3, $returns->course_events); | ||
$this->assertObjectHasAttribute('oldest_course_event', $returns); | ||
$this->assertTrue(($basetime <= $returns->oldest_course_event) && ($returns->oldest_course_event <= $coursetime)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters