mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 12:32:30 +08:00
Feat/monitor task (#11116)
### What problem does this PR solve? Show task executor. ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -12,6 +12,7 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import socket
|
||||
import concurrent
|
||||
# from beartype import BeartypeConf
|
||||
# from beartype.claw import beartype_all # <-- you didn't sign up for this
|
||||
@ -963,6 +964,17 @@ async def handle_task():
|
||||
redis_msg.ack()
|
||||
|
||||
|
||||
async def get_server_ip() -> str:
|
||||
# get ip by udp
|
||||
try:
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
|
||||
s.connect(("8.8.8.8", 80))
|
||||
return s.getsockname()[0]
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
return 'Unknown'
|
||||
|
||||
|
||||
async def report_status():
|
||||
global CONSUMER_NAME, BOOT_AT, PENDING_TASKS, LAG_TASKS, DONE_TASKS, FAILED_TASKS
|
||||
REDIS_CONN.sadd("TASKEXE", CONSUMER_NAME)
|
||||
@ -975,8 +987,12 @@ async def report_status():
|
||||
PENDING_TASKS = int(group_info.get("pending", 0))
|
||||
LAG_TASKS = int(group_info.get("lag", 0))
|
||||
|
||||
pid = os.getpid()
|
||||
ip_address = await get_server_ip()
|
||||
current = copy.deepcopy(CURRENT_TASKS)
|
||||
heartbeat = json.dumps({
|
||||
"ip_address": ip_address,
|
||||
"pid": pid,
|
||||
"name": CONSUMER_NAME,
|
||||
"now": now.astimezone().isoformat(timespec="milliseconds"),
|
||||
"boot_at": BOOT_AT,
|
||||
|
||||
Reference in New Issue
Block a user