MDL-80323 h5p: fail content type retrieval task on errors.

It's better for the task to fail gracefully rather than silently
swallow any errors, so that the task API can schedule re-tries.

If the endpoint is temporarily down and/or misbehaving, this will
allow admins to have clearer failures.
This commit is contained in:
Paul Holden
2024-01-08 10:06:43 +00:00
parent 591cdd8211
commit a85e2ca6ca
@@ -14,22 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Task to get the latest content types from the official H5P repository.
*
* @package core
* @copyright 2019 Victor Deniz <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\task;
use core_h5p\factory;
defined('MOODLE_INTERNAL') || die();
use invalid_response_exception;
/**
* A task to get the latest content types from the official H5P repository.
*
* @package core
* @copyright 2019 Victor Deniz <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -57,6 +50,8 @@ class h5p_get_content_types_task extends scheduled_task {
/**
* Execute the task.
*
* @throws invalid_response_exception If request to get the latest content types fails (usually due to a transient error)
*/
public function execute() {
// MDL-68579, avoid execute the task through behat tests.
@@ -69,7 +64,7 @@ class h5p_get_content_types_task extends scheduled_task {
$result = $core->fetch_latest_content_types();
if (!empty($result->error)) {
mtrace($result->error);
throw new invalid_response_exception($result->error);
} else {
$numtypesinstalled = count($result->typesinstalled);
mtrace("{$numtypesinstalled} new content types installed");