当前位置: 首页>>代码示例>>PHP>>正文


PHP task\manager类代码示例

本文整理汇总了PHP中core\task\manager的典型用法代码示例。如果您正苦于以下问题:PHP manager类的具体用法?PHP manager怎么用?PHP manager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了manager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_get_next_adhoc_task

 public function test_get_next_adhoc_task()
 {
     $this->resetAfterTest(true);
     // Create an adhoc task.
     $task = new \core\task\adhoc_test_task();
     // Queue it.
     $task = \core\task\manager::queue_adhoc_task($task);
     $now = time();
     // Get it from the scheduler.
     $task = \core\task\manager::get_next_adhoc_task($now);
     $this->assertNotNull($task);
     $task->execute();
     \core\task\manager::adhoc_task_failed($task);
     // Should not get any task.
     $task = \core\task\manager::get_next_adhoc_task($now);
     $this->assertNull($task);
     // Should get the adhoc task (retry after delay).
     $task = \core\task\manager::get_next_adhoc_task($now + 120);
     $this->assertNotNull($task);
     $task->execute();
     \core\task\manager::adhoc_task_complete($task);
     // Should not get any task.
     $task = \core\task\manager::get_next_adhoc_task($now);
     $this->assertNull($task);
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:25,代码来源:adhoc_task_test.php

示例2: definition

 public function definition()
 {
     $mform = $this->_form;
     /** @var \core\task\scheduled_task $task */
     $task = $this->_customdata;
     $lastrun = $task->get_last_run_time() ? userdate($task->get_last_run_time()) : get_string('never');
     $nextrun = $task->get_next_run_time();
     if ($task->get_disabled()) {
         $nextrun = get_string('disabled', 'tool_task');
     } else {
         if ($nextrun > time()) {
             $nextrun = userdate($nextrun);
         } else {
             $nextrun = get_string('asap', 'tool_task');
         }
     }
     $mform->addElement('static', 'lastrun', get_string('lastruntime', 'tool_task'), $lastrun);
     $mform->addElement('static', 'nextrun', get_string('nextruntime', 'tool_task'), $nextrun);
     $mform->addElement('text', 'minute', get_string('taskscheduleminute', 'tool_task'));
     $mform->setType('minute', PARAM_RAW);
     $mform->addHelpButton('minute', 'taskscheduleminute', 'tool_task');
     $mform->addElement('text', 'hour', get_string('taskschedulehour', 'tool_task'));
     $mform->setType('hour', PARAM_RAW);
     $mform->addHelpButton('hour', 'taskschedulehour', 'tool_task');
     $mform->addElement('text', 'day', get_string('taskscheduleday', 'tool_task'));
     $mform->setType('day', PARAM_RAW);
     $mform->addHelpButton('day', 'taskscheduleday', 'tool_task');
     $mform->addElement('text', 'month', get_string('taskschedulemonth', 'tool_task'));
     $mform->setType('month', PARAM_RAW);
     $mform->addHelpButton('month', 'taskschedulemonth', 'tool_task');
     $mform->addElement('text', 'dayofweek', get_string('taskscheduledayofweek', 'tool_task'));
     $mform->setType('dayofweek', PARAM_RAW);
     $mform->addHelpButton('dayofweek', 'taskscheduledayofweek', 'tool_task');
     $mform->addElement('advcheckbox', 'disabled', get_string('disabled', 'tool_task'));
     $mform->addHelpButton('disabled', 'disabled', 'tool_task');
     $mform->addElement('advcheckbox', 'resettodefaults', get_string('resettasktodefaults', 'tool_task'));
     $mform->addHelpButton('resettodefaults', 'resettasktodefaults', 'tool_task');
     $mform->disabledIf('minute', 'resettodefaults', 'checked');
     $mform->disabledIf('hour', 'resettodefaults', 'checked');
     $mform->disabledIf('day', 'resettodefaults', 'checked');
     $mform->disabledIf('dayofweek', 'resettodefaults', 'checked');
     $mform->disabledIf('month', 'resettodefaults', 'checked');
     $mform->disabledIf('disabled', 'resettodefaults', 'checked');
     $mform->addElement('hidden', 'task', get_class($task));
     $mform->setType('task', PARAM_RAW);
     $mform->addElement('hidden', 'action', 'edit');
     $mform->setType('action', PARAM_ALPHANUMEXT);
     $this->add_action_buttons(true, get_string('savechanges'));
     // Do not use defaults for existing values, the set_data() is the correct way.
     $this->set_data(\core\task\manager::record_from_scheduled_task($task));
 }
开发者ID:educacionbe,项目名称:cursos,代码行数:51,代码来源:edit_scheduled_task_form.php

示例3: write_setting

 /**
  * Store new setting
  *
  * @param mixed $data string or array, must not be NULL
  * @return string empty string if ok, string error message otherwise
  */
 public function write_setting($data)
 {
     $oldvalue = get_config($this->plugin, $this->name);
     if ($oldvalue == $data && !empty($data)) {
         return '';
     }
     if (!empty($data)) {
         $this->config_write($this->name, $data);
         $this->config_write('sharepoint_initialized', '0');
         $sharepointinit = new \local_o365\task\sharepointinit();
         \core\task\manager::queue_adhoc_task($sharepointinit);
     } else {
         // Support default value so it doesn't prompt for setting on install.
         $this->config_write($this->name, '');
     }
     return '';
 }
开发者ID:jamesmcq,项目名称:o365-moodle,代码行数:23,代码来源:sharepointlink.php

示例4: check_status

 public function check_status(thresholds $thresholds, $params = array())
 {
     if (!isset($params['task'])) {
         throw new invalid_service_exception("Task parameter required");
     }
     if (!($task = \core\task\manager::get_scheduled_task($params['task']))) {
         throw new invalid_service_exception("Task not found");
     }
     $result = new status_result();
     $lastrun = $task->get_last_run_time();
     if (!$lastrun) {
         $result->text = 'Task has never run';
         $result->status = service::NAGIOS_STATUS_UNKNOWN;
     } else {
         $timeelapsed = time() - $lastrun;
         $result->status = $thresholds->check($timeelapsed);
         $result->text = "Last ran at " . date(DATE_RSS, $lastrun) . ", {$timeelapsed} seconds ago";
     }
     return $result;
 }
开发者ID:pauln,项目名称:local_nagios,代码行数:20,代码来源:scheduled_task_service.php

示例5: roledeleted

 /**
  * Called when an role has been removed.
  */
 public static function roledeleted(\core\event\role_unassigned $event)
 {
     global $CFG;
     if (\panopto_data::get_panopto_course_id($event->courseid) === false || $CFG->version < $requiredVersion) {
         return;
     }
     $task = new \block_panopto\task\update_user();
     $task->set_custom_data(array('courseid' => $event->courseid, 'relateduserid' => $event->relateduserid, 'contextid' => $event->contextid, 'eventtype' => "role"));
     if ($CFG->block_panopto_async_tasks) {
         \core\task\manager::queue_adhoc_task($task);
     } else {
         $task->execute();
     }
 }
开发者ID:edwinp-catalyst-eu,项目名称:Moodle-2.0-plugin-for-Panopto,代码行数:17,代码来源:rollingsync.php

示例6: define

 *   - For debugging & better logging, you are encouraged to use in the command line:
 *     -d log_errors=1 -d error_reporting=E_ALL -d display_errors=0 -d html_errors=0
 *
 * Performance notes:
 * We have optimized it as best as we could for PostgreSQL and MySQL, with 27K students
 * we have seen this take 10 minutes.
 *
 * @package    auth_cas
 * @copyright  2007 Jerome Gutierrez - based on code by Martin Langhoff
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @deprecated since Moodle 3.0 MDL-51824 - please do not use this CLI script any more, use scheduled task instead.
 * @todo MDL-50264 This will be deleted in Moodle 3.2.
 */
define('CLI_SCRIPT', true);
require __DIR__ . '/../../../config.php';
require_once $CFG->dirroot . '/course/lib.php';
require_once $CFG->libdir . '/clilib.php';
// Ensure errors are well explained
set_debugging(DEBUG_DEVELOPER, true);
if (!is_enabled_auth('cas')) {
    error_log('[AUTH CAS] ' . get_string('pluginnotenabled', 'auth_ldap'));
    die;
}
cli_problem('[AUTH CAS] The sync users cron has been deprecated. Please use the scheduled task instead.');
// Abort execution of the CLI script if the auth_cas\task\sync_task is enabled.
$task = \core\task\manager::get_scheduled_task('auth_cas\\task\\sync_task');
if (!$task->get_disabled()) {
    cli_error('[AUTH CAS] The scheduled task sync_task is enabled, the cron execution has been aborted.');
}
$casauth = get_auth_plugin('cas');
$casauth->sync_users(true);
开发者ID:evltuma,项目名称:moodle,代码行数:31,代码来源:sync_users.php

示例7: get_mailer

    try {
        get_mailer('buffer');
        $task->execute();
        if (isset($predbqueries)) {
            mtrace("... used " . ($DB->perf_get_queries() - $predbqueries) . " dbqueries");
            mtrace("... used " . (microtime(1) - $pretime) . " seconds");
        }
        mtrace("Task completed.");
        \core\task\manager::scheduled_task_complete($task);
        get_mailer('close');
        exit(0);
    } catch (Exception $e) {
        if ($DB->is_transaction_started()) {
            $DB->force_transaction_rollback();
        }
        mtrace("... used " . ($DB->perf_get_queries() - $predbqueries) . " dbqueries");
        mtrace("... used " . (microtime(true) - $pretime) . " seconds");
        mtrace("Task failed: " . $e->getMessage());
        if ($CFG->debugdeveloper) {
            if (!empty($e->debuginfo)) {
                mtrace("Debug info:");
                mtrace($e->debuginfo);
            }
            mtrace("Backtrace:");
            mtrace(format_backtrace($e->getTrace(), true));
        }
        \core\task\manager::scheduled_task_failed($task);
        get_mailer('close');
        exit(1);
    }
}
开发者ID:educakanchay,项目名称:campus,代码行数:31,代码来源:schedule_task.php

