Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

User:Damyon Wiese/Dev Meeting 20140429

From MoodleDocs

Atto

What does Atto mean ?

10^-16 (Really really small)

Where did it come from ?

It was originally just an experiment with contenteditable divs:
https://moodle.org/plugins/view.php?plugin=editor_contenteditable
The experiment worked really well - and was considered for Moodle 2.6:
https://moodle.org/plugins/view.php?plugin=editor_atto
Since work began on making this the new default editor for 2.7 it has been refactored (again) and is now faster, has many more features, is super accessible, and has extra spit and polish. This is basically a 2.0 version of the editor and has a very solid base for building new plugins and features. Lots of work has been done on it by all of the members of the HQ frontend team and it looks great!

What will happen to TinyMCE ?

Nothing - but - the version of TinyMCE shipped with Moodle is still based on version 2.X which is now unsupported by Moxiecode. TinyMCE will still be installed (but not default), and users who prefer it, can choose it as their preferred text editor in their profile. The core functionality of this version of TinyMCE should remain working, but bugs may appear with newer browsers over time.

What will happen to my TinyMCE plugins ?

Nothing - they will still work with TinyMCE, but will need to be re-written if they are to be used with Atto.

How do I write a plugin for Atto ?

https://docs.moodle.org/dev/Atto

What are some benefits of Atto plugins verses TinyMCE ones (in Moodle)?

Faster loading (all plugins are combo loaded in a single request with no callbacks for lang strings)
Use the Moodle/YUI standard dialogues and widgets
Simpler (follow all the conventions of other Moodle plugins)

No really ? I don't read docs. How do I make a plugin ?

https://docs.moodle.org/dev/Atto#Examples

No really ? I don't follow links. How do I make a plugin ?

lib/editor/atto/plugins/strike/yui/src/button/js/button.js

Y.namespace('M.atto_strike').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], {
    initializer: function() {
        this.addBasicButton({
            exec: 'strikeThrough',
            icon: 'e/strikethrough',

            // Watch the following tags and add/remove highlighting as appropriate:
            tags: 'strike'
        });
    }
});

What is this execCommand voodoo ?

https://developer.mozilla.org/en-US/docs/Web/API/document.execCommand

Does Atto support dragmath ?

No - Atto has a new equation editor that works directly with Moodles Tex filters. You can use either the old Tex filter, or the new MathJax filter. It was not desirable to port the drag math filter directly to Atto because it was a java applet, and drag/drop interactions do not support screen readers or touch screens nicely.

What is this MathJax filter you speak of ?

Well - lets get distracted by this shiny new thing for a second... It's a new maths filter that renders equations in the browser with Javascript. It uses the excellent MathJax javascript library (MDL-43856). MathJax equations render very nicely and it integrates well with screen readers (particularly Chrome Vox and MathPlayer). Previously people have used MathJax with Moodle by embedding the javascript include code in the head of every page and configuring it manually. The new filter just makes this process easier so that the configuration can be done with settings, and the rendering is more efficient (it only operates on parts of the page that can actually contain equations). It also works with content loaded via Ajax, which would not be possible without making it a filter. MathJax is loaded over CDN by default, but there is an option to install it locally. The default settings can be tweaked to support different delimiters and features (e.g. asciimath or mchem) without changing the code.

What cool new things will be added to Atto ?

Some that are highly desirable (and have been played with already) are: Auto saving to browsers local storage, drag and drop image upload, image resizing on upload, more media features (e.g. thumbnail previews)

Cron

(Big thanks to Petr and Fred)

Work on cron started because of the editpdf integration for Moodle 2.6. The way that works, the first time a teacher accesses a students submission, the conversion process kicks off to convert the pdf to a set of images that can used as backgrounds for the pdf editor - for huge files, this can take minutes and the teacher has to wait for a progress bar to walk across the screen. So - to fix this I wanted to kick off a background task at the point the student submit's their pdf. We don't want to wait for this to finish before giving feedback to the student, but we can start working on it right away, then when a teacher comes along to give feedback, the images have already been created and it will work like "magic".

So - following the chain of issues backwards - I needed to start some work that kept running after the current request has completed. Ahah - I could just put it in cron! Well - the downside of this is that cron is "single" threaded, it's scheduling is unreliable (because it depends on how long the jobs before take to complete), and failures will prevent the rest of cron from working. It may also be desirable to do the pdf conversions on a specific server.

So - thinking about this, I found that (as usual) all these problems had previously been discussed (before I was even a Moodle noob). I found https://docs.moodle.org/dev/Scheduled_Tasks_Proposal and http://tracker.moodle.org/browse/MDL-25499. Basically those specs were almost perfect so I got stuck in.

Where did I get up to for Moodle 2.7 ?

  • Locking - done
  • Parallel cron - done
  • Scheduling screens for cron tasks - done
  • Adhoc tasks - done
  • Using all of this to improve editpdf - not done :(

What does this mean for cron in 2.8 ?

  • Run it more!!!!

Because cron can do tasks in parallel, it will benefit from being run as often as once per minute. When it runs, if there is nothing scheduled - it will exit quickly and cheaply. If there is stuff to do - it will do it. If there is stuff to do, and cron is already doing something else - it will do it in parallel!

Cron is dead. Long live cron!

The cli and admin page that triggers cron has been rewritten to trigger the new scheduled tasks code. Any code that is still using the old cron API, will still be run by a dedicated scheduled task "legacy_cron". This means that all code using the old cron API is not really parallel, because there will only ever be one legacy_cron task running (which will loop through all the plugins and run their cron code). The replacement for the cron api - is scheduled tasks.

https://docs.moodle.org/dev/Task_API

You add a new class that inherits from \core\task\scheduled_task. You define it's default schedule in "<plugin>/db/tasks.php". That's it.

If you just want to run a task in the background asap - create an instance of an adhoc_task and queue it with:

\core\task\manager::queue_adhoc_task($task);

What else do I get for free ?

Now:

  • Run cron on several separate cluster nodes in parallel
  • Run specific tasks on a separate cluster nodes (maybe enrolment syncs) with CLI task runner
  • Run some really important task "Right now!!!" with CLI task runner

Later:

  • Replace all the moodle cli scripts with the CLI task runner (just needs some argument passing options added).
  • Use adhocs tasks for editpdf.