From: Aleš Křenek Date: Thu, 16 Mar 2006 18:33:40 +0000 (+0000) Subject: purge expired feeds X-Git-Tag: first~17 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=01a34f6ad1df53221a552f57a1ff13a99c8c4c44;p=jra1mw.git purge expired feeds --- diff --git a/org.glite.jp.primary/src/bones_server.c b/org.glite.jp.primary/src/bones_server.c index b4c408c..d2c37b2 100644 --- a/org.glite.jp.primary/src/bones_server.c +++ b/org.glite.jp.primary/src/bones_server.c @@ -225,7 +225,8 @@ static int data_init(void **data) glite_jpps_srv_init(ctx); glite_jppsbe_init_slave(ctx); /* XXX: global but slave's */ //sleep(10); - if (glite_jppsbe_read_feeds(ctx)) fputs(glite_jp_error_chain(ctx),stderr); + if (glite_jppsbe_purge_feeds(ctx) || /* XXX: is there a better place for the call? */ + glite_jppsbe_read_feeds(ctx)) fputs(glite_jp_error_chain(ctx),stderr); printf("[%d] slave init done\n",getpid()); return 0; diff --git a/org.glite.jp.primary/src/new_ftp_backend.c b/org.glite.jp.primary/src/new_ftp_backend.c index 5b32915..5774b51 100644 --- a/org.glite.jp.primary/src/new_ftp_backend.c +++ b/org.glite.jp.primary/src/new_ftp_backend.c @@ -2181,8 +2181,49 @@ int glite_jppsbe_purge_feeds( glite_jp_context_t ctx ) { - /* TODO */ - abort(); + char *stmt = NULL,*feed = NULL; + char *expires = glite_jp_db_timetodb(time(NULL)); + glite_jp_error_t err; + glite_jp_db_stmt_t q = NULL; + int rows; + + memset(&err,0,sizeof err); + + trio_asprintf(&stmt,"select feedid from feeds where expires < %s",expires); + + if ((rows = glite_jp_db_execstmt(ctx, stmt, &q)) < 0) { + err.code = EIO; + err.desc = "select from feeds"; + glite_jp_stack_error(ctx,&err); + goto cleanup; + } + + while ((rows = glite_jp_db_fetchrow(q,&feed)) > 0) { + free(stmt); + trio_asprintf(&stmt,"delete from fed_jobs where feedid = '%|Ss'",feed); + if ((rows = glite_jp_db_execstmt(ctx, stmt, NULL)) < 0) { + err.code = EIO; + err.desc = "delete from fed_jobs"; + glite_jp_stack_error(ctx,&err); + goto cleanup; + } + } + + free(stmt); + trio_asprintf(&stmt,"delete from feeds where expires < %s",expires); + if ((rows = glite_jp_db_execstmt(ctx, stmt, NULL)) < 0) { + err.code = EIO; + err.desc = "select from feeds"; + glite_jp_stack_error(ctx,&err); + goto cleanup; + } + +cleanup: + glite_jp_db_freestmt(&q); + free(feed); + free(stmt); + free(expires); + return err.code; }