IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16957


Ignore:
Timestamp:
Mar 12, 2008, 11:20:53 AM (18 years ago)
Author:
bills
Message:

added mode to list a request. Used by the web interface to check request
status

Location:
trunk/ippTools/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/pstamptool.c

    r16931 r16957  
    3535static bool moddatastoreMode(pxConfig *config);
    3636static bool addReqMode(pxConfig *config);
     37static bool listReqMode(pxConfig *config);
    3738static bool pendingReqMode(pxConfig *config);
    3839static bool processedReqMode(pxConfig *config);
     
    6566        MODECASE(PSTAMPTOOL_MODE_MODDATASTORE, moddatastoreMode);
    6667        MODECASE(PSTAMPTOOL_MODE_ADDREQ, addReqMode);
     68        MODECASE(PSTAMPTOOL_MODE_LISTREQ, listReqMode);
    6769        MODECASE(PSTAMPTOOL_MODE_PENDINGREQ, pendingReqMode);
    6870        MODECASE(PSTAMPTOOL_MODE_PROCESSEDREQ, processedReqMode);
     
    254256}
    255257
     258#define  MAGIC_STR  "$REQ_ID"
     259
     260// Replace $REQ_ID with the value of the request id if present in the outFileset
     261
     262static bool
     263updateFilesetID(pxConfig *config, psS64 req_id, psString outFileset)
     264{
     265    char *magic;
     266
     267    magic = strcasestr(outFileset, MAGIC_STR);
     268    if (magic == NULL) {
     269        return true;
     270    }
     271
     272    // find part of the string after the magic
     273    char *after = magic + strlen(MAGIC_STR);
     274
     275    if (*after == 0) {
     276        after = NULL;
     277    }
     278
     279    psString converted = NULL;
     280    if (magic > outFileset) {
     281        int len = magic - outFileset;
     282        converted = psStringAlloc(len + 1);
     283        strncpy(converted, outFileset, len);
     284        converted[len] = 0;
     285    }
     286
     287    psStringAppend(&converted, "%" PRId64, req_id);
     288    if (after) {
     289        psStringAppend(&converted, after);
     290    }
     291
     292    if (!p_psDBRunQuery(config->dbh, "UPDATE pstampRequest set outFileset = '%s' WHERE req_id = %" PRId64,
     293            converted, req_id)) {
     294        psError(PS_ERR_UNKNOWN, false, "database error");
     295        return false;
     296    }
     297
     298    return true;
     299}
     300
    256301static bool addReqMode(pxConfig *config)
    257302{
     
    307352
    308353    psS64 req_id = psDBLastInsertID(config->dbh);
     354    if (!updateFilesetID(config, req_id, outFileset)) {
     355        psError(PS_ERR_UNKNOWN, false, "failed to update fileset id\n");
     356        return false;
     357    }
     358
    309359    printf("%" PRId64 "\n", req_id);
    310360
     
    334384        psStringAppend(&query, " AND %s", whereClause);
    335385        psFree(whereClause);
     386    }
     387
     388    // treat limit == 0 as "no limit"
     389    if (limit) {
     390        psString limitString = psDBGenerateLimitSQL(limit);
     391        psStringAppend(&query, " %s", limitString);
     392        psFree(limitString);
     393    }
     394
     395    if (!p_psDBRunQuery(config->dbh, query)) {
     396        psError(PS_ERR_UNKNOWN, false, "database error");
     397        psFree(query);
     398        return false;
     399    }
     400    psFree(query);
     401
     402    psArray *output = p_psDBFetchResult(config->dbh);
     403    if (!output) {
     404        psError(PS_ERR_UNKNOWN, false, "database error");
     405        return false;
     406    }
     407    if (!psArrayLength(output)) {
     408        psTrace("pstamptool", PS_LOG_INFO, "no rows found");
     409        psFree(output);
     410        return true;
     411    }
     412
     413    bool simple = false;
     414    {
     415        bool status = false;
     416        simple = psMetadataLookupBool(&status, config->args, "-simple");
     417        if (!status) {
     418            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
     419            psFree(output);
     420            return false;
     421        }
     422    }
     423
     424    // negative simple so the default is true
     425    if (!ippdbPrintMetadatas(stdout, output, "pstampRequest", !simple)) {
     426        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     427        psFree(output);
     428        return false;
     429    }
     430
     431    psFree(output);
     432
     433    return true;
     434}
     435static bool listReqMode(pxConfig *config)
     436{
     437    PS_ASSERT_PTR_NON_NULL(config, false);
     438
     439    bool status = false;
     440    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
     441    if (!status) {
     442        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
     443        return false;
     444    }
     445
     446    psString query = NULL;
     447
     448    psString req_id = psMetadataLookupStr(&status, config->args, "-req_id");
     449   
     450    if (req_id) {
     451        psStringAppend(&query,
     452                "SELECT"
     453                " *"
     454                " FROM pstampRequest"
     455                " WHERE req_id = %s", req_id
     456            );
     457    } else {
     458        fprintf(stderr, "req_id must be specified\n");
     459        exit (1);
    336460    }
    337461
  • trunk/ippTools/src/pstamptool.h

    r16471 r16957  
    2929    PSTAMPTOOL_MODE_MODDATASTORE,
    3030    PSTAMPTOOL_MODE_ADDREQ,
     31    PSTAMPTOOL_MODE_LISTREQ,
    3132    PSTAMPTOOL_MODE_PENDINGREQ,
    3233    PSTAMPTOOL_MODE_PROCESSEDREQ,
  • trunk/ippTools/src/pstamptoolConfig.c

    r16931 r16957  
    8989            "limit result set to N items", 0);
    9090    psMetadataAddBool(pendingreqArgs, PS_LIST_TAIL, "-simple", 0,
     91            "use the simple output format", false);
     92
     93    // -listreq
     94    psMetadata *listreqArgs = psMetadataAlloc();
     95    psMetadataAddStr(listreqArgs, PS_LIST_TAIL, "-req_id", 0,
     96            "define req_id", NULL);
     97    psMetadataAddU64(listreqArgs, PS_LIST_TAIL, "-limit",  0,
     98            "limit result set to N items", 0);
     99    psMetadataAddBool(listreqArgs, PS_LIST_TAIL, "-simple", 0,
    91100            "use the simple output format", false);
    92101
     
    165174    PXOPT_ADD_MODE("-pendingreq",      "", PSTAMPTOOL_MODE_PENDINGREQ,   pendingreqArgs);
    166175    PXOPT_ADD_MODE("-processedreq",    "", PSTAMPTOOL_MODE_PROCESSEDREQ, processedreqArgs);
     176    PXOPT_ADD_MODE("-listreq",         "", PSTAMPTOOL_MODE_LISTREQ,      listreqArgs);
    167177
    168178    PXOPT_ADD_MODE("-addjob",          "", PSTAMPTOOL_MODE_ADDJOB,       addjobArgs);
Note: See TracChangeset for help on using the changeset viewer.