Documentation ¶
Overview ¶
Package dynoscaler scales Heroku workers proportionally to RabbitMQ queues.
It utilizes information about queued/unacked messages in a RabbitMQ queue combined with pre-defined message-worker ratios.
ds := dynoscaler.NewDynoScaler( "baboon.rmq.cloudamqp.com", "username", "password", "heroku Platform API key", "heroku app name", dynoscaler.WorkerConfig{ MsgWorkerRatios: map[int]int{1: 1}, QueueName: "foo", WorkerType: "fooworker", }, dynoscaler.WorkerConfig{ MsgWorkerRatios: map[int]int{1: 1, 10: 2, 30: 5}, QueueName: "bar", WorkerType: "mainworker", }, ) ds.Logger.SetLevel(logrus.InfoLevel) err = ds.Monitor() logrus.WithError(err).Error("dynoscaler monitoring failed")
For more details, visit https://github.com/monsterroster/dynoscaler.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DynoScaler ¶
type DynoScaler struct { // How long to sleep between the checks. CheckInterval time.Duration // Where to log errors. Logger *logrus.Logger // contains filtered or unexported fields }
DynoScaler has the ability to scale dynos on Heroku according to some configuration combined with details about the message counts in a RabbitMQ queue.
func NewDynoScaler ¶
func NewDynoScaler( rabbitMQHost, rabbitMQUsername, rabbitMQPassword, herokuAPIKey, herokuAppID string, workerConfigs ...WorkerConfig, ) DynoScaler
NewDynoScaler initializes a new DynoScaler with specified and default values. It will connect to the RabbitMQ Management API with TLS using the provided information to get current details about the queues. It also utilizes the Heroku Platform API to get the current formation for the specified app, and to update the formation (scale) to the desired quantity based on the total number of unacked and queued messages.
func (*DynoScaler) Monitor ¶
func (ds *DynoScaler) Monitor() error
Monitor watches the queue message count and scales the dynos accordingly.
type WorkerConfig ¶
type WorkerConfig struct { // Number of workers to use once the queue reaches a certain // number of messages. For example, if {1: 1, 10: 2, 30: 5} // was used, one worker would be used when the first message // comes in, then if the queue grows to 10 messages, a second // worker would be started up. Finally, if the queue grows to // 30 messages, another 3 workers would be started up. MsgWorkerRatios map[int]int // Name of the AMQP queue to track. QueueName string // Name of the process on Heroku. // This is the same name you use in the Procfile. WorkerType string }
WorkerConfig holds the scaling settings for a specific dyno and queue.