メイン コンテンツにスキップ

 Subscribe

We just published a new RTM release of the Azure WebJobs SDK packed with new features! This release opens a new extensibility model for the SDK which allows you to write custom triggers and binders for example, triggering functions based on file events, periodic schedules, etc. It leads to simplicity in developing and managing WebJobs, since you can now have a single WebJob with functions which can be triggered on Azure Queues, Blobs, Service Bus, Files, Timers, WebHooks – GitHub, Slack, Instagram, IFTTT and more. You can also set up alerts where you can send notification when a function fails. We’ve also added many new features and made many bug fixes based on your feedback.

Features in this release

This release is packed with many features around the new extensibility model for the SDK which allows you to write customer triggers and binders as well as core improvements to existing feature set. Following are some of the highlights in this release.

Extensible model for writing your own triggers and binders

The initial release of the SDK was focused on triggering functions based on events from Azure Queues, Blobs and Service Bus. Since the release of the SDK, we have received lots of feedback that developers would like to add more triggers such as triggering a function based on file events, schedule based triggers, events from SQL server and more. The new extensibility model allows extension authors to write new triggers and binders, and those extensions can be used by others in their applications.

Redis.WebJob.Extensions is a project being built by Jason Haley which allows a user to trigger functions based on events in Redis.

We created a new open source repo which contains extensions demonstrating the new extensibility model. Follow this detailed guide on the architecture of the extensibility model. There is a sample you can use to get started with to write your own trigger or binder.

New triggers, binders and attributes

This release include many new ways for the SDK to trigger functions. Some new ways of triggering functions are as follows:

  • Schedule based using TimerTrigger
  • File based events using FileTrigger
  • Ensure only a single instance of a particular function will run at any given time across multiple hosts using Singleton attribute
  • Allow a function to timeout or after a specified amount of time using Timeout attribute
  • Send emails on function completion using the new SendGrid binding
  • Trigger functions based on some error threshold (Raise an alert if there are more than 10 errors in the last 1 hr) using ErrorTrigger.
  • Trigger functions based on generic WebHook events using WebHookTrigger (​preview)

The following snippet of code shows a WebJob which has functions which can be triggered on all these events. As you can see you can now have a single WebJob running with all these functions being triggered on different events. You can also leverage all the existing features of the SDK such as parameter binding, route matching and more.

    public class Functions
    {
        public static void ProcessTimer([TimerTrigger("*/15 * * * * *", RunOnStartup = true)]
        TimerInfo info, [Queue("queue")] out string message)
        {
            message = info.FormatNextOccurrences(1);
        }

        public static void ProcessQueueMessage([QueueTrigger("queue")] string message,
        TextWriter log)
        {
            log.WriteLine(message);
        }

        public static void ProcessFileAndUploadToBlob(
            [FileTrigger(@"import{name}", "*.*", autoDelete: true)] Stream file,
            [Blob(@"processed/{name}", FileAccess.Write)] Stream output,
            string name,
            TextWriter log)
        {
            output = file;
            file.Close();
            log.WriteLine(string.Format("Processed input file '{0}'!", name));
        }

        [Singleton]
        public static void ProcessWebHookA([WebHookTrigger] string body, TextWriter log)
        {
            log.WriteLine(string.Format("WebHookA invoked! Body: {0}", body));
        }

        public static void ProcessGitHubWebHook([WebHookTrigger] string body, TextWriter log)
        {
            dynamic issueEvent = JObject.Parse(body);
            log.WriteLine(string.Format("GitHub WebHook invoked! ('{0}', '{1}')",
                issueEvent.issue.title, issueEvent.action));
        }

        public static void ErrorMonitor(
        [ErrorTrigger("00:01:00", 1)] TraceFilter filter, TextWriter log,
        [SendGrid(
            To = "admin@emailaddress.com",
            Subject = "Error!")]
         SendGridMessage message)
        {
            // log last 5 detailed errors to the Dashboard
            log.WriteLine(filter.GetDetailedMessage(5));
            message.Text = filter.GetDetailedMessage(1);
        }
    }

New features in the Core SDK

