File tree Expand file tree Collapse file tree 2 files changed +30
-5
lines changed
packages/try/try-faststream/src/try_faststream Expand file tree Collapse file tree 2 files changed +30
-5
lines changed Original file line number Diff line number Diff line change 15
15
16
16
@group .task (trigger = Every (seconds = 5 ))
17
17
async def every ():
18
- msg = f"cron task : at { time .time ()} "
19
- logger .debug (f"Every 5 seconds, Publish msg to Nats, msg: { msg } " )
18
+ msg = f"cron one : at { int ( time .time () )} "
19
+ logger .debug (f"cron one: pub msg: { msg } " )
20
20
21
21
await broker .publish (
22
22
msg ,
23
23
subject = "test-cron" ,
24
24
)
25
25
26
26
27
+ @group .task (trigger = Every (seconds = 5 ))
28
+ async def every ():
29
+ msg = f"cron batch: at { int (time .time ())} "
30
+ logger .debug (f"cron batch, pub msg: { msg } " )
31
+
32
+ await broker .publish (
33
+ msg ,
34
+ subject = "test-cron2" ,
35
+ )
36
+
37
+
27
38
@group .task (trigger = Every (weeks = 50 ))
28
39
def even_sync_works ():
29
40
logger .debug (f"synchronous task" )
Original file line number Diff line number Diff line change
1
+ import os
2
+
1
3
import anyio
2
4
from faststream import FastStream
3
5
from faststream .nats import NatsBroker , PullSub
6
8
7
9
host = "nats://localhost:4222"
8
10
11
+ # logger file, 进程 id
12
+
13
+
14
+ logger .add (f"tmp/nats_pub_{ os .getpid ()} .log" , rotation = "10 MB" , retention = "10 days" )
15
+
9
16
broker = NatsBroker (host )
10
17
11
18
app = FastStream (broker )
@@ -20,13 +27,20 @@ async def to_batch(body: str, msg: NatsMessage):
20
27
logger .debug (f"subscriber batch: msg: { msg } " )
21
28
22
29
23
- @broker .subscriber ("test-cron" )
30
+ @broker .subscriber ("test-cron" , "cron" )
24
31
async def to_cron (body : str , msg : NatsMessage ):
25
32
"""
26
33
TODO X: 定时任务
27
34
"""
28
- logger .debug (f"subscriber batch: { body } " )
29
- logger .debug (f"subscriber batch: msg id: { msg .message_id } " )
35
+ logger .debug (f"subscriber cron one: { body } , { msg .message_id } " )
36
+
37
+
38
+ @broker .subscriber ("test-cron2" )
39
+ async def to_cron (body : str , msg : NatsMessage ):
40
+ """
41
+ TODO X: 定时任务
42
+ """
43
+ logger .debug (f"subscriber cron batch: { body } , { msg .message_id } " )
30
44
31
45
32
46
@broker .subscriber ("test-workers" , "workers" )
You can’t perform that action at this time.
0 commit comments