跳转到主要内容

最小化Redis作业运行器

项目描述

minique /miniːk/

适用于Python 3.7及以上的最小化Redis 4.0+作业队列。

要求

  • Python 3.7+
  • Redis 4.0+

用法

  • 确保您的Redis 4.0+服务器正在运行。

客户端

from redis import StrictRedis
from minique.api import enqueue, get_job

# Get a Redis connection, somehow.
redis = StrictRedis.from_url('redis://localhost:6379/4')

job = enqueue(
    redis=redis,
    queue_name='work',
    callable='my_jobs.calcumacalate',  # Dotted path to your callable.
    kwargs={'a': 5, 'b': 5},  # Only kwargs supported.
    # You can also set a `job_id` yourself (but it must be unique)
)

job_id = job.id  # Save the job ID somewhere, maybe?

while not job.has_finished:
    pass  # Twiddle thumbs...

print(job.result)  # Okay!

# Get the same job later (though not later than 7 days (by default)):
job = get_job(redis, job_id)

工作进程

  • 确保您的作业进程能够导入您希望运行的函数。
  • 使用--allow-callable设置作业进程允许的调用函数。
    • 或者,您可能希望继承minique.work.job_runner.JobRunner以指定不同的查找机制。
$ minique -u redis://localhost:6379/4 -q work -q anotherqueue -q thirdqueue --allow-callable 'my_jobs.*'

Sentry支持

Minique自动集成了Sentry异常跟踪服务。

您可以使用[sentry] 安装额外功能来安装Minique和sentry-sdk,或者您可以手动安装。

只需设置SENTRY_DSN环境变量;如果一切顺利,您应该在CLI启动时看到一条“已配置有效的DSN的Sentry”消息。

其他环境配置选项也按预期工作。

作业执行期间发生的异常将被发送到Sentry,并使用描述作业ID和队列名称的minique上下文进行注释。

开发

# install `minique` in editable mode with development dependencies
pip install -e .[sentry,test] pre-commit mypy==1.0.0 types-redis && pre-commit install

# run lints
pre-commit run --all-files

# run type checks
mypy --strict --install-types --show-error-codes minique

# run tests against the specified Redis database
REDIS_URL=redis://localhost:6379/0 pytest .

发布

# decide on a new version number and set it
vim minique/__init__.py
__version__ = "0.9.0"

npx auto-changelog --commit-limit=0 -v 0.9.0

# undo changes changelog generation did to the older entries

git add -u
git commit -m "Become 0.9.0"
git tag -m "v0.9.0" -a v0.9.0

git push --follow-tags

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码发行版

minique-0.9.1.tar.gz (12.1 kB 查看散列值)

上传时间 源代码

构建发行版

minique-0.9.1-py3-none-any.whl (17.5 kB 查看散列值)

上传时间 Python 3

支持