forked from jamesyonan/brenda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
brenda-node
executable file
·94 lines (82 loc) · 4.27 KB
/
brenda-node
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python -u
# Brenda -- Render farm tool for Amazon Web Services
# Copyright (C) 2013 James Yonan <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys, optparse
from brenda import config, daemon, node, version, utils
def main():
usage = """\
usage: %s [options]
Version:
Brenda %s
Synopsis:
Remote instance worker that executes render tasks
from the work queue, and saves the render output in an S3 bucket.
Required config vars:
WORK_QUEUE : name of SQS queue (e.g. sqs://QUEUE) containing render work.
OUTPUT_URL : save render output to this S3 URL (e.g. s3://BUCKET or s3://BUCKET/PREFIX)
Optional config vars:
S3_REGION : S3 region name, defaults to US standard.
SQS_REGION : SQS region name, defaults to US standard.
VISIBILITY_TIMEOUT : SQS visibility timeout in seconds (default=120).
SQS will return a task to the queue if the instance
doesn't acknowledge or complete the pending task over
this period of time.
VISIBILITY_TIMEOUT_REASSERT : frequency in seconds, while working on task,
that render farm will reassert with SQS that
task is still pending (default=30). This value
must be less than VISIBILITY_TIMEOUT.
ERROR_RETRIES : number of retries on general errors before fail (default=5).
ERROR_PAUSE : number of seconds to pause after general error (default=30).
ERROR_RESET : time in seconds before retry counter is reset (default=3600).
WORK_DIR : local work directory used by the instance, defaults to AMI_USER home
RUNNING_ON_EC2 : boolean (0|1, default=1) that indicates if we are running on an EC2 instance.
DONE : what to do when render job is complete, choices are:
'shutdown' -- terminate the instance
'poll' -- continue to poll the work queue for new tasks
'exit' -- exit but leave the instance running (default)""" % (sys.argv[0], version.VERSION)
parser = optparse.OptionParser(usage)
parser.add_option("-c", "--config", dest="config",
help="Configuration file (by default read from stdin)")
parser.add_option("-D", "--daemon", action="store_true", dest="daemon",
help="Run as a daemon")
parser.add_option("-l", "--logfile", dest="logfile", metavar="FILE",
help="Save log to file")
parser.add_option("-v", "--loglevel", dest="loglevel",
help="Level of events to log (default: INFO)")
parser.add_option("-L", "--logdaemon", dest="logdaemon", metavar="FILE",
help="Save daemon log to file")
parser.add_option("-p", "--pidfile", dest="pidfile", default="brenda.pid", metavar="FILE",
help="Write process ID to this file when running as a daemon, default=%default")
parser.add_option("-S", "--shutdown", action="store_true", dest="shutdown",
help="Shut down the instance on completion of all tasks")
parser.add_option("-d", "--dry-run", action="store_true", dest="dry_run",
help="Initialize instance but don't run any tasks")
# Get command line arguments...
( opts, args ) = parser.parse_args()
#print "OPTS", (opts, args)
# Get configuration
conf = config.Config(opts.config, 'BRENDA_', default_stdin=True)
#print "CONFIG", conf
utils.setup_logger(opts, conf)
# dispatch
func = lambda : node.run_tasks(opts, args, conf)
if opts.daemon:
logdaemon = utils.get_opt(opts.logdaemon, conf, 'LOG_DAEMON', '/dev/null')
i = daemon.Instance(func, logdaemon, opts.pidfile)
i.start()
else:
func()
main()