Statistics
| Branch: | Revision:

root / bin / send_job.py @ b6f6ece7

History | View | Annotate | Download (4.57 KB)

1
# -*- coding: utf-8 -*-
2

    
3
"""
4
Create new job
5
Copyright (C) 2011 Andreas Schroeder
6

7
This file is part of DrQueue.
8

9
Licensed under GNU General Public License version 3. See LICENSE for details.
10
"""
11

    
12
from optparse import OptionParser
13
import os
14
import DrQueue
15
from DrQueue import Job as DrQueueJob
16
from DrQueue import Client as DrQueueClient
17
import getpass
18

    
19

    
20
def main():
21
    # parse arguments
22
    parser = OptionParser()
23
    parser.usage = "%prog [options] -n name -r renderer -f scenefile"
24
    parser.add_option("-s", "--startframe",
25
                      dest="startframe", default=1, help="first frame")
26
    parser.add_option("-e", "--endframe",
27
                      dest="endframe", default=1, help="last frame")
28
    parser.add_option("-b", "--blocksize",
29
                      dest="blocksize", default=1, help="size of block")
30
    parser.add_option("-n", "--name",
31
                      dest="name", default=None, help="name of job")
32
    parser.add_option("-r", "--renderer",
33
                      dest="renderer", help="render type (maya|blender|mentalray)")
34
    parser.add_option("-f", "--scenefile",
35
                      dest="scenefile", default=None, help="path to scenefile")
36
    parser.add_option("-p", "--pool",
37
                      dest="pool", default=None, help="pool of computers")
38
    parser.add_option("-o", "--options",
39
                      dest="options", default="{}", help="specific options for renderer as Python dict")
40
    parser.add_option("--retries",
41
                      dest="retries", default=1, help="number of retries for every task")
42
    parser.add_option("--owner",
43
                      dest="owner", default=getpass.getuser(), help="Owner of job. Default is current username.")
44
    parser.add_option("--os",
45
                      dest="os", default=None, help="Operating system.")
46
    parser.add_option("--minram",
47
                      dest="minram", default=0, help="Minimal RAM in GB.")
48
    parser.add_option("--mincores",
49
                      dest="mincores", default=0, help="Minimal CPU cores.")
50
    parser.add_option("--send-email",
51
                      action="store_true", dest="send_email", default=False, help="Send notification email when job is finished.")
52
    parser.add_option("--email-recipients",
53
                      dest="email_recipients", default=None, help="Recipients for notification email.")
54
    parser.add_option("-w", "--wait",
55
                      action="store_true", dest="wait", default=False, help="wait for job to finish")
56
    parser.add_option("-v", "--verbose",
57
                      action="store_true", dest="verbose", default=False, help="verbose output")
58
    (options, args) = parser.parse_args()
59

    
60
    # initialize DrQueue client
61
    client = DrQueueClient()
62

    
63
    # set limits
64
    limits = dict()
65
    limits['pool_name'] = options.pool
66
    limits['os'] = options.os
67
    limits['minram'] = int(options.minram)
68
    limits['mincores'] = int(options.mincores)
69

    
70
    options_var = eval(options.options)
71
    options_var['send_email'] = options.send_email
72
    options_var['email_recipients'] = options.email_recipients
73

    
74
    # add standard Blender option
75
    if (options.renderer == "blender") and ("rendertype" not in options_var):
76
        options_var['rendertype'] = "animation"
77

    
78
    # initialize DrQueue job
79
    job = DrQueueJob(options.name, int(options.startframe), int(options.endframe), int(options.blocksize), options.renderer, options.scenefile, options.retries, options.owner, options_var, "send_job.py", limits)
80

    
81
    # run job with client
82
    try:
83
        client.job_run(job)
84
    except ValueError:
85
        print("One of your the specified values produced an error:")
86
        raise
87
        exit(1)
88

    
89
    # tasks which have been created
90
    tasks = client.query_task_list(job['_id'])
91

    
92
    # wait for all tasks of job to finish
93
    if options.wait:
94
        if (tasks == []) and (client.query_computer_list() == []):
95
            print("Tasks have been sent but no render node is running at the moment.")
96
            exit(0)
97

    
98
        for task in tasks:
99
            ar = client.task_wait(task['msg_id'])
100
            # add some verbose output
101
            if options.verbose:
102
                cpl = ar.metadata.completed
103
                msg_id = ar.metadata.msg_id
104
                status = ar.status
105
                engine_id = ar.metadata.engine_id
106
                print("Task %s finished with status '%s' on engine %i at %i-%02i-%02i %02i:%02i:%02i." % (msg_id, status, engine_id, cpl.year, cpl.month, cpl.day, cpl.hour, cpl.minute, cpl.second))
107
                if ar.pyerr != None:
108
                    print(ar.pyerr)
109
        print("Job %s finished." % job['name'])
110

    
111
if __name__ == "__main__":
112
    main()
113

    
114