bugfix
This commit is contained in:
parent
98991877a1
commit
6b2736b03b
42
README.md
42
README.md
@ -1,2 +1,44 @@
|
||||
# longtasks
|
||||
|
||||
## Usage
|
||||
|
||||
Use with ahserver, you need to save a instance of LongTasks or its child class to ServerEnv, in child class, implements the process_task method for your business
|
||||
|
||||
save LongTasks instace to ServerEnv:
|
||||
```
|
||||
from ahserver.serverenv import ServerEnv
|
||||
from longtasks.longtasks import Longtasks
|
||||
from appPublic.worker import schedule_once
|
||||
|
||||
class MyTasks(LongTasks):
|
||||
# Child class
|
||||
async def process_task(self, payload):
|
||||
# use logic to execute task
|
||||
pass
|
||||
|
||||
def load_longtasks()
|
||||
longtasks = MyTasks('redis://127.0.0.1:6379', 'example')
|
||||
env = ServerEnv()
|
||||
env.longtasks = longtasks
|
||||
# run the backend job
|
||||
schedule_once(0.1, longtasks.run)
|
||||
|
||||
```
|
||||
|
||||
submit a task in dspy
|
||||
```
|
||||
payload = {
|
||||
'prompt':'gagagag'
|
||||
}
|
||||
x = await longtasks.submit_task(payload)
|
||||
# x is a dict with has a 'task_id' key
|
||||
return x
|
||||
```
|
||||
|
||||
query task status
|
||||
```
|
||||
taskid = 'mytaskid'
|
||||
task_status = await longtasks.get_status(taskid)
|
||||
return task_status
|
||||
```
|
||||
|
||||
|
||||
14
longtasks/init.py
Normal file
14
longtasks/init.py
Normal file
@ -0,0 +1,14 @@
|
||||
from ahserver.serverenv import ServerEnv
|
||||
from longtasks.longtasks import Longtasks
|
||||
from appPublic.worker import schedule_once
|
||||
|
||||
class MyTasks(LongTasks):
|
||||
async def process_task(self, payload):
|
||||
....
|
||||
|
||||
def load_longtasks()
|
||||
longtasks = MyTasks('redis://127.0.0.1:6379', 'example')
|
||||
env = ServerEnv()
|
||||
env.longtasks = longtasks
|
||||
schedule_once(0.1, longtasks.run)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user