Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-80667

Running a task in the admin UI isn't possible, if config.php use environments variables

XMLWordPrintable

    • MOODLE_311_STABLE, MOODLE_39_STABLE, MOODLE_400_STABLE, MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE
    • MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE
    • MDL-80667-401
    • MDL-80667-403
    • Hide
      1. Clone the following repository locally: https://github.com/moodlehq/moodle-docker
      2. Copy the config.docker-template.php from that to your <DIRROOT>/config.php
      3. Configure/bring up the Docker site:

        $ cd <MOODLEDOCKERPATH>
        $ export MOODLE_DOCKER_WWWROOT=<DIRROOT>
        $ export MOODLE_DOCKER_DB=mysql
        $ bin/moodle-docker-compose up -d
        $ bin/moodle-docker-compose exec --user www-data webserver php admin/cli/install_database.php --agree-license --fullname="Docker" --shortname="Docker" --summary="Docker site" --adminpass="admin" --adminemail="admin@example.com"
        

      4. Log in to the site as admin at http://localhost:8000
      5. Navigate to Server > Tasks > Scheduled tasks from site administration
      6. Press Run now for any task (e.g. \editor_atto\task\autosave_cleanup_task)
      7. Press Run now on the subsequent confirmation screen
      8. Confirm the task executes successfully
      Show
      Clone the following repository locally: https://github.com/moodlehq/moodle-docker Copy the config.docker-template.php from that to your <DIRROOT>/config.php Configure/bring up the Docker site: $ cd <MOODLEDOCKERPATH> $ export MOODLE_DOCKER_WWWROOT=<DIRROOT> $ export MOODLE_DOCKER_DB=mysql $ bin/moodle-docker-compose up -d $ bin/moodle-docker-compose exec --user www-data webserver php admin/cli/install_database.php --agree-license --fullname="Docker" --shortname="Docker" --summary="Docker site" --adminpass="admin" --adminemail="admin@example.com" Log in to the site as admin at http://localhost:8000 Navigate to Server > Tasks > Scheduled tasks from site administration Press Run now for any task (e.g. \editor_atto\task\autosave_cleanup_task ) Press Run now on the subsequent confirmation screen Confirm the task executes successfully

      We recently noticed that running scheduled task by the gui fails silently if you use any getenv in the config.php.

      To reproduce:

      1.have at least 1 getenv in your config.php

      2. Run a schedule task from the gui, no logs will be shown

      This was introduced with this fix:

      https://tracker.moodle.org/browse/MDL-80309

      Specificaly this line:

      https://github.com/moodle/moodle/blob/580c009cacbd1093037599b2b92716154199a77e/lib/classes/task/manager.php#L1564

      By passing an empty array to the env_vars options of the proc_open function, no environment variables is passed to the process (see documentation of proc_open here https://www.php.net/manual/en/function.proc-open.php)

      As stderr isn't printed Moodle doesn't show any error, but you can change the code to see the error like this:

              $process = proc_open($command, $descriptorspec, $pipes, realpath('./'), []);
              if (is_resource($process)) {
                  echo("commmand output 2: " .stream_get_contents($pipes[2]);
                  while ($s = fgets($pipes[1])) {
                      mtrace($s, '');
                      flush();
                  }
              }
       

      This could be fixed by changing the code to:

      $process = proc_open($command, $descriptorspec, $pipes, realpath('./'), null);
      

      Which would then pass all environment variables.

            pholden Paul Holden
            olivierwenger Olivier Wenger
            ted-strauss-K1 ted-strauss-K1
            Andrew Lyons Andrew Lyons
            Kim Jared Lucas Kim Jared Lucas
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 hours, 50 minutes
                2h 50m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.