mirror of
https://github.com/QingdaoU/JudgeServer.git
synced 2025-01-16 17:49:59 +00:00
remove TaskCounter
This commit is contained in:
parent
a7973090ff
commit
e2b0f4b4a0
@ -21,5 +21,4 @@ TEST_CASE_DIR = "/test_case"
|
||||
SPJ_SRC_DIR = "/spj"
|
||||
SPJ_EXE_DIR = "/spj"
|
||||
|
||||
COUNTER_FILE_PATH = "/tmp/counter"
|
||||
TOKEN_FILE_PATH = "/token.txt"
|
||||
|
@ -1,7 +1,6 @@
|
||||
# coding=utf-8
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
@ -10,10 +9,10 @@ import uuid
|
||||
import web
|
||||
|
||||
from compiler import Compiler
|
||||
from config import JUDGER_WORKSPACE_BASE, SPJ_SRC_DIR, SPJ_EXE_DIR, COUNTER_FILE_PATH
|
||||
from config import JUDGER_WORKSPACE_BASE, SPJ_SRC_DIR, SPJ_EXE_DIR
|
||||
from exception import TokenVerificationFailed, CompileError, SPJCompileError,JudgeClientError
|
||||
from judge_client import JudgeClient
|
||||
from utils import server_info, logger, TaskCounter, token
|
||||
from utils import server_info, logger, token
|
||||
|
||||
|
||||
DEBUG = os.environ.get("judger_debug") == "1"
|
||||
@ -30,11 +29,9 @@ class InitSubmissionEnv(object):
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
raise JudgeClientError("failed to create runtime dir")
|
||||
TaskCounter().update(+1)
|
||||
return self.path
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
TaskCounter().update(-1)
|
||||
if not DEBUG:
|
||||
try:
|
||||
shutil.rmtree(self.path)
|
||||
|
@ -4,11 +4,9 @@ import _judger
|
||||
import psutil
|
||||
import socket
|
||||
import logging
|
||||
import fcntl
|
||||
import hashlib
|
||||
import os
|
||||
|
||||
from config import COUNTER_FILE_PATH, TOKEN_FILE_PATH
|
||||
from config import TOKEN_FILE_PATH
|
||||
from exception import JudgeClientError
|
||||
|
||||
|
||||
@ -20,41 +18,13 @@ logger.addHandler(handler)
|
||||
logger.setLevel(logging.WARNING)
|
||||
|
||||
|
||||
class TaskCounter(object):
|
||||
def __init__(self, file_path=COUNTER_FILE_PATH):
|
||||
self.f = open(file_path, "r+")
|
||||
self.fd = self.f.fileno()
|
||||
|
||||
def update(self, action):
|
||||
# lock file
|
||||
fcntl.lockf(self.fd, fcntl.LOCK_EX)
|
||||
try:
|
||||
value = self.f.read()
|
||||
self.f.seek(0)
|
||||
self.f.write(str(int(value) + action))
|
||||
finally:
|
||||
# release lock
|
||||
fcntl.lockf(self.fd, fcntl.LOCK_UN)
|
||||
|
||||
def get(self):
|
||||
# lock file
|
||||
fcntl.lockf(self.fd, fcntl.LOCK_EX)
|
||||
try:
|
||||
value = self.f.read()
|
||||
return int(value)
|
||||
finally:
|
||||
# release lock
|
||||
fcntl.lockf(self.fd, fcntl.LOCK_UN)
|
||||
|
||||
|
||||
def server_info():
|
||||
ver = _judger.VERSION
|
||||
return {"hostname": socket.gethostname(),
|
||||
"cpu": psutil.cpu_percent(),
|
||||
"cpu_core": psutil.cpu_count(),
|
||||
"memory": psutil.virtual_memory().percent,
|
||||
"judger_version": ".".join([str((ver >> 16) & 0xff), str((ver >> 8) & 0xff), str(ver & 0xff)]),
|
||||
"running_task_number": TaskCounter().get()}
|
||||
"judger_version": ".".join([str((ver >> 16) & 0xff), str((ver >> 8) & 0xff), str(ver & 0xff)])}
|
||||
|
||||
|
||||
def get_token():
|
||||
|
Loading…
x
Reference in New Issue
Block a user