Socket
Socket
Sign inDemoInstall

catline

Package Overview
Dependencies
2
Maintainers
1
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    catline

Simple job queue


Maintainers
1

Readme

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 を用いた保存方法がライブラリに同封されているため、特段理由が無い場合はそちらを使うことを推奨します。

注意点

  1. ジョブを取得する際に優先度順に取得するなどといった処理を自分で作成する必要があります。

FAQs


Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc