Monitoring Flights and Sending SMS with Taskmatics Scheduler and Enzo Unified

Software developers need to build solutions quickly so that businesses remain competitive and agile. This blog post shows you how Taskmatics Scheduler and Enzo Unified can help developers build and deploy solutions very quickly by removing two significant pain points: the learning curve of new APIs, and orchestrating Internet services.

Sample Solution

Let’s build a solution that checks incoming flights in Miami, Florida and send a text message using SMS when new flights arrive to one or more phone numbers. To track flight arrivals, we will be using the FlightAware service which provides a REST API to retrieve flight information. To send SMS messages, we will be using Twilio’s service which provides an API as well for sending messages.

To remove the learning from these APIs, we used Enzo Unified, a Backend as a Service (BaaS) platform that enables the consumption of services through native SQL statements. Enzo Unified abstracts communication and simplifies development of a large number of internal systems and Internet services. In this example, Enzo Unified is hosted on the Microsoft Azure platform for scalability and operational efficiency.

To orchestrate and schedule the solution, we used the Taskmatics Scheduler platform. Taskmatics calls into your custom code written in .NET on a schedule that you specify, which is configured to connect to Enzo Unified in the cloud. The call to Enzo Unified is made using ADO.NET by sending native SQL statements to pull information from FlightAware, and send an SMS message through Twilio. At a high level, the solution looks like this:

High Level call sequence between Taskmatics Scheduler and Enzo Unified

High Level call sequence between Taskmatics Scheduler and Enzo Unified

How To Call FlightAware and Twilio with Enzo Unified

Developers can call Enzo Unified using a REST interface, or a native SQL interface. In this example, the developer uses the SQL interface, leveraging ADO.NET. The following code connects to Enzo Unified as a database endpoint using the SqlConnection class, and sends a command to fetch flights from a specific airport code using an SqlCommand object. Fetching FlightAware data is as simple as calling the “Arrived” stored procedure against the “flightaware” database schema.

var results = new List<ArrivedFlightInfo>();

// Connect to Enzo Unified using SqlConnection
using (var connection = new SqlConnection(parameters.EnzoConnectionString))
  // Prepare call to FlightAware's Arrived procedure 
  using (var command = new SqlCommand("flightaware.arrived", connection))
  {
    connection.Open();
    command.CommandType = System.Data.CommandType.StoredProcedure;
    command.Parameters.Add(new SqlParameter("airport", airportCode));
    command.Parameters.Add(new SqlParameter("count", 10));
    command.Parameters.Add(new SqlParameter("type", "airline"));

    // Call FlightAware's Arrived procedure 
    using (var reader = command.ExecuteReader())
      while (reader.Read())
        results.Add(new ArrivedFlightInfo
        {
          Ident = (String)reader["ident"],
          AircraftType = (String)reader["aircrafttype"],
          OriginICAO = (String)reader["origin"],
          OriginName = (String)reader["originName"],
          DestinationName = (String)reader["destinationName"],
          DestinationCity = (String)reader["destinationCity"]
          // ... additional code removed for clarity...
        });
    }

Calling Twilio is just as easy. A simple ADO.NET call to the SendSMS stored procedure in the “Twilio” schema is all that’s needed (the code is simplified to show the relevant part of the call).

// Establish a connection Enzo Unified
using (var connection = new SqlConnection(parameters.EnzoConnectionString))
  using (var command = new SqlCommand("twilio.sendsms", connection))
  {
    connection.Open();
    command.CommandType = System.Data.CommandType.StoredProcedure;
    command.Parameters.Add(new SqlParameter("phones", phoneNumbers));
    command.Parameters.Add(new SqlParameter("message", smsMessage));

    // Call Twilio’s SendSMS method
    command.ExecuteReader();
  }

If you inspect the above code carefully, you will notice that it does not reference the APIs of FlightAware or Twilio. Indeed, calling both FlightAware and Twilio was done using ADO.NET calls against Enzo Unified; because Enzo Unified behaves like a native database server (without the need to install special ODBC drivers), authenticating, making the actual API calls, and interpreting the REST results was entirely abstracted away from the developer, and replaced by an SQL interface, which dramatically increases developer productivity. Database developers can call Enzo Unified directly to test FlightAware and Twilio using SQL Server Management Studio (SSMS). The following picture shows the results of calling Enzo Unified from SSMS to retrieve arrived flights from FlightAware.

Calling the FlightAware service using simple SQL syntax in SQL Server Management Studio

Calling the FlightAware service using simple SQL syntax in SQL Server Management Studio

Sending a SMS text message using Twilio is just as simple using SSMS:

Calling the Twilio service using simple SQL syntax in SQL Server Management Studio

