if args.debug:
    logger.setLevel(logging.DEBUG)
else:
    logger.setLevel(logging.INFO)

# for each file get the obsnum, then reset the status to first item in config files workflow_actions

obsnums = []

# for filename in glob.glob(args.files):

for filename in args.files:
    logger.debug("looking for file {filename}".format(filename=filename))

    try:
        s = dbi.Session()
        FILE = s.query(File).filter(File.filename == filename).one(
        )  # XXX note assumes we are not noting that this file is copied.

        obsnum = FILE.obsnum
        logger.debug("found obsnum {obsnum}".format(obsnum=obsnum))
        s.close()
        logger.debug("setting status to {status}".format(status=args.status))
        dbi.set_obs_status(obsnum, args.status)
        dbi.set_obs_pid(obsnum, None)
        dbi.set_obs_still_host(obsnum, None)
        dbi.add_log(obsnum, args.status, "issuing a reset_observations", 0)
    except Exception as e:
        print("failed on file %s: %s") % (filename, e)
        continue
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger('reset_observations.py')

if args.debug:
    logger.setLevel(logging.DEBUG)
else:
    logger.setLevel(logging.INFO)


# for each file get the obsnum, then reset the status to first item in config files workflow_actions

obsnum=0
# for filename in glob.glob(args.files):

for jd in args.jds:
    #update observation set observation.status = 'UV_POT' where observation.date like '2456663%';
    try:
        s = dbi.Session()
        OBSES = s.query(Observation).filter(Observation.date.like('{jd}%'.format(jd=jd)))  # XXX note assumes we are not noting that this file is copied.
        obsnumbs = [obs.obsnum for obs in OBSES]
        s.close()
        for obsnum in obsnumbs:
            dbi.set_obs_status(obsnum,args.status)
            dbi.set_obs_pid(obsnum, None)
            dbi.set_obs_still_host(obsnum, None)
            dbi.add_log(obsnum, args.status, "issuing a reset_observations", 0)
            dbi.update_obs_current_stage(obsnum,None)
    except Exception as e:
        print("failed on jd/obsnum %s/%s: %s") % (jd,obsnum, e)
        continue
Exemple #3
0
s = dbi.Session()

for name in args.names:
    try:
        # In current usage, the "obsnum" is the file basename.
        obsnum = os.path.basename(name)

        obs = s.query(Observation).filter(
            Observation.obsnum == obsnum).one_or_none()
        if obs is None:
            print("failed on filename \"%s\": nothing with that obsnum" % name)
            continue

        if obs.current_stage_in_progress not in ('FAILED', 'KILLED'):
            print("skipping \"%s\": current_stage is \"%s\", not FAILED or KILLED" % (name,
                                                                                      obs.current_stage_in_progress))
            continue

        print("issuing a %s for \"%s\"" % (desc, name))
        if args.reset:
            dbi.set_obs_status(obsnum, reset_status)
            dbi.set_obs_still_host(obsnum, None)
        dbi.update_obs_current_stage(obsnum, None)
        dbi.set_obs_pid(obsnum, None)
        dbi.add_log(obsnum, desc.upper(),
                    "doing a %s at user request" % desc, 0)
    except Exception as e:
        print("failed on filename \"%s\": %s" % (name, e), file=sys.stderr)

s.close()