Make integrations with other services more resilient using a Queue

One downside of automating things is dealing with outages. Sometimes services go down, and are not available for some period of time. When this happens, how does it impact your automation?

If you don't design your automation carefully, you might lose the data entirely. Or get spammed by hundreds of submissions when it comes back up. Handling this correctly does end up needing some understanding of how the automation works, as well as any quirks of the remote system.

One great tool in the Drupal arsenal is the Queue API, and the Events, Conditions, and Actions module makes it super easy to ueue into your model. I tend to reach for a queue anytime I'm doing an integration with an external service.

For one client, we made a custom action plugin to post data to a Salesforce case. We wired it all together using ECA. There was already a webform in use for collecting the information. The client wanted certain destinations to go to SalesForce, and others to go to different email addresses.

Using ECA allowed us to use a queue to get around any connectivity issues with SalesForce. Once the data was collected, we sent it to an action to "Enqueue a task." And then used an event "ECA processing queued task" to do the actual SalesForce post.

Our custom plugin throws a "requeue" exception if it can't reach Salesforce, and then the job just goes back on the queue to be tried again later.

In this advent calender, on the 17th, the server for our Mastodon account stopped accepting image uploads. We added a queue to the model we built for Day 15 - Automatically post to Mastodon and retriggered it. For Mastodon's API, we had to explicitly look at the web response to determine whether it was successful, and if it was not, then we had to re-add it to the queue.

When the API started working again, our post for the 17th automatically published!

Advent 2024 -- 24 days of Automations

Door number 7
7
Door number 10
10
Door number 14
14
Door number 19
19
Door number 6
6
Door number 17
17
Door number 1
1
Door number 4
4
Door number 16
16
Door number 22
22
Door number 3
3
Door number 21
21
Door number 5
5
Door number 2
2
Door number 11
11
Door number 9
9
Door number 15
15
Door number 12
12
Door number 8
8
Door number 13
13
Door number 18
18
Door number 20
20
Door number 23
23
Door number 24
24

Add new comment

The content of this field is kept private and will not be shown publicly.

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <blockquote cite> <cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h1> <h2 id> <h3 id> <h4 id> <h5 id> <p> <br> <img src alt height width>
  • Lines and paragraphs break automatically.