HireFire - Job Queue Size (Any Language)
"Job Queue Size is the number of jobs in the queue that are ready to be processed."
If you're not using one of our natively supported programming languages (Ruby, Python, Node.js), this guide will demonstrate how to integrate the Job Queue Size autoscaling strategy into your application. Although we will use Node.js and Express.js for demonstration purposes, the fundamental principles can be universally applied across various programming environments.
HireFire will periodically make an HTTP GET request to a specific endpoint within your application. This request is formatted to follow a particular URL/PATH pattern:
https://your-domain.com/hirefire/<HIREFIRE_TOKEN>/info
HIREFIRE_TOKEN
represents an environment variable that needs to be added to your Heroku environment variables. You can locate this token within the HireFire app when you're setting up or modifying a dyno manager that requires this variable.
To accommodate this in your application, you'll need to establish a new route adhering to the path:
/hirefire/<HIREFIRE_TOKEN>/info
For an application built using Node.js and Express.js, your route definition might look something like this:
const express = require("express") const app = express() const port = process.env.PORT || 3000 const token = process.env.HIREFIRE_TOKEN || "development" app.get(`/hirefire/${token}/info`, (req, res) => { res.json([ { name: "worker", value: yourJobQueueSize() } ]) }) function yourJobQueueSize() { // Implement the logic to measure your job queue's size return 32; // Example job queue size value } app.listen(port, () => { console.log(`Server running on port ${port}`) })
This setup directs the /hirefire/<HIREFIRE_TOKEN>/info
route to a handler function that responds with a JSON payload. This payload should contain your job queue sizes, which HireFire uses to autoscale your worker dynos.
Your JSON response should follow this structure:
[{"name": "worker", "value": 32}]
Here, name
is a string representing the name of the dyno as defined in your Procfile
, and value
is an integer reflecting the number of jobs in the queue being processed by worker
.
Return multiple objects if you have several Procfile
entries that you wish HireFire to autoscale, for instance:
[{"name": "worker", "value": 32}, {"name": "worker_critical", "value": 8}]
Verifying Functionality
With everything in place, initiate your local development server and navigate to:
http://localhost:3000/hirefire/development/info
You should be greeted with a JSON response showcasing the size of your job queues. If all looks good, you're ready to proceed with deployment to your production environment.
After deploying your application, log into HireFire and create and configure two Dyno Managers with the names worker
and worker_critical
, select the HireFire - Job Queue Size
strategy, and configure the autoscaling rules to your liking.
Once done, enable the Dyno Managers to autoscale your worker
and worker_critical
dynos.
If you have any questions or need assistance, don't hesitate to reach out to us at support@hirefire.io.