Over a million developers have joined DZone.

Windows Azure Mobile Services - Scheduler Scripts

· Cloud Zone

Learn about the benefits and drawbacks of microservices with best practices for your own architecture, brought to you in partnership with Iron.io.

Scheduler scripts are a very recent addition to Windows Azure Mobile Services. This is a very nice feature that supports periodic background processing in your mobile service. As a reminder, in the original release of Windows Azure Mobile Services, the only opportunity to run any server-side work (in scripts) is when the client performs an operation on a table (select, insert, update, or delete). For any kind of periodic processing, you'd have to use an external solution or have a client ping one of your tables -- a very ugly solution, as opposed to a scheduled script.

When would you use scheduled scripts?

  • To perform background processing on data uploaded by your users, or data that you retrieve from some external web services. For example, if you allow free text uploads, you might want to index the text for faster searching, or mine the text to detect interesting patterns.
  • To prune unnecessary data from your tables, such as dead push channels (channels that represent devices that are no longer available, or devices where you app is no longer installed).
  • To send push notifications at a certain time of day, or when an interesting event occurs at some point in the future. This is helpful when you have users all over the world, and you don't want to send a push notification to European users at 8PM Pacific time...
  • But another very useful thing you can do with scheduled scripts is test your server-side code. As you write your server-side scripts, the only way to test them previously was to hit one of your tables with a CRUD operation. With scheduled scripts, you can run your script by clicking a button in the Windows Azure Management Portal.

    Image borrowed from Scott Guthrie's blog.

    When I was working on push notification support in my unofficial Android SDK for Windows Azure Mobile Services, it was very helpful to have a script that sends push notifications to all registered devices, and invoke it whenever I want without hitting a table with a CRUD operation:

function TestPush() {
    var reqModule = require('request');
    var channelTable = tables.getTable('pushChannel');
        success: function(channels) {
            channels.forEach(function(channel) {
                    url: 'https://android.googleapis.com/gcm/send',
                    method: 'POST',
                    headers: {
                        'Authorization': 'key=MY_AUTHORIZATION_KEY'
                    json: {
                        registration_ids: [channel.regId],
                        data: {
                            "__builtInType": "notification",
                            "contentTitle": "Test title",
                            "contentText": "Test content",
                            "tickerText": "Test ticker",
                            "number": "42"
                }, function (err, resp, body) {
                    if (err || resp.statusCode !== 200) {
                        console.error('Error sending GCM push: ', err);

    With the most recent command-line tool release to manage your Windows Azure Mobile Services, you can list, download, and upload your scheduler scripts from the command-line. Unfortunately, there's no way at this point to invoke the scheduler script from the command-line tool, but you can easily test any script from the portal, as we've seen above.

    I am posting short links and updates on Twitter as well as on this blog. You can follow me: @goldshtn

The Cloud Zone is brought to you in partnership with Iron.io.  Learn about best practices and common pitfalls for working with Iron.io. Avoid the dead ends, and take the enlightened path.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}