typedef struct _glite_jpis_context {
glite_jp_context_t jpctx;
glite_jp_is_conf *conf;
- glite_jp_db_stmt_t select_unlocked_feed_stmt, lock_feed_stmt, init_feed_stmt, unlock_feed_stmt, select_info_feed_stmt, update_state_feed_stmt, update_error_feed_stmt, select_info_attrs_indexed;
+ glite_jp_db_stmt_t select_unlocked_feed_stmt, lock_feed_stmt, init_feed_stmt, unlock_feed_stmt, select_info_feed_stmt, update_state_feed_stmt, update_error_feed_stmt, select_info_attrs_indexed, select_jobid_stmt, insert_job_stmt;
long int param_uniqueid, param_state;
- char param_feedid[33], param_ps[256], param_indexed[256];
- unsigned long param_ps_len, param_feedid_len, param_indexed_len;
+ char param_feedid[33], param_ps[256], param_indexed[256], param_jobid[33], param_dg_jobid[256];
+ unsigned long param_ps_len, param_feedid_len, param_indexed_len, param_jobid_len, param_dg_jobid_len;
void *param_expires;
char *hname;
GLITE_JP_DB_TYPE_VARCHAR, NULL, &isctx->param_indexed, sizeof(isctx->param_indexed), &isctx->param_indexed_len);
if ((ret = glite_jp_db_prepare(jpctx, "SELECT name FROM attrs WHERE (indexed=1)", &isctx->select_info_attrs_indexed, NULL, myres)) != 0) goto fail;
+ // sql command: check for job with jobid
+ glite_jp_db_create_params(&myparam, 1,
+ GLITE_JP_DB_TYPE_CHAR, &isctx->param_jobid, &isctx->param_jobid_len);
+ if ((glite_jp_db_prepare(jpctx, "SELECT jobid FROM jobs WHERE jobid=?", &isctx->select_jobid_stmt, myparam, NULL)) != 0) goto fail;
+
+ // sql command: insert the job
+ glite_jp_db_create_params(&myparam, 3,
+ GLITE_JP_DB_TYPE_CHAR, &isctx->param_jobid, &isctx->param_jobid_len,
+ GLITE_JP_DB_TYPE_VARCHAR, &isctx->param_dg_jobid, &isctx->param_dg_jobid_len,
+ GLITE_JP_DB_TYPE_VARCHAR, &isctx->param_ps, &isctx->param_ps_len);
+ // XXX: as attribute?
+ if ((glite_jp_db_prepare(jpctx, "INSERT INTO jobs (jobid, dg_jobid, ownerid, ps) VALUES (?, ?, 'XXX: unknown', ?)", &isctx->insert_job_stmt, myparam, NULL)) != 0) goto fail;
+
return 0;
fail:
glite_jp_db_freestmt(&ctx->update_state_feed_stmt);
glite_jp_db_freestmt(&ctx->update_error_feed_stmt);
glite_jp_db_freestmt(&ctx->select_info_attrs_indexed);
+ glite_jp_db_freestmt(&ctx->select_jobid_stmt);
+ glite_jp_db_freestmt(&ctx->insert_job_stmt);
glite_jp_db_close(ctx->jpctx);
}
return 0;
}
+
+
+int glite_jpis_lazyInsertJob(glite_jpis_context_t ctx, const char *jobid) {
+ int ret;
+
+ lprintf("%s\n", __FUNCTION__);
+
+ switch (ret = glite_jp_db_execute(ctx->select_jobid_stmt)) {
+ case -1: return ctx->jpctx->error->code;
+ case 0:
+ lprintf("inserting jobid '%s'\n", jobid);
+ if (glite_jp_db_execute(ctx->insert_job_stmt) != 1) return ctx->jpctx->error->code;
+ break;
+ case 1: lprintf("jobid '%s' found\n", jobid); break;
+ default: assert(ret != 1); break;
+ }
+
+ return 0;
+}