IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 7, 2009, 1:05:22 PM (17 years ago)
Author:
bills
Message:

Add new table pstampDependent. An entry gets created by the postage stamp request parser
when the source run has been cleaned. The pstampJob is blocked from running until
the system detects that the run has been updated and magicked. (This code is yet
to be developed.)

File:
1 edited

Legend:

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

    r25711 r25793  
    4848static bool projectMode(pxConfig *config);
    4949static bool modprojectMode(pxConfig *config);
     50static bool getdependentMode(pxConfig *config);
     51static bool pendingdependentMode(pxConfig *config);
     52static bool updatedependentMode(pxConfig *config);
    5053
    5154# define MODECASE(caseName, func) \
     
    8588        MODECASE(PSTAMPTOOL_MODE_MODPROJECT, modprojectMode);
    8689        MODECASE(PSTAMPTOOL_MODE_PROJECT, projectMode);
     90        MODECASE(PSTAMPTOOL_MODE_GETDEPENDENT, getdependentMode);
     91        MODECASE(PSTAMPTOOL_MODE_PENDINGDEPENDENT, pendingdependentMode);
     92        MODECASE(PSTAMPTOOL_MODE_UPDATEDEPENDENT, updatedependentMode);
    8793        default:
    8894            psAbort("invalid option (this should not happen)");
     
    545551    PXOPT_LOOKUP_S64(exp_id,      config->args, "-exp_id",     false, false);
    546552    PXOPT_LOOKUP_S64(options,     config->args, "-options",     false, false);
     553    PXOPT_LOOKUP_S64(dep_id,      config->args, "-dep_id",     false, false);
    547554
    548555    // unless the job is being inserted with stop state require outputBase
     
    570577            exp_id,
    571578            outputBase,
    572             options
     579            options,
     580            dep_id
    573581            )) {
    574582        psError(PS_ERR_UNKNOWN, false, "database error");
     
    896904}
    897905
     906static bool getdependentMode(pxConfig *config)
     907{
     908    PS_ASSERT_PTR_NON_NULL(config, false);
     909
     910    PXOPT_LOOKUP_STR(stage,       config->args, "-stage",   true, false);
     911    PXOPT_LOOKUP_S64(stage_id,    config->args, "-stage_id", true, false);
     912    PXOPT_LOOKUP_STR(imagedb,     config->args, "-imagedb",  true, false);
     913    PXOPT_LOOKUP_STR(rlabel,      config->args, "-rlabel",  false, false);
     914    PXOPT_LOOKUP_BOOL(no_magic,   config->args, "-no_magic", false);
     915    PXOPT_LOOKUP_BOOL(no_create,  config->args, "-no_create", false);
     916
     917    psString query = pxDataGet("pstamptool_pendingdependent.sql");
     918    if (!query) {
     919        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     920        return false;
     921    }
     922    if (!p_psDBRunQuery(config->dbh, query)) {
     923        psError(PS_ERR_UNKNOWN, false, "database error");
     924        psFree(query);
     925        return false;
     926    }
     927    psFree(query);
     928
     929    psArray *output = p_psDBFetchResult(config->dbh);
     930    if (!output) {
     931        psError(PS_ERR_UNKNOWN, false, "database error");
     932        return false;
     933    }
     934    if (psArrayLength(output)) {
     935        psMetadata *dep = output->data[0];
     936        psS64 dep_id = psMetadataLookupS64(NULL, dep, "dep_id");
     937        if (!dep_id) {
     938            psError(PS_ERR_UNKNOWN, false, "database error");
     939            return false;
     940        }
     941        printf("%" PRId64 "\n", dep_id);
     942        return true;
     943    }
     944    if (no_create) {
     945        return true;
     946    }
     947    // no existing dependent that matches, insert one
     948
     949    if (!pstampDependentInsert(
     950        config->dbh,
     951        0,              // dep_id
     952        "new",          // state
     953        stage,
     954        stage_id,
     955        imagedb,
     956        rlabel,
     957        no_magic
     958        )) {
     959        psError(PS_ERR_UNKNOWN, false, "failed to insert pstampDependent");
     960        return false;
     961    }
     962
     963    psS64 dep_id = psDBLastInsertID(config->dbh);
     964
     965    printf("%" PRId64 "\n", dep_id);
     966
     967    return true;
     968}
     969
     970static bool pendingdependentMode(pxConfig *config)
     971{
     972    PS_ASSERT_PTR_NON_NULL(config, false);
     973
     974    psMetadata *where = psMetadataAlloc();
     975
     976    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     977    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     978
     979    psString query = pxDataGet("pstamptool_pendingdependent.sql");
     980    if (!query) {
     981        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     982        return false;
     983    }
     984
     985    if (psListLength(where->list)) {
     986        psString whereClause = psDBGenerateWhereConditionSQL(where, "pstampDependent");
     987        psStringAppend(&query, " AND %s", whereClause);
     988        psFree(whereClause);
     989    }
     990    psFree(where);
     991
     992    // treat limit == 0 as "no limit"
     993    if (limit) {
     994        psString limitString = psDBGenerateLimitSQL(limit);
     995        psStringAppend(&query, " %s", limitString);
     996        psFree(limitString);
     997    }
     998
     999    if (!p_psDBRunQuery(config->dbh, query)) {
     1000        psError(PS_ERR_UNKNOWN, false, "database error");
     1001        psFree(query);
     1002        return false;
     1003    }
     1004    psFree(query);
     1005
     1006    psArray *output = p_psDBFetchResult(config->dbh);
     1007    if (!output) {
     1008        psError(PS_ERR_UNKNOWN, false, "database error");
     1009        return false;
     1010    }
     1011    if (!psArrayLength(output)) {
     1012        psTrace("pstamptool", PS_LOG_INFO, "no rows found");
     1013        psFree(output);
     1014        return true;
     1015    }
     1016
     1017    // negative simple so the default is true
     1018    if (!ippdbPrintMetadatas(stdout, output, "pstampDependent", !simple)) {
     1019        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1020        psFree(output);
     1021        return false;
     1022    }
     1023
     1024    psFree(output);
     1025
     1026    return true;
     1027}
     1028static bool updatedependentMode(pxConfig *config)
     1029{
     1030    PS_ASSERT_PTR_NON_NULL(config, false);
     1031
     1032    PXOPT_LOOKUP_S64(dep_id,    config->args, "-dep_id", true, false);
     1033    PXOPT_LOOKUP_STR(state,     config->args, "-set_state",  true, false);
     1034
     1035    char *query ="UPDATE pstampDependent"
     1036        " SET state = '%s'"
     1037        " WHERE dep_id = %" PRId64;
     1038   
     1039    if (!p_psDBRunQueryF(config->dbh, query, state, dep_id)) {
     1040        psError(PS_ERR_UNKNOWN, false, "database error");
     1041        psFree(query);
     1042        return false;
     1043    }
     1044
     1045    psU64 affected = psDBAffectedRows(config->dbh);
     1046    if (affected != 1) {
     1047        psError(PS_ERR_UNKNOWN, false, "should have affected one row but %"
     1048                                        PRIu64 " rows were modified", affected);
     1049        return false;
     1050    }
     1051
     1052    return true;
     1053}
Note: See TracChangeset for help on using the changeset viewer.