示例8: run_adhock_tasks

 /**
  * Run adhoc tasks.
  */
 protected function run_adhock_tasks()
 {
     while ($task = \core\task\manager::get_next_adhoc_task(time())) {
         $task->execute();
         \core\task\manager::adhoc_task_complete($task);
     }
 }
开发者ID:HuiChangZhai,项目名称:moodle,代码行数:10,代码来源:eventobservers_test.php

示例9: test_get_broken_scheduled_task

 public function test_get_broken_scheduled_task()
 {
     global $DB;
     $this->resetAfterTest(true);
     // Delete all existing scheduled tasks.
     $DB->delete_records('task_scheduled');
     // Add a scheduled task.
     // A broken task that runs all the time.
     $record = new stdClass();
     $record->blocking = true;
     $record->minute = '*';
     $record->hour = '*';
     $record->dayofweek = '*';
     $record->day = '*';
     $record->month = '*';
     $record->component = 'test_scheduled_task';
     $record->classname = '\\core\\task\\scheduled_test_task_broken';
     $DB->insert_record('task_scheduled', $record);
     $now = time();
     // Should not get any task.
     $task = \core\task\manager::get_next_scheduled_task($now);
     $this->assertDebuggingCalled();
     $this->assertNull($task);
 }
开发者ID:abhilash1994,项目名称:moodle,代码行数:24,代码来源:scheduled_task_test.php

