-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.py
More file actions
53 lines (45 loc) · 941 Bytes
/
tasks.py
File metadata and controls
53 lines (45 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
# encoding: utf-8
"""
@author: chaochen
@file: tasks.py
@time: 2021/5/15 下午4:02
"""
import os
import time
import socket
from CeleryProject.app import app
def get_host_ip():
"""
查询worker节点的ip
:return: ip
"""
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
ip = s.getsockname()[0]
finally:
s.close()
return ip
@app.task
def add(x, y):
s = x + y
time.sleep(3)
print("主机IP{}:x + y = {}".format(get_host_ip(), s))
return s
@app.task
def taskA():
print("taskA begin...")
print("主机IP{}:taskA".format(get_host_ip()))
time.sleep(3)
print("taskA end.")
@app.task
def taskB():
print("taskB begin...")
print("主机IP{}:taskB".format(get_host_ip()))
time.sleep(3)
print("taskB end.")
if __name__ == "__main__":
print(get_host_ip())
taskA()
pass