-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathServerTask.py
executable file
·64 lines (54 loc) · 1.43 KB
/
ServerTask.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
"""
a generic class for implementing a server task.
this class does not actually do anything. it needs
to be extended and the functions filled in with
something meaningful specific for a task
author: Gevorg Grigoryan, 08/31/2016
"""
import os
import tempfile
import subprocess
from werkzeug.utils import secure_filename
from rq import Queue
from redis import Redis
import re
class ServerTask(object):
"""
main class
uses an rq redis worker to submit a background task
to do something
"""
def __init__(self, app):
"""
sets up redis queue and connection
"""
self.app = app
self.redis_conn = Redis()
self.rq = Queue(connection=self.redis_conn)
self.inputs = ''
self.maxTime = 3600
def process(self):
"""
override this
actually process the request; does all the error checking
and parsing, and prepares all needed information for function
do in self.inputs variable
"""
handle = 1
error = False
return handle, error
def progress(self):
"""
override this
a generator for providing progress updates
"""
yield ''
def enqueue(self, func, inputs):
"""
schedule the job
"""
job = self.rq.enqueue_call(func, args = inputs, timeout = self.maxTime)
return job
if __name__ == "__main__":
pass