示例10: i_run_all_adhoc_tasks

 /**
  * Runs all ad-hoc tasks in the queue.
  *
  * This is faster and more reliable than running cron (running cron won't
  * work more than once in the same test, for instance). However it is
  * a little less 'realistic'.
  *
  * While the task is running, we suppress mtrace output because it makes
  * the Behat result look ugly.
  *
  * @Given /^I run all adhoc tasks$/
  * @throws DriverException
  */
 public function i_run_all_adhoc_tasks()
 {
     // Do setup for cron task.
     cron_setup_user();
     // Run tasks. Locking is handled by get_next_adhoc_task.
     $now = time();
     ob_start();
     // Discard task output as not appropriate for Behat output!
     while (($task = \core\task\manager::get_next_adhoc_task($now)) !== null) {
         try {
             $task->execute();
             // Mark task complete.
             \core\task\manager::adhoc_task_complete($task);
         } catch (Exception $e) {
             // Mark task failed and throw exception.
             \core\task\manager::adhoc_task_failed($task);
             ob_end_clean();
             throw new DriverException('An adhoc task failed', 0, $e);
         }
     }
     ob_end_clean();
 }
开发者ID:lucaboesch,项目名称:moodle,代码行数:35,代码来源:behat_general.php

示例11: purge_all_caches

/**
 * Invalidates browser caches and cached data in temp.
 *
 * IMPORTANT - If you are adding anything here to do with the cache directory you should also have a look at
 * {@link phpunit_util::reset_dataroot()}
 *
 * @return void
 */
