-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.py
36 lines (28 loc) · 1.14 KB
/
worker.py
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
from __future__ import print_function
from random import randint
from pyres import ResQ
from executor import Executor
import yaml, os, time, config
RESQUE_CONFIG = yaml.load(file('configs/resque.yml','r'))
class SubmissionChecker(object):
queue = "submissions"
@staticmethod
def perform(submission):
result = {"id": submission["id"]}
working_folder = os.path.join(config.PLAYGROUND_PATH, str(os.getpid())) + '/'
if submission.has_key('destination_queue'):
result['start_time'] = time.time()
try:
executor = Executor(submission["lang"].upper(), submission["task"],
submission["source"], working_folder)
(result["result"], result["fail_cause"]) = executor.execute()
except ImportError as error:
result["result"] = "failed"
result["fail_cause"] = "We are sorry, but this language is not available."
if submission.has_key('destination_queue'):
queue = submission['destination_queue']
result['finish_time'] = time.time()
else:
queue = RESQUE_CONFIG['queue_resque']
worker = RESQUE_CONFIG['worker_resque']
ResQ().push(queue, {'class': worker, 'args': [result]})