简单的脱机任务队列。

alligator的Python项目详细描述


https://travis-ci.org/toastdriven/alligator.png?branch=master

简单的脱机任务队列。对于python。

“再见,鳄鱼。”

最新文档位于http://alligator.readthedocs.org/en/latest/

要求

  • python 2.6+或python 3.3+
  • (可选)redis后端的redis
  • (可选)豆茎后端的beanstalkc
  • (可选)豆茎后端的PyYAML
  • (可选)sqs后端的boto>=2.35.0

为什么?!!1个!

  • 因为我得了NIH综合症。
  • 或者因为我渴望一些简单的东西(~375 loc)。
  • 或者因为我想要一些测试(90%以上的覆盖率)和文档。
  • 或者因为我想要可插拔的后端。
  • 或者因为测试其他排队系统是一件痛苦的事。
  • 或者因为我是个白痴。

基本用法

这个例子使用了django,但是没有关于鳄鱼的django特定的内容。

我重复一遍,您可以将它与anypython代码一起使用 后台处理。

fromalligatorimportGatorfromdjango.contrib.auth.modelsimportUserfromdjango.shortcutsimportsend_email# Make a Gator instance.# Under most circumstances, you would configure this in one place &# import that instance instead.gator=Gator('redis://localhost:6379/0')# The task itself.# Nothing special, just a plain *undecorated* function.deffollow_email(followee_username,follower_username):followee=User.objects.get(username=followee_username)follower=User.objects.get(username=follower_username)subject='You got followed!'message='Hey {}, you just got followed by {}! Whoohoo!'.format(followee.username,follower.username)send_email(subject,message,'server@example.com',[followee.email])# An simple, previously expensive view.@login_requireddeffollow(request,username):# You'd import the task function above.ifrequest.method=='POST':# Schedule the task.# Use args & kwargs as normal.gator.task(follow_email,request.user.username,username)returnredirect('...')

运行任务

与其尝试自动发现、扇出等,不如控制 工人的配置及其消耗的资源。

如果您的需求很简单,请运行包含的latergator.pyworker:

$ python latergator.py redis://localhost:6379/0

如果您有更复杂的需求,可以创建一个新的可执行文件 (bin脚本、管理命令等)输入以下代码。

fromalligatorimportGator,Worker# Bonus points if you import that one pre-configured ``Gator`` instead.gator=Gator('redis://localhost:6379/0')# Consume & handle all tasks.worker=Worker(gator)worker.run_forever()

许可证

新的BSD

未来愿望列表

这些东西还没有出现,但也许有一天会出现。

# Delayed tasks (run in an hour).withgator.options(run_after=60*60)astask:task(this_can_wait)# Dependent tasks, will only run if the listed tasks succeed.# Maybe.withgator.options(depends_on=[feeds_job])astask:task(rebuild_cache)

运行测试

Alligator有95%以上的测试覆盖率,并希望始终通过/稳定。

如果要运行测试,请克隆repo,然后运行:

$ virtualenv env2
$ . env2/bin/activate
$ pip install -r requirements.txt
$ python setup.py develop
$ py.test -s -v --cov=alligator --cov-report=html tests

待办事项

  • 计划任务
  • 从属任务

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

推荐PyPI第三方库


热门话题
java在ArrayList中比较数字   java在Kotlin中使异步调用同步   让“Scala编程”junit示例在IntelliJ中工作的java问题   java Servlet侦听器未在ContextListener中设置属性   将Microsoft SQL Server数据库连接到我的Java项目   加载资源时出现java“需要注册工厂”异常   java如何使用POI检查excel中的重复记录?   java如何更改机器生成的代码   java如何确保重写的方法是同步的   用Spring编写Hibernate时的java XML奥秘   java管理mysql数据库中存储的用户权限   java如何运行。来自Javascript的jar方法   java我想在Web应用程序中进行身份验证&对桌面应用程序使用相同的凭据。我该怎么做?