소스 검색

[minor] add locking to scheduler

version-14
Pratik Vyas 11 년 전
부모
커밋
f9f01fa727
2개의 변경된 파일45개의 추가작업 그리고 2개의 파일을 삭제
  1. +39
    -0
      webnotes/utils/file_lock.py
  2. +6
    -2
      wnf.py

+ 39
- 0
webnotes/utils/file_lock.py 파일 보기

@@ -0,0 +1,39 @@
import os
from time import time
from webnotes.utils import get_site_path

class LockTimeoutError(Exception):
pass

def create_lock(name):
pre
lock_path = get_lock_path(name)
if not check_lock(lock_path):
return touch_file(lock_path)
else:
return False

def touch_file(path):
with open(path, 'a'):
os.utime(path, None)
return True

def check_lock(path):
if not os.path.exists(path):
return False
if time() - os.path.mtime(path) > 600:
raise LockTimeoutError(path)
return True

def delete_lock(name):
lock_path = get_lock_path(name)
try:
os.remove(path)
except OSError:
pass
return True

def get_lock_path(name):
name = name.lower()
lock_path = get_site_path(name + '.lock')
return lock_path

+ 6
- 2
wnf.py 파일 보기

@@ -454,9 +454,13 @@ def reset_perms(site=None):
# scheduler # scheduler
@cmd @cmd
def run_scheduler(site=None): def run_scheduler(site=None):
from webnotes.utils.file_lock import create_lock, delete_lock
import webnotes.utils.scheduler import webnotes.utils.scheduler
webnotes.connect(site=site)
print webnotes.utils.scheduler.execute()
webnotes.init(site=site)
if create_lock('scheduler'):
webnotes.connect(site=site)
print webnotes.utils.scheduler.execute()
delete_lock('scheduler')
webnotes.destroy() webnotes.destroy()


@cmd @cmd


불러오는 중...
취소
저장