Developer Docs
Executify's vision is to make cloud code easier and more affordable to develop and execute. Traditionally if you want to execute code in the cloud as a background task, you are left with very few affordable options and you have to pay a monthly fee even if you only use the code a few times a month.
This is why we at Executify have developed cloud code on-demand, where you only pay for the execution time you use each month. No more, no less, and no complicated pricing plans.
What is Cloud Code?
Our mission is to free developers from reinventing the wheel when all they really want to accomplish is a simple coding task in the cloud. We at Executify feel this pain, because we are also developers and we have run into the same problems you have run into when trying to deploy our code jobs to the cloud.
- Creating our own scheduling algorithm
- Trying to justify the costs of a cloud worker role to our bosses
- Constantly making sure the scheduled job has been run and the output has been saved
That is why we invented our Executify Cloud Code service which makes it easy to build and deploy your own on-demand cloud code that you can execute through a REST call or via a scheduled cron job. Our Cloud Code is easy to use because it is built on the same .NET Framework that powers millions of apps worldwide. The only difference is that instead of running it on your own servers, it runs in Executify's cloud. That lets you rest assured that no matter the circumstances your code will run when you want and how you want.
Where is the Cloud Code run?
The Executify platform is built on top of the Azure cloud. As you develop and deploy your Executify Cloud Code Jobs you can rest assured that you get the scalability and performance that you have come to expect from the Azure cloud.
As an added benefit of being on the Azure platform you are able to access your Azure services without needing to do any customization or create special firewall rules. This is especially useful if you need to do clean up or run custom commands in your database on a scheduled basis.
But lets be clear, this doesn't rule out you using Executify with Amazon's AWS Cloud, it is just much easier configuration wise if Azure is your preferred platform.
Getting Started
To get started in developing your code for Executify you need to have the following on your development machine:
- .NET Framework version 4.5 - download
- Visual Studio or another editor for developing .NET code - download
- Executify runtime - download or nuget
Creating Your First Job
When creating your cloud code job, you first need to create a .NET 4.5 library. In our example below we are going to be using Visual Studio 2012.
Creating The Library
Creating a cloud code job library is just like creating any other library in .NET. Here is the step by step guide in case this is your first time.
- Start Visual Studio
- Select File > New > Project
- Select Class Library
- For the purpose of this example I am naming the project MyFirstJob
- Fill out the rest of the fields the way you want and click OK.
- Delete Class1.cs file.
- In the NuGet package manager console run
install-package Executify(for help using NuGet please this link) - Right click on the project and go to Add > Class.
- Give it a name, for this example it will be MyJob.cs, and click OK
Coding The Job
For this cloud code job, we are going to be creating code that will pull the latest tweet from Twitter and send a Pushover notification to my iPhone.
public class MyJob : Executify.Runtime.JobEntryPoint
{
public MyJob() { }
public override void Run()
{
var userName = Args.userName ?? "nberardi";
// get tweets for userName
var twitterEndPoint = "http://search.twitter.com/search.json?q={0}";
var url = String.Format(twitterEndPoint, userName);
var response = Http.Get(url);
// convert string to dynamic JSON object
dynamic obj = Json.ToObject(response);
dynamic tweets = obj.results;
if (tweets.Count == 0) {
Console.WriteLine("No tweets found.");
return;
}
// get latest tweet
var tweet = tweets[0];
var text = String.Format("{0} said {1}", tweet.from_user_name, tweet.text);
Console.WriteLine(text);
var pushoverToken = "3QiBQcv4HMQrYLViX1domk3jYKOofT";
var pushoverUser = "iPFY5guT178FE7oO1mPSVnyuAodW6a";
// send push notification
Services.Pushover(pushoverToken, pushoverUser, text);
}
}
Note: We provide some great job examples to get you started on our GitHub repository.
The above code uses 4 built in helper properties. Http, Json, Args, and Services. These 4 build in helper properties are designed to get common tasks done quicker in your code than if you had to write them yourself. Here is a short description of each one.
Httpcontains methods to help you make calls over HTTP.Jsoncontains methods to help you serialize and deserialize JSON strings to objects and back to strings again if nessisary.Argsis a dynamic object smart object that contains parameters from the query string if executed through a GET REST call, or from the body if executed through a POST REST call.Servicescontains methods to help communication with non-Executify services.
Also not listed but available helper properties are:
Queryis a dynamic object that just contains query strings that might have been passed in via a REST call.Headersis a dynamic object that just contains headers that might have been passed in via a REST call.Bodyis a dynamic object that just contains values that might have been passed in through the body via a REST call.
Setup New Job
After you are done coding your job, the next step is to compile it and upload it to Executify. To do this you need to create a new job. You can do this by:
- Clicking the Jobs tab on executify.com
- Clicking the Create New Job button which will take you here.
- Give you job a name, in my case for this example it will be My First Job.
- Select a time limit, this is used to protect your credits in case the job runs longer than expected.
- We are going to set this up so it runs daily at 5:00 PM in other words we are going to enter this cron schedule
0 12 * * * - To finalize creating the job, we now just need to select our cloud code job that we compiled and click the *Save Changes button.
- And with that we are done we have successfully created our first cloud code job.
Executing A Job
After you have successfully created your first job, you can either choose to wait for the job to run based on the schedule you have chosen or you can or you can execute the job via a REST call. Since waiting around for the schedule to execute is no fun, we are going to execute the job via a REST call using cURL.
The first thing we need to do to execute our cloud code job via REST is to get our job key. You can find the job key doing the following:
- Clicking the Jobs tab on executify.com
- Clicking the View button next to the job you want to find the key for.
- On this page you will find the job key other wise known as the API Key
Since we now know our job key we can now execute the job via a REST call. So lets execute a basic call with no parameters
curl -v -X GET
http://executify.com/api/jobs/87008e89571b4a03a3612ef35a21d8c2/execute
When the creation is successful, the HTTP response is a 201 Created and the Location header contains the URL for where the job run response can be retrieved:
Status: 201 Created
Location: http://executify.com/api/jobs/87008e89571b4a03a3612ef35a21d8c2/runs/1
Now if you go back to your Jobs tab and click the job you just ran you should be able to see the run results right on the page.