function purge_all_caches()
{
    global $CFG, $DB;
    reset_text_filters_cache();
    js_reset_all_caches();
    theme_reset_all_caches();
    get_string_manager()->reset_caches();
    core_text::reset_caches();
    if (class_exists('core_plugin_manager')) {
        core_plugin_manager::reset_caches();
    }
    // Bump up cacherev field for all courses.
    try {
        increment_revision_number('course', 'cacherev', '');
    } catch (moodle_exception $e) {
        // Ignore exception since this function is also called before upgrade script when field course.cacherev does not exist yet.
    }
    $DB->reset_caches();
    cache_helper::purge_all();
    // Purge all other caches: rss, simplepie, etc.
    clearstatcache();
    remove_dir($CFG->cachedir . '', true);
    // Make sure cache dir is writable, throws exception if not.
    make_cache_directory('');
    // This is the only place where we purge local caches, we are only adding files there.
    // The $CFG->localcachedirpurged flag forces local directories to be purged on cluster nodes.
    remove_dir($CFG->localcachedir, true);
    set_config('localcachedirpurged', time());
    make_localcache_directory('', true);
    \core\task\manager::clear_static_caches();
}
开发者ID:lucaboesch,项目名称:moodle,代码行数:39,代码来源:moodlelib.php

示例12: test_file_temp_cleanup_task

    /**
     * Test that the file_temp_cleanup_task removes directories and
     * files as expected.
     */
    public function test_file_temp_cleanup_task() {
        global $CFG;

        // Create directories.
        $dir = $CFG->tempdir . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR . 'backup01' . DIRECTORY_SEPARATOR . 'courses';
        mkdir($dir, 0777, true);

        // Create files to be checked and then deleted.
        $file01 = $dir . DIRECTORY_SEPARATOR . 'sections.xml';
        file_put_contents($file01, 'test data 001');
        $file02 = $dir . DIRECTORY_SEPARATOR . 'modules.xml';
        file_put_contents($file02, 'test data 002');
        // Change the time modified for the first file, to a time that will be deleted by the task (greater than seven days).
        touch($file01, time() - (8 * 24 * 3600));

        $task = \core\task\manager::get_scheduled_task('\\core\\task\\file_temp_cleanup_task');
        $this->assertInstanceOf('\core\task\file_temp_cleanup_task', $task);
        $task->execute();

        // Scan the directory. Only modules.xml should be left.
        $filesarray = scandir($dir);
        $this->assertEquals('modules.xml', $filesarray[2]);
        $this->assertEquals(3, count($filesarray));

        // Change the time modified on modules.xml.
        touch($file02, time() - (8 * 24 * 3600));
        // Change the time modified on the courses directory.
        touch($CFG->tempdir . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR . 'backup01' . DIRECTORY_SEPARATOR .
                'courses', time() - (8 * 24 * 3600));
        // Run the scheduled task to remove the file and directory.
        $task->execute();
        $filesarray = scandir($CFG->tempdir . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR . 'backup01');
        // There should only be two items in the array, '.' and '..'.
        $this->assertEquals(2, count($filesarray));

        // Change the time modified on all of the files and directories.
        $dir = new \RecursiveDirectoryIterator($CFG->tempdir);
        // Show all child nodes prior to their parent.
        $iter = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::CHILD_FIRST);

        for ($iter->rewind(); $iter->valid(); $iter->next()) {
            $node = $iter->getRealPath();
            touch($node, time() - (8 * 24 * 3600));
        }

        // Run the scheduled task again to remove all of the files and directories.
        $task->execute();
        $filesarray = scandir($CFG->tempdir);
        // All of the files and directories should be deleted.
        // There should only be two items in the array, '.' and '..'.
        $this->assertEquals(2, count($filesarray));
    }
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:56,代码来源:scheduled_task_test.php

示例13: run_adhock_tasks

 /**
  * Run adhoc tasks.
  */
 protected function run_adhock_tasks()
 {
     while ($task = \core\task\manager::get_next_adhoc_task(time())) {
         $task->execute();
         \core\task\manager::adhoc_task_complete($task);
     }
     $this->expectOutputRegex("/^Sending message to the user with id \\d+ for the subscription with id \\d+\\.\\.\\..Sent./ms");
 }
开发者ID:gabrielrosset,项目名称:moodle,代码行数:11,代码来源:eventobservers_test.php

