CatLine
このプロジェクトは簡易的な非同期 ジョブキューを実装するための物です。
注意事項
threadingを用いた並列処理はサポート・テストしていませんQueueクラスは イベントループ作成後にインスタンス化してください。- 優先度は 0 ~ 9 であり、 0に近づくほど優先度が高くなります。
使い方
以下が例になります。 このコードの意味をまとめると以下のようになります
- ジョブが実行された際に引数で渡されたジョブの名前で
meowと出力する - 優先度が0のcatには
VIPを先頭につけ、それ以外のcatはnormalをつける - 待機中のジョブが0になった際にループを終了し、キューを停止させる
import asyncio
import random
from catline.adapters.json_adapter import QueueStorageJSONAdapter
from catline.queue import Queue
async def say_meow(cat_name: str):
print(f'{cat_name}: meow' + '!' * random.randrange(1,10))
async def main():
cat_queue = Queue('cat', QueueStorageJSONAdapter(), say_meow)
cat_queue.run()
for i in range(random.randrange(1, 20)):
priority = random.randrange(0, 9)
await cat_queue.add(priority, f'{"VIP" if priority == 0 else "normal"} cat{i}') # type: ignore
while True:
waiting_cat_number = await cat_queue.count_jobs('waiting')
print(f'waiting cat number: {waiting_cat_number}')
await asyncio.sleep(1)
if waiting_cat_number == 0:
break
cat_queue.stop()
print('finish!!!')
if __name__ == '__main__':
asyncio.run(main())
実装予定の機能
| 機能 | 説明 | 状態 |
|---|---|---|
| ジョブの追加 | ジョブをキューに追加できる | 〇 |
| ジョブの実行 | キューにあるジョブをスケジューラーで実行できる | 〇 |
| ジョブのリトライ | ジョブが失敗した際に再実行できる | × |
| ジョブの優先度 | ジョブを追加する際優先度を指定できる | 〇 |
| スケジューラーの実行間隔 | スケジューラーがジョブを実行するまでの間隔を変更できる | 〇 |
| キューストレージの変更 | キューをredisやjsonに保存する際自分でadapterを作れる | 〇 |
| threadingのサポート | 並列処理のサポート | × |
| 実行するジョブの上限変更 | 同時に実行できるジョブの数を変更できる | 〇 |
ストレージを自分で作成する方法
このプロジェクトではキューのジョブを保存するためのクラスをアダプターパターンで作成しているため、それに沿ってクラスを作成すれば作成が可能です。
また、デフォルトで json 又は redis を用いた保存方法がライブラリに同封されているため、特段理由が無い場合はそちらを使うことを推奨します。
注意点
- ジョブを取得する際に優先度順に取得するなどといった処理を自分で作成する必要があります。
Metadata
Release files for catline 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| catline-0.0.3.tar.gz | 27.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| catline-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.2 kB
Release files / catline-0.0.3.tar.gz
| Download URL | catline-0.0.3.tar.gz |
|---|---|
| Size | 27.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0616a73b46708e42ab92040bb7ab94afe019afddaa0413e1395ec2c77ce94edb
|
|
BLAKE2b-256 checksum How to use checksums |
abe64bae6b0716959c7c1a790e6c39335bfd276c8c4164bc1dd232f9c0cc21be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.17
|
Release files / catline-0.0.3-py3-none-any.whl
| Download URL | catline-0.0.3-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
df98f49c7a65a5989df3d226ec4696ad9ae96a65b7501be3cbddd5170a9d56e8
|
|
BLAKE2b-256 checksum How to use checksums |
ffb9dbb9a28b184be214bfcce2c808fa655f99bf2e2ae6bf2e9653b5b28a641c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.17
|
Security for catline 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.