与hirefire服务集成的python库——heroku进程管理器

HireFire的Python项目详细描述


这是一个python包,用于HireFire–流程管理器Heroku

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

它支持以下python队列系统作为后端:

如果您使用不同的 排队系统。

安装

用您最喜欢的安装程序安装Hirefire软件包,例如:

pip install HireFire

注册HireFire并设置HIREFIRE_TOKEN环境变量 使用特定hirefireapplication page上提供的Heroku CLI, 例如:

heroku config:set HIREFIRE_TOKEN=f69f0c0ddebe041248daf187caa6abb3e5d943ca

现在按照下面的快速入门指南,不要忘记调整 HireFire management system中的选项。

有关更多帮助,请参见hirefiredocumentation

配置

hirefirepython包目前支持两个框架: Django和Tornado。其他框架的实现是有计划的,但是 尚未处理过:FlaskPyramid(pastedeploy),WSGI中间件,…

如果你不能等待,请随时contribute one

以下指南暗示您至少定义了一个 hirefire.procs.Proc定义的子类匹配 程序文件。对于要监视的每个进程,必须有一个子类。

例如,这里有一个Procfile,它使用RQ作为“worker”进程:

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

在项目的某个地方定义一个RQProc子类,例如。 mysite/procs.py,具有适当的属性(namequeues

fromhirefire.procs.rqimportRQProcclassWorkerProc(RQProc):name='worker'queues=['high','default','low']

如果您正在使用另一个后端,请参阅procs api文档。现在跟随 以下框架具体准则。

django

为django设置hirefire支持很简单:

  1. 'hirefire.contrib.django.middleware.HireFireMiddleware'添加到 MIDDLEWARE设置

    # Use ``MIDDLEWARE_CLASSES`` prior to Django 1.10MIDDLEWARE=['hirefire.contrib.django.middleware.HireFireMiddleware',# ...]

    确保它是列表/元组中的第一项。

  2. HIREFIRE_PROCS设置设置为指向 程序。对于上面的示例proc

    HIREFIRE_PROCS=['mysite.procs.WorkerProc']
  3. HIREFIRE_TOKEN设置设置为hirefire的令牌 显示在特定的application page(可选)

    HIREFIRE_TOKEN='f69f0c0ddebe041248daf187caa6abb3e5d943ca'

    只有在未设置^{tt1}时才需要此命令$ 环境变量已存在(请参阅安装部分如何 在Heroku上这样做)。

  4. 通过打开 浏览器中的以下URL:

    http://localhost:8000/hirefire/test
    

    您应该会看到一个空页面,其中包含“找到hirefire中间件!”’。

    您还可以查看HireFire检查以获取 当前任务数:

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

    其中<HIREFIRE_TOKEN>需要替换为您的令牌或 –如果您没有在设置或环境中设置令牌 –只需使用development

龙卷风

为Tornado设置Hirefire支持也很简单:

  1. 定义时使用hirefire.contrib.tornado.handlers.hirefire_handlers。 您的tornado.web.Application实例

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

    确保将点路径列表传递给hirefire_handlers 功能。

  2. HIREFIRE_TOKEN环境变量设置为hirefire的标记 显示在特定的application page(可选)

    exportHIREFIRE_TOKEN='f69f0c0ddebe041248daf187caa6abb3e5d943ca'

    有关如何在heroku上执行此操作,请参见上面的安装部分。

  3. 通过打开 浏览器中的以下URL:

    http://localhost:8888/hirefire/test
    

    您应该会看到一个空页面,其中包含“找到hirefire中间件!”’。

    您还可以查看HireFire检查以获取 当前任务数:

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

    其中<HIREFIRE_TOKEN>需要替换为您的令牌或 –如果您没有将令牌设置为环境变量 –只需使用development

烧瓶

为烧瓶设置Hirefire支架是(再次!)也很简单:

  1. 模块hirefire.contrib.flask.blueprint提供 build_hirefire_blueprintfactory函数,应使用 hirefire标记和过程作为参数。结果是一个蓝图提供 Hirefire路由和应该在您的应用程序中注册的路由

    importosfromflaskimportFlaskfromhirefire.contrib.flask.blueprintimportbuild_hirefire_blueprintapp=Flask(__name__)bp=build_hirefire_blueprint(os.environ['HIREFIRE_TOKEN'],['mysite.procs.WorkerProc'])app.register_blueprint(bp)

    确保传递dott列表指向^{tt23}的ed路径$ 功能。

  2. HIREFIRE_TOKEN环境变量设置为hirefire的标记 显示在特定的application page(可选)

    exportHIREFIRE_TOKEN='f69f0c0ddebe041248daf187caa6abb3e5d943ca'

    有关如何在heroku上执行此操作,请参见上面的安装部分。

  3. 通过打开 浏览器中的以下URL:

    http://localhost:8080/hirefire/test
    

    您应该会看到一个空页面,其中包含“找到hirefire中间件!”’。

    您还可以查看HireFire检查以获取 当前任务数:

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

    其中<HIREFIRE_TOKEN>需要替换为您的令牌或 –如果您没有将令牌设置为环境变量 –只需使用development

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
多线程如何在读取文本文件时使用Java进度条?   ChromeDriver出现“java.lang.module.InvalidModuleDescriptorException:提供程序类org.apache.bsf.BSFManager不在模块中”错误   java如何将Google日历链接到应用程序?   java线程信令序列   java StackOverflowerr不知道出了什么问题   从azure mobile apps easy tables获取表格时,java Android应用程序冻结   java Android应用程序无法连接到firebase数据库   java如何将属性文件中的值注入字段?   无法创建java Spring引导CXF XMLOutputFactory   javaui:月份选择器   获取java数组中n个最大值的索引   java注入servlet调度器中的EntityManagerFactory(非托管)   我在Android Studio中编写java代码,需要从特定网页获取并显示特定行的数据   java如何在Hibernate中设置内部查询的限制?   java如何编写接受一个数组和两个整数的交换方法   基于递归的java快速供电方法