示例14: execute

 /**
  * Execute task
  * 
  * @global \moodle_database $DB
  * @global \stdClass $CFG
  * @return void
  * @throws \moodle_exception
  */
 public function execute()
 {
     global $DB, $CFG;
     // Not going to work if we're missing settings.
     if (!isset($CFG->block_mailchimp_apicode) || !isset($CFG->block_mailchimp_listid) || !isset($CFG->block_mailchimp_linked_profile_field)) {
         return;
     }
     echo '== Beginning synchronization of MailChimp subscribers ==', "\n";
     // Get all users in MailChimp and synchronize.
     echo 'Getting list of users in MailChimp.', "\n";
     $listusers = \block_mailchimp\helper::getMembersSync();
     if (!$listusers) {
         debugging("ERROR: Failed to get list of all members. Unable to synchronize users.");
         return;
     }
     // If there is an interest specified, filter out users who do not have this interest marked.
     if (isset($CFG->block_mailchimp_interest) && !$CFG->block_mailchimp_interest == "0") {
         foreach ($listusers['members'] as $key => $externaluser) {
             if ($externaluser['interests'][$CFG->block_mailchimp_interest] == false) {
                 unset($listusers['members'][$key]);
             }
         }
         // Reindex the array
         $listusers['members'] = array_values($listusers['members']);
     }
     $listuserscount = count($listusers['members']);
     // Get list of users in Moodle
     echo 'Getting list of users in Moodle.', "\n";
     $moodleusers = $DB->get_records('user');
     $moodleuserscount = count($moodleusers);
     // Convert Moodle email addresses to lower case. Mailchimp stores emails in lower case and calculates the MD5 hash on the lower case email.
     foreach ($moodleusers as $moodleuser) {
         $moodleuser->email = strtolower($moodleuser->email);
     }
     // Sort MailChimp users list
     echo 'Sorting list of MailChimp users.', "\n";
     foreach ($listusers['members'] as $key => $row) {
         $emails[$key] = $row['email_address'];
     }
     array_multisort($emails, SORT_ASC, $listusers['members']);
     unset($emails);
     // Sort Moodle users list
     echo 'Sorting list of Moodle users.', "\n";
     foreach ($moodleusers as $key => $row) {
         $emails[$key] = $row->email;
     }
     array_multisort($emails, SORT_ASC, $moodleusers);
     unset($emails);
     // Syncronize the list of users in Moodle with those in Mailchimp
     echo '== Starting sync of Moodle users with users in MailChimp ==', "\n";
     foreach ($moodleusers as $moodleusersynckey => $moodleuser) {
         $statuspercent = round($moodleusersynckey / $moodleuserscount * 100, 1, PHP_ROUND_HALF_UP);
         echo $statuspercent, "%        \r";
         if (isguestuser($moodleuser)) {
             continue;
         }
         $this->synchronize_user($moodleuser, $listusers);
     }
     echo 'Done.', "\n";
     //Iterate through mailchimp list and compare to moodle users' emails. If the email is not found in moodle, delete from mailchimp list.
     echo '== Starting MailChimp list cleanup ==', "\n";
     foreach ($listusers['members'] as $listuserskey => $externaluser) {
         $statuspercent = round($listuserskey / $listuserscount * 100, 1, PHP_ROUND_HALF_UP);
         echo $statuspercent, "%        \r";
         $this->synchronize_mcuser($externaluser, $moodleusers);
     }
     echo 'Done.', "\n";
     echo '== Finished MailChimp syncronization ==', "\n";
     // Clean up static caches, since this process runs for a long time and (potentially) changes many DB records. See https://docs.moodle.org/dev/Task_API#Caches
     \core\task\manager::clear_static_caches();
 }
开发者ID:saylordotorg,项目名称:moodle-block_mailchimp,代码行数:79,代码来源:mcsynchronize.php

示例15: test_get_next_adhoc_task_future

 /**
  * Test future adhoc task execution.
  */
 public function test_get_next_adhoc_task_future()
 {
     $this->resetAfterTest(true);
     $now = time();
     // Create an adhoc task in future.
     $task = new \core\task\adhoc_test_task();
     $task->set_next_run_time($now + 1000);
     \core\task\manager::queue_adhoc_task($task);
     // Fetching the next task should not return anything.
     $this->assertNull(\core\task\manager::get_next_adhoc_task($now));
     // Fetching in the future should return the task.
     $task = \core\task\manager::get_next_adhoc_task($now + 1020);
     $this->assertInstanceOf('\\core\\task\\adhoc_test_task', $task);
     $task->execute();
     \core\task\manager::adhoc_task_complete($task);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:19,代码来源:adhoc_task_test.php


注:本文中的core\task\manager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。