def wait_for_job(): job_count = 0 try: job_count = queue.count() log_msg("Current Job Queue length is %s" % job_count) except Exception, e: logging.err("Caught exception: %s" % e)
def process_job(job): log_msg("Picked up job: %s" % job['ID']) log_debug("details:%s" % job.get_body()) template_mappings = {} try: # Pull down the asset and assign template variables asset_name = job["ASSET_URL"].split('/')[-1] filename = "%s/%s" % (tmp_dir, asset_name) basename = "%s/%s" % (tmp_dir, asset_name.split('.')[0]) template_mappings["filename"] = filename template_mappings["basename"] = basename # "wget" asset_url to $filename asset = open(filename, "wb") asset.write( wget.open(job["ASSET_URL"]).read() ) asset.close() # Take ownership for job job.update( { "STATUS": "PROCESSING" } ) log_msg("Picked up asset: %s" % asset_name) except Exception, e: log_err("Caught exception taking job: %s" % e)
log_debug("Matched suffix '%s'" % matched_suffix) else: log_err("Could not match any job configs to files with suffix '%s'" % suffix) except Exception, e: log_err("Caught exception matching execs to suffix" % e) try: # Perform commands on asset exec_list = job_processes[matched_suffix[0]] for command_template in exec_list: log_debug("Command template [ %s ]" % command_template) cmd_pattern = Template(command_template) cmd = cmd_pattern.substitute(template_mappings) log_msg("Running command [%s]" % cmd) os.system(cmd) # If successful, delete job queue.delete_message(job) except Exception, e: log_err("Caught exception processing job: %s" % e) def wait_for_job(): job_count = 0 try: job_count = queue.count() log_msg("Current Job Queue length is %s" % job_count) except Exception, e: