示例#1
0
def request_kill_from_controller(app, dry_run=False):
    sqs_conn = app.config["sqs.conn"]
    active = app.config["instance.tags"]["ActiveQueueName"]
    active_q = sqs_conn.get_queue(active)

    msg = {"job_id": "kill_request", "dry_run": str(dry_run)}

    job_id = "kill_request"
    sns_sqs.post_message_to_active(app, active_q, json.dumps(msg), job_id)
示例#2
0
def request_kill_from_controller(app, dry_run=False):
    sqs_conn = app.config["sqs.conn"]
    active = app.config["instance.tags"]["ActiveQueueName"]
    active_q = sqs_conn.get_queue(active)

    msg = {"job_id": "kill_request", "dry_run": str(dry_run)}

    job_id = "kill_request"
    sns_sqs.post_message_to_active(app, active_q, json.dumps(msg), job_id)
示例#3
0
def task_loop(app):
    sqs_conn = app.config["sqs.conn"]
    pending = app.config["instance.tags"]["JobsQueueName"]
    active = app.config["instance.tags"]["ActiveQueueName"]
    pending_q = sqs_conn.get_queue(pending)
    active_q = sqs_conn.get_queue(active)

    while 1:
        # Wait to read a message from the pending_q
        msg = pending_q.read(wait_time_seconds=20)

        print "Received message from pending_q"
        if msg:
            # Too many things could fail here, do a blanket
            # Try catch
            try:

                sreq = json.loads(msg.get_body())["Message"]
                if not sreq:
                    continue

                app.config["current_msg_handle"] = msg

                data = ast.literal_eval(sreq)
                job_id = data.get('job_id')
                jobtype = data.get('jobtype')
                executable = data.get('executable')
                args = data.get('args')
                inputs = data.get('inputs')
                inputs = data.get('inputs')
                outputs = data.get('outputs')
                user_auth = {
                    "user": data.get('i_user_id'),
                    "role": data.get('i_user_role'),
                    "token": data.get('i_token'),
                    "keyid": data.get('i_keyid'),
                    "keysecret": data.get('i_keysecret')
                }

                # Post the job to the active queue and delete it from the pending queue
                attr, current_msg = sns_sqs.post_message_to_active(
                    app, active_q, msg.get_body(), job_id)
                print "Posted job from pending to active queue"
                if not pending_q.delete_message(msg):
                    print "Deleting message from pending queue failed"

                for key in data:
                    print "{0} : {1}".format(key, data[key])

                print "Starting task"
                status = exec_job(app, jobtype, job_id, executable, args,
                                  inputs, outputs, data, user_auth)

                print "Status : ", status

                if status == True:
                    conf_man.send_success_mail(data, app)
                else:
                    conf_man.send_failure_mail(data, app)

            except Exception as e:
                print "Job failed to complete : {0}".format(sys.exc_info()[0])
                print "Trace : ", inspect.trace()

        else:
            print "{0}: Waiting for job description".format(time.time())
            seppukku.die_at_hour_edge(app, dry_run=True)
            logging.debug("{0}: Waiting for job description".format(
                time.time()))

        conf_man.update_creds_from_metadata_server(app)
示例#4
0
def task_loop(app):
   sqs_conn  = app.config["sqs.conn"]
   pending   = app.config["instance.tags"]["JobsQueueName"]
   active    = app.config["instance.tags"]["ActiveQueueName"]
   pending_q = sqs_conn.get_queue(pending)
   active_q  = sqs_conn.get_queue(active)


   while 1:
      # Wait to read a message from the pending_q
      msg = pending_q.read(wait_time_seconds=20)

      print "Received message from pending_q"
      if msg:         
         # Too many things could fail here, do a blanket
         # Try catch      
         try:

            sreq = json.loads(msg.get_body())["Message"]
            if not sreq :
               continue

            app.config["current_msg_handle"] = msg
            
            data        =  ast.literal_eval(sreq)
            job_id      =  data.get('job_id')
            jobtype     =  data.get('jobtype')
            executable  =  data.get('executable')
            args        =  data.get('args')
            inputs      =  data.get('inputs')
            inputs      =  data.get('inputs')
            outputs     =  data.get('outputs')
            user_auth   =  {"user"      : data.get('i_user_id'),
                            "role"      : data.get('i_user_role'),
                            "token"     : data.get('i_token'),
                            "keyid"     : data.get('i_keyid'),
                            "keysecret" : data.get('i_keysecret')}

            # Post the job to the active queue and delete it from the pending queue
            attr, current_msg = sns_sqs.post_message_to_active(app, active_q, msg.get_body(), job_id)
            print "Posted job from pending to active queue"
            if not pending_q.delete_message(msg):
               print "Deleting message from pending queue failed"
            
            for key in data:
               print "{0} : {1}".format(key, data[key])

            print "Starting task"
            status      =  exec_job(app,
                                    jobtype,
                                    job_id,
                                    executable,
                                    args,
                                    inputs,
                                    outputs,
                                    data,
                                    user_auth)
            
            print "Status : ", status

            if status == True:
               conf_man.send_success_mail(data, app)
            else:
               conf_man.send_failure_mail(data, app)

         except Exception as e:
               print "Job failed to complete : {0}".format(sys.exc_info()[0])
               print "Trace : ", inspect.trace()               

      else:
         print "{0}: Waiting for job description".format(time.time())
         seppukku.die_at_hour_edge(app, dry_run=True)
         logging.debug("{0}: Waiting for job description".format(time.time()))

      conf_man.update_creds_from_metadata_server(app)