IronWorker Webhooks

Using IronWorker webhooks enables you to run pretty much anything you want whenever an event happens at a third party service that supports webhooks.

Table of Contents

How to Use IronWorker Webhooks

A Webhook is simply an HTTP POST API endpoint so you don't need any updates in your existing workers to use them. A typical workflow for a webhook is:

$ iron_worker webhook $WORKER_NAME
  • Pass webhook link to 3rdparty service like GitHub, or as subscriber URL for IronMQ Push Queue
  • Do something to trigger the webhook, say, commit to GitHub or post a message to a Push Queue.

When the IronWorker service receives the HTTP POST request to your webhook endpoint, it will pass the request's body to a worker as a file, specified by -payload option.

The URL's scheme for webhooks is:

$ WORKER_API_URL/projects/$PROJECT_ID/tasks/webhook?code_name=$CODE_NAME&oauth=$TOKEN

Where:

  • $WORKER_API_URL is https://worker-aws-us-east-1.iron.io/2
  • $PROJECT_ID and $TOKEN are credentials to access to your project
  • $CODE_NAME is name of your worker

Example

The best way to see how this works is via an example. The rest of this section will use a Github to Hipchat webhook where Github will hit the webhook and the worker will post to Hipchat. The full code is here.

Step 1: Create a worker and upload it to IronWorker

This is the same as you would create and upload a worker normally, the difference is in how the task is queued up.

First let's create the worker:

Now let's upload it:

Step 2: Add your workers webhook URL to Github service hooks

Github service hooks are where you can add webhooks for Github events. In your Github project, click Admin, Service Hooks, then Post-Receive URLs.

Admin button

Post-receive

In the text field, add the webhook url for your worker, it should look something like this:

https://worker-aws-us-east-1.iron.io/2/projects/{Project ID}/tasks/webhook?code_name={Code Name}&oauth={Token}

The upload script above will print the exact URL to your console so you can just copy and paste it.

Step 3: Commit and push some code to your github project and watch the magic happen!

That's it! It will post your github commit information to the Hipchat room you specified in the config file.