Apart from opening up the extensibility model and adding more triggers and binders, we also added many features to the Core SDK. Many of these were feature requests from the community so we are thrilled to complete these asks in this release.

  • More control over Queue processing: A user can have more control (JobHostQueuesConfiguration.NewBatchThreshold) over the concurrency settings of how many queue messages are de-queued. A user can also plug in their own QueueProcessor to customize how Queue messages are processed.
  • Extensible tracing and logging: In this release we provided extensibility points so you can plug in your own logger.
  • Error monitoring system: This feature allows you to monitor the Host or functions for any errors. You can also raise alerts and send notifications via email or text or plugin any other system such as IFTTT.
  • Multiple storage account support: You can now use multiple storage accounts in your WebJob functions. This allows you to perform scenarios such as reading a blob from one storage account and archiving it to another storage account.
  • Allows function timeouts to be specified: Based on user feedback (“Continuous Web Job frozen and preventing further QueueTriggers”), we added a Timeout attribute which allows functions to declaratively request function cancellation when a timeout expires. You can set this at the JobHost level.
  • Dynamically enable/disable functions: This allows you to disable functions from being triggered and can be controlled by a config switch which could be an app setting or environment name.
  • Added a CloudBlobDirectory binding for blobs.
  • IEnumerable binder for blobs: You can now bind to a collection of blobs (IEnumerable, IEnumerable, CloudBlobContainer, etc.).
  • Control/customize the Azure Storage SDK clients used by the WebJobs SDK: Added JobHostConfiguration.StorageClientFactory to specify/set advanced options on CloudQueueClient/CloudBlobClient/CloudTableClient, etc.

ServiceBus enhancements

As part of opening up the extensibility model, we moved ServiceBus triggers and binders to be based off this new extensibility system. If you are using ServiceBus and you update to this version of the SDK, you will have to register ServiceBus triggers and binders as follows.

Service Bus connection string override is now provided by ServiceBusConfiguration. Please refer to the following sample.

public class Program
{
   public static void Main()
   {
      JobHostConfiguration config = new JobHostConfiguration();
      config.UseServiceBus();
      JobHost host = new JobHost(config);
      host.RunAndBlock();
   }
}

Enhancements include:

  • Allow deep customization of Message processing via ServiceBusConfiguration.MessagingProvider
  • MessagingProvider supports customization of the ServiceBus MessagingFactory and NamespaceManager
  • A new MessageProcessor strategy pattern allows you to specify a processor per queue/topic
  • Support message processing concurrency by default (previously there was no concurrency)
  • Easy customization of OnMessageOptions via ServiceBusConfiguration.MessageOptions
  • Allow AccessRights to be specified on ServiceBusTriggerAttribute/ServiceBusAttribute (for scenarios where you might not have Manage rights)

Dashboard for monitoring

You can continue to use the dashboard to monitor all functions triggered based on various events. You get all the same benefits of the dashboard as before such as: real time monitoring, real time I/O, replay a function, abort a function etc. The following image shows the Functions view of the dashboard for this specific WebJob.

AzureWebJobs

Download this release

You can download the WebJobs SDK from the NuGet gallery and can install these packages from the NuGet gallery using the NuGet Package Manager Console, like this:

If you want to use Microsoft Azure Service Bus, install the following package:

There is a new package which has some new triggers (Timer, File etc.) and binders built on the new extensibility model.

There is a new package where you can send emails using SendGrid service. You can use this to raise email notification for different errors such as function failure and more.

This is a new package which allows the SDK to trigger functions based on WebHook events. This package is currently still in preview.

Open source

The source code for the SDK, extensibility system and related repos are available here:

Please open issues for any feedback and send PR’s for issues you want to fix.

Samples

  • You can find samples on how to use triggers and binders for blobs, tables, queues, timers, files, WebHooks, Service Bus and more. 
  • PhluffyShuffy which is an Image processing website where a customer can upload pictures which will trigger a function to process those pictures from blob storage.
  • PhluffyLogs is an example where a WebJob parses log files generated by the app and archives the log files.

Documentation

Give feedback and get help

If you have questions, please ask them on the Azure forum, the ASP.NET forum, or StackOverflow.com (tag name #Azure-WebJobsSDK).

Summary

This release of the SDK opens up a whole new world of triggers and binders enabling extension authors to write triggers for any event type they choose. Examples include File events, Timer/Cron schedule events, SQL events, Redis pub/sub events, etc. (check out our links to further documentation and samples below). Triggers are no longer bound to Azure events only – you can write a trigger that monitors any event source you choose. It will make developing and managing apps based on triggers a lot easier. We are looking forward to seeing new triggers and binders being written by the community and receiving your feedback around the extensibility model.

Thank You!

Azure WebJobs team
Find us on Twitter for the latest updates and use #AzureWebJobs.

  • Explore

     

    Let us know what you think of Azure and what you would like to see in the future.

     

    Provide feedback

  • Build your cloud computing and Azure skills with free courses by Microsoft Learn.

     

    Explore Azure learning


Join the conversation