Calling the Twilio service using simple SQL syntax in SQL Server Management Studio

How To Schedule The Call With Taskmatics Scheduler

In order to run and schedule this code, we are using Taskmatics Scheduler, which provides an enterprise grade scheduling and monitoring platform. When a class written in .NET inherits from the Taskmatics.Scheduler.Core.TaskBase class, it becomes automatically available as a custom task inside the Taskmatics Scheduler user interface. This means that a .NET library can easily be scheduled without writing additional code. Furthermore, marking the custom class with the InputParameters attribute provides a simple way to specify input parameters (such as the airport code to monitor, and the phone numbers to call) for your task through the Taskmatics user interface.
The following simplified code shows how a custom task class is created so that it can be hosted inside the Taskmatics Scheduler platform. Calling Context.Logger.Log gives developers the ability to log information directly to Taskmatics Scheduler for troubleshooting purposes.

namespace Taskmatics.EnzoUnified.FlightTracker
{
    // Mark this class so it is visible in the Taskmatics interface
    [InputParameters(typeof(FlightNotificationParameters))]
    public class FlightNotificationTask : TaskBase
    {
        // Override the Execute method called by Taskmatics on a schedule
        protected override void Execute()
        {
	     // Retrieve parameters as specified inside Taskmatics
            var parameters = (FlightNotificationParameters)Context.Parameters;

            // Invoke method that calls FlightAware through Enzo Unified
            var arrivedFlights = GetArrivedFlights(parameters);

            // do more work here… such as identify new arrivals
            var newFlights = FlightCache.FilterNewArrivals(arrivedFlights);

            // Do we have new arrivals since last call?
            if (newFlights.Count > 0)
            {
               // Invoke method that calls Twilio through Enzo Unified
               var results = SendArrivedFlightsViaSMS(newFlights, parameters);

		  // Update cache so these flights won’t be sent through SMS again
		  FlightCache.SaveFlightsToCache(newFlights); 
            }
            else
                Context.Logger.Log("SMS phase skipped due to no new arrivals.");

            Context.Logger.Log("Job execution complete.");
        }
    }
}

Installing the task into the Taskmatics Scheduler platform is very straightforward. Log into the user interface and create a definition for the flight tracker task. This step allows you to import your library into the system to serve as a template for the new scheduled task that we will create next.

Import your custom task as a definition

Import your custom task as a definition

Schedule your custom task to run on the days and times you specify.

Schedule your custom task to run on the days and times you specify.

Once you have created your definition, go to the “Scheduled Tasks” section of the user interface, and create the task by selecting the definition that you just created from the Task dropdown. This is also where you will schedule the time and frequency that the task will run as well as configure the input parameters for the task.

Configure the parameters for the scheduled task.

Configure the parameters for the scheduled task.

Finally, from the Dashboard screen, you can run your task manually and watch the output live, or look at a past execution of the task to see the outcome and logs from that run. In the image below, you can see the execution of the Flight Tracking task where we monitored recent arrivals into the Miami International Airport (KMIA).

Review and analyze previous task executions or watch your tasks live as they run.

Review and analyze previous task executions or watch your tasks live as they run.

Conclusion

This blog post shows how developers can easily build integrated solutions without having to learn complex APIs using simple SQL statements, thanks to Enzo Unified’s BaaS platform. In addition, developers can easily orchestrate and schedule their libraries using the Taskmatics Scheduler platform. Combining the strengths of Enzo Unified and Taskmatics, organizations can reap the following benefits:

  • Rapid application development by removing the learning curve associated with APIs
  • Reduced testing and simple deployment by leveraging already tested services
  • Service orchestration spanning Internet services and on-premises systems
  • Enterprise grade scheduling and monitoring

About Blue Syntax Consulting

Our mission is to make your business successful through the technologies we build, create innovative solutions that are relevant to the technical community, and help your company adopt cloud computing where it makes sense. We are now making APIs irrelevant with Enzo® Unified. For more information about Enzo Unified and how developers can access services easily using SQL statements or a simple REST interface, visit http://www.enzounified.com or contact Blue Syntax Consulting at info@bluesyntaxconsulting.com.

About Taskmatics

Taskmatics was founded by a group of developers looking to improve the productivity of their peers. Their flagship application, Taskmatics Scheduler, aims to boost developer productivity and reduce the effort involved in creating consistent and scalable tasks while providing a centralized user interface to manage all aspects of your task automation. For more information and a free 90-day trial, visit us or email us at info@taskmatics.com.

Taskmatics Scheduler and Windows Azure Scheduler: Redux

