Skip to content

Commit

Permalink
get pid 명령어 추가.
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenD93 committed Jul 24, 2020
1 parent 4af2b79 commit 837d4de
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 20 deletions.
57 changes: 37 additions & 20 deletions app/tasks/task_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Status(enum.Enum):
WATCHDOG_INTERVAL = 5

# 종료조건시에 각 진행마다 슬립시간
WATCHDOG_SLEEP_ON_STOPPING = 1
WATCHDOG_SLEEP_ON_STOPPING = 0.2

class TaskManager():

Expand Down Expand Up @@ -104,7 +104,7 @@ def pause_services(self):

self.print_status()

log_info('TaskManager.paused')
print('TaskManager.paused')

pass

Expand Down Expand Up @@ -404,15 +404,17 @@ def _do_thread():

time.sleep(WATCHDOG_INTERVAL)

print('>>> WATCHDOG STOPPING TASKS...')
self.tasks_status = Status.STOPPING
if _is_done():

self.print_status()
print('>>> WATCHDOG STOPPING TASKS...')
self.tasks_status = Status.STOPPING

_force_stop()
self.print_status()

print('>>> WATCHDOG STOPPED TASKS.')
self.tasks_status = Status.STOPPED
_force_stop()

print('>>> WATCHDOG STOPPED TASKS.')
self.tasks_status = Status.STOPPED

time.sleep(WATCHDOG_INTERVAL)

Expand Down Expand Up @@ -452,23 +454,26 @@ def _force_stop():

#---------------------------------------
# 태스크 정지
log_info('>> [WATCHDOG] STOPPING TASKS...')
print('>> [WATCHDOG] STOPPING TASKS...')

for task in arr_task:
task.stop()

if len(arr_task) > 0:
time.sleep(WATCHDOG_SLEEP_ON_STOPPING)
log_info('>> [WATCHDOG] STOPPED TASKS')

print('>> [WATCHDOG] STOPPED TASKS')

#---------------------------------------
# 큐 정지
log_info('>> [WATCHDOG] STOPPING QUEUES...')
print('>> [WATCHDOG] STOPPING QUEUES...')
for queue in arr_queue:
queue.stop()

if len(arr_queue) > 0:
time.sleep(WATCHDOG_SLEEP_ON_STOPPING)
log_info('>> [WATCHDOG] STOPPED QUEUES')

print('>> [WATCHDOG] STOPPED QUEUES')

pass

Expand Down Expand Up @@ -581,6 +586,20 @@ def get_status_strings(self):

return result

#----------------------------------------------
# get_stats
def get_stats(self):
stats = []

for name, task in self.tasks.items():
stats.append(task.get_stats())

stats = list(sorted(stats, key=lambda x: x['name']))

self.last_stats = stats

return stats

#----------------------------------------------
# calculate_total_processed_counts
def calculate_total_processed_counts(self):
Expand All @@ -594,15 +613,13 @@ def calculate_total_processed_counts(self):
pass

#----------------------------------------------
# get_stats
def get_stats(self):
stats = []
# get_pids
def get_pids(self):
pids = []

for name, task in self.tasks.items():
stats.append(task.get_stats())

stats = list(sorted(stats, key=lambda x: x['name']))
pids.append(task.pid)

self.last_stats = stats
pids = list(sorted(pids))

return stats
return pids
16 changes: 16 additions & 0 deletions app/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ def req_stop_procs():
TaskManager.get_instance().stop_services()
return "stop"

#----------------------------------------
# get pids
@app.route("/pids")
def req_pids_procs():
pids = TaskManager.get_instance().get_pids()

result = 'pids: {}'.format(os.getpid())

for pid in pids:
result += ' {}'.format(pid)

result += '\n'

return result

#----------------------------------------
# starter
def start_runner():
Expand All @@ -47,6 +62,7 @@ def start_loop():
while not_started:

time.sleep(5)

print('In start loop')

r = requests.get('http://127.0.0.1:{}/load'.format(port_no))
Expand Down

0 comments on commit 837d4de

Please sign in to comment.