Skip to main content

A Python lib to integrate with the HireFire service -- The Heroku Proccess Manager

Project description

This is a Python package for HireFire – The Heroku Process Manager:

HireFire has the ability to automatically scale your web and worker dynos up and down when necessary. When new jobs are queued in to your application’s worker queue [..], HireFire will spin up new worker dynos to process these jobs. When the queue is empty, HireFire will shut down the worker dynos again so you’re not paying for idle workers.

HireFire also has the ability to scale your web dynos. When your web application experiences heavy traffic during certain times of the day, or if you’ve been featured somewhere, chances are your application’s backlog might grow to a point that your web application will run dramatically slow, or even worse, it might result in a timeout. In order to prevent this, HireFire will automatically scale your web dynos up when traffic increases to ensure that your application runs fast at all times. When traffic decreases, HireFire will spin down your web dynos again.

—from the HireFire frontpage

It supports the following Python queuing systems as backends:

Feel free to contribute other backends if you’re using a different queuing system.

Installation

Install the HireFire package with your favorite installer, e.g.:

pip install HireFire

Sign up for HireFire and set the HIREFIRE_TOKEN environment variable with the Heroku CLI as provided on the specific HireFire application page, e.g.:

heroku config:set HIREFIRE_TOKEN=f69f0c0ddebe041248daf187caa6abb3e5d943ca

Now follow the quickstart guide below and don’t forget to tweak the options in the HireFire management system.

For more help see the Hirefire documentation.

Configuration

The hirefire Python package currently supports two frameworks: Django and Tornado. Implementations for other frameworks are planned but haven’t been worked on: Flask, Pyramid (PasteDeploy), WSGI middleware, ..

Feel free to contribute one if you can’t wait.

The following guides imply you have defined at least one hirefire.procs.Proc subclass defined matching one of the processes in your Procfile. For each process you want to monitor you have to have one subclass.

For example here is a Procfile which uses RQ for the “worker” proccess:

web: python manage.py runserver
worker: DJANGO_SETTINGS_MODULE=mysite.settings rqworker high default low

Define a RQProc subclass somewhere in your project, e.g. mysite/procs.py, with the appropriate attributes (name and queues):

from hirefire.procs.rq import RQProc

class WorkerProc(RQProc):
    name = 'worker'
    queues = ['high', 'default', 'low']

See the procs API documentation if you’re using another backend. Now follow the framework specific guidelines below.

Django

Setting up HireFire support for Django is easy:

  1. Add 'hirefire.contrib.django.middleware.HireFireMiddleware' to your MIDDLEWARE_CLASSES setting:

    MIDDLEWARE_CLASSES = [
        'hirefire.contrib.django.middleware.HireFireMiddleware',
        # ...
    ]

    Make sure it’s the first item in the list/tuple.

  2. Set the HIREFIRE_PROCS setting to a list of dotted paths to your procs. For the above example proc:

    HIREFIRE_PROCS = ['mysite.procs.WorkerProc']
  3. Set the HIREFIRE_TOKEN setting to the token that HireFire shows on the specific application page (optional):

    HIREFIRE_TOKEN = 'f69f0c0ddebe041248daf187caa6abb3e5d943ca'

    This is only needed if you haven’t set the HIREFIRE_TOKEN environment variable already (see the installation section how to do that on Heroku).

  4. Check that the middleware has been correctly setup by opening the following URL in a browser:

    http://localhost:8000/hirefire/test

    You should see an empty page with ‘HireFire Middleware Found!’.

    You can also have a look at the page that HireFire checks to get the number of current tasks:

    http://localhost:8000/hirefire/<HIREFIRE_TOKEN>/info

    where <HIREFIRE_TOKEN> needs to be replaced with your token or – in case you haven’t set the token in your settings or environment – just use development.

Tornado

Setting up HireFire support for Tornado is also easy:

  1. Use hirefire.contrib.tornado.handlers.hirefire_handlers when defining your tornado.web.Application instance:

    import os
    from hirefire.contrib.tornado.handlers import hirefire_handlers
    
    application = tornado.web.Application([
        # .. some patterns and handlers
    ] + hirefire_handlers(os.environ['HIREFIRE_TOKEN'],
                          ['mysite.procs.WorkerProc']))

    Make sure to pass a list of dotted paths to the hirefire_handlers function.

  2. Set the HIREFIRE_TOKEN environment variable to the token that HireFire shows on the specific application page (optional):

    export HIREFIRE_TOKEN='f69f0c0ddebe041248daf187caa6abb3e5d943ca'

    See the installation section above for how to do that on Heroku.

  3. Check that the handlers have been correctly setup by opening the following URL in a browser:

    http://localhost:8888/hirefire/test

    You should see an empty page with ‘HireFire Middleware Found!’.

    You can also have a look at the page that HireFire checks to get the number of current tasks:

    http://localhost:8888/hirefire/<HIREFIRE_TOKEN>/info

    where <HIREFIRE_TOKEN> needs to be replaced with your token or – in case you haven’t set the token as an environment variable – just use development.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

HireFire-0.2.1.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

HireFire-0.2.1-py2.py3-none-any.whl (17.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file HireFire-0.2.1.tar.gz.

File metadata

  • Download URL: HireFire-0.2.1.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for HireFire-0.2.1.tar.gz
Algorithm Hash digest
SHA256 c9c4082abd7269430a4f3539fc35f9612ba0245f762b275c2cd9d6d02770a1e6
MD5 c0b2c31bdbcd55a4d0fbc0664decaea9
BLAKE2b-256 65ff589ffb176d6b8a08f7c4dc649bac7813d5d4991f9bdf7acb002b182039c9

See more details on using hashes here.

File details

Details for the file HireFire-0.2.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for HireFire-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2f88479e7152eee6631f5326ac1541e1423d2859ba5cd323ec9ef44f15871c4b
MD5 c05c25ff6441e63e5a65c524f00afde3
BLAKE2b-256 8a99cc61cb95c98367fd87dd5921e0463c32e6030fbe094d3f3665f8c9797a73

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page