There has been a lot of coverage lately about the Windows Azure Scheduler offering currently in preview. After getting familiar with the product, I thought it might be a good idea to talk about what it brings to the table and how it differs from Taskmatics Scheduler, which is currently in beta. We’ll also talk a little bit about how you can use the two platforms together to get robust automation for your environment.

What is Windows Azure Scheduler?

Windows Azure Scheduler is a service that exposes a REST API that allows you to schedule jobs that will be run either in a web or worker role hosted within Azure or on a remote server outside the cloud. These jobs could be run once or recurring in nature, and the API provides you with ways to group these jobs into a job collection, which is a logical grouping of jobs that share settings such as the region from which the job should be triggered. Currently, Windows Azure Scheduler offers two distinct ways of executing jobs scheduled:

  • The simplest way to execute jobs is by providing an HTTP or HTTPS endpoint address which the service will call at the scheduled time(s). This could be any HTTP endpoint that will execute the job when it receives a request from the scheduler. While simple, this method is more suited to small jobs with a duration of 30 seconds or less. The scheduler currently records the responses of the HTTP/HTTPS calls as whether or not the job succeeds, and the default timeout for the call is 30 seconds, which means that longer jobs will record a failure if this method is used.
  • The second method for job execution is for the scheduled job to post a message to an Azure Storage Queue. This will require you to set up and configure Azure Storage Queues on your account but it provides a way to trigger job execution by watching a queue from your own process. How the message is processed is determined completely by whatever application is listening to the queue, and the success or failure of the scheduled job is simply whether the queue receives the posted message successfully.

The Windows Azure Scheduler API also has methods to track and recall job status for all jobs and get success/failure history for one or more jobs as well, though again note that the success or failure not of the job execution itself, but simply the posting of the message to the endpoint or queue. Being that the service is currently in preview, I’m sure that even more functionality will be added over time. There are a few shortcomings of the new scheduler offering:

  • While jobs scheduled are run in the cloud and are therefore reliable, the endpoints or queue subscribers are not necessarily cloud based and the reliability and scale of these applications which will actually perform the work is still a burden placed on the developer. Running web/worker roles to host endpoints that can process messages can get costly since they’ll need to be listening (and thus active) 24/7.
  • Reporting and statistics for the jobs is currently very basic and doesn’t provide a way to extend the collected information such that it can be reported on.
  • Job execution cannot be controlled once the job has started running. Jobs cannot be paused/terminated.

What is Taskmatics Scheduler?

Taskmatics Scheduler is a task scheduling platform that combines a fully extensible .NET API for creating and executing jobs with an administration site that can manage and provide reporting on the jobs created with the API. Where Windows Azure Scheduler focuses on ways to trigger job execution, Taskmatics Scheduler covers the triggering of jobs, but also manages the distribution and execution of those jobs and provides health monitoring and detailed reporting during execution and beyond. Taskmatics Scheduler has the edge on Azure Scheduler when your automation needs extend beyond just a few small nightly tasks because it can handle distribution of the job load internally, without relying on the developer to ensure load balancing and availability of resources to run the desired job. The true power of Taskmatics Scheduler, however, is the extensibility it provides for developers. There are basically three main components to the job scheduling API:

  • Triggers define how job execution will be started. Like Windows Azure Scheduler, a calendar based trigger is provided out of the box, but you can create custom triggers that can fire based on domain specific criteria.
  • Tasks are the central unit of work in the system. They represent the work to be automated, and are executed by one or more triggers. Tasks can be paired with custom configuration to allow reusability and contain built in controls that allows users to pause or terminate running tasks.
  • Event Listeners define code that will execute when one or more target events are raised by a task during execution. Custom event listeners can be created that can be used for real time error notifications or integration with line of business applications such as Enterprise ERP and CRM systems.

Taskmatics Scheduler also provides a web based administration console where customized tasks can be loaded, scheduled and managed. The console also provides detailed reports and execution history for all tasks. If your job automation landscape is fairly complex or involves many long running tasks, Taskmatics Scheduler might be a better fit than using the Windows Azure Scheduler service.

The Best of Both Worlds

On one hand you have a cloud based scheduler that can reliably fire off messages, and on the other you have a fully customizable system that is designed to distribute and execute jobs. Can they be used together? The short answer is yes. If you want to benefit from scheduling jobs in the cloud environment, you can create a custom trigger for Taskmatics Scheduler that will listen on a given HTTP address and port as a receiver for the cloud based scheduler. Another option is a custom trigger that subscribes to the Azure Storage Queue that gets messages posted to it that can fire off one or more tasks within Taskmatics Scheduler. If you are drawn to the potential of Windows Azure Scheduler as a reliable, cloud based scheduling tool, I encourage you to put Taskmatics Scheduler to the test for that same reliability and much more.