本文整理汇总了PHP中core\task\manager::adhoc_task_complete方法的典型用法代码示例。如果您正苦于以下问题:PHP manager::adhoc_task_complete方法的具体用法?PHP manager::adhoc_task_complete怎么用?PHP manager::adhoc_task_complete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core\task\manager
的用法示例。
在下文中一共展示了manager::adhoc_task_complete方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: 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");
}
示例3: run_all_adhoc_tasks
/**
* Executes all adhoc tasks in the queue. Useful for testing asynchronous behaviour.
*
* @return void
*/
public static function run_all_adhoc_tasks()
{
$now = time();
while (($task = \core\task\manager::get_next_adhoc_task($now)) !== null) {
try {
$task->execute();
\core\task\manager::adhoc_task_complete($task);
} catch (Exception $e) {
\core\task\manager::adhoc_task_failed($task);
}
}
}
示例4: cron_run
/**
* Execute cron tasks
*/
function cron_run()
{
global $DB, $CFG, $OUTPUT;
if (CLI_MAINTENANCE) {
echo "CLI maintenance mode active, cron execution suspended.\n";
exit(1);
}
if (moodle_needs_upgrading()) {
echo "Moodle upgrade pending, cron execution suspended.\n";
exit(1);
}
require_once $CFG->libdir . '/adminlib.php';
if (!empty($CFG->showcronsql)) {
$DB->set_debug(true);
}
if (!empty($CFG->showcrondebugging)) {
set_debugging(DEBUG_DEVELOPER, true);
}
core_php_time_limit::raise();
$starttime = microtime();
// Increase memory limit
raise_memory_limit(MEMORY_EXTRA);
// Emulate normal session - we use admin accoutn by default
cron_setup_user();
// Start output log
$timenow = time();
mtrace("Server Time: " . date('r', $timenow) . "\n\n");
// Run all scheduled tasks.
while (!\core\task\manager::static_caches_cleared_since($timenow) && ($task = \core\task\manager::get_next_scheduled_task($timenow))) {
mtrace("Execute scheduled task: " . $task->get_name());
cron_trace_time_and_memory();
$predbqueries = null;
$predbqueries = $DB->perf_get_queries();
$pretime = microtime(1);
try {
get_mailer('buffer');
$task->execute();
if ($DB->is_transaction_started()) {
throw new coding_exception("Task left transaction open");
}
if (isset($predbqueries)) {
mtrace("... used " . ($DB->perf_get_queries() - $predbqueries) . " dbqueries");
mtrace("... used " . (microtime(1) - $pretime) . " seconds");
}
mtrace("Scheduled task complete: " . $task->get_name());
\core\task\manager::scheduled_task_complete($task);
} catch (Exception $e) {
if ($DB && $DB->is_transaction_started()) {
error_log('Database transaction aborted automatically in ' . get_class($task));
$DB->force_transaction_rollback();
}
if (isset($predbqueries)) {
mtrace("... used " . ($DB->perf_get_queries() - $predbqueries) . " dbqueries");
mtrace("... used " . (microtime(1) - $pretime) . " seconds");
}
mtrace("Scheduled task failed: " . $task->get_name() . "," . $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');
unset($task);
}
// Run all adhoc tasks.
while (!\core\task\manager::static_caches_cleared_since($timenow) && ($task = \core\task\manager::get_next_adhoc_task($timenow))) {
mtrace("Execute adhoc task: " . get_class($task));
cron_trace_time_and_memory();
$predbqueries = null;
$predbqueries = $DB->perf_get_queries();
$pretime = microtime(1);
try {
get_mailer('buffer');
$task->execute();
if ($DB->is_transaction_started()) {
throw new coding_exception("Task left transaction open");
}
if (isset($predbqueries)) {
mtrace("... used " . ($DB->perf_get_queries() - $predbqueries) . " dbqueries");
mtrace("... used " . (microtime(1) - $pretime) . " seconds");
}
mtrace("Adhoc task complete: " . get_class($task));
\core\task\manager::adhoc_task_complete($task);
} catch (Exception $e) {
if ($DB && $DB->is_transaction_started()) {
error_log('Database transaction aborted automatically in ' . get_class($task));
$DB->force_transaction_rollback();
}
if (isset($predbqueries)) {
mtrace("... used " . ($DB->perf_get_queries() - $predbqueries) . " dbqueries");
mtrace("... used " . (microtime(1) - $pretime) . " seconds");
}
//.........这里部分代码省略.........
示例5: 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();
}
示例6: run_adhock_tasks
/**
* Run adhoc tasks.
*/
protected function run_adhock_tasks()
{
ob_start();
while ($task = \core\task\manager::get_next_adhoc_task(time())) {
$task->execute();
\core\task\manager::adhoc_task_complete($task);
}
ob_clean();
// Suppress mtrace debugging info.
}
示例7: 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);
}
示例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);
}
}