purge expired feeds
authorAleš Křenek <ljocha@ics.muni.cz>
Thu, 16 Mar 2006 18:33:40 +0000 (18:33 +0000)
committerAleš Křenek <ljocha@ics.muni.cz>
Thu, 16 Mar 2006 18:33:40 +0000 (18:33 +0000)
org.glite.jp.primary/src/bones_server.c
org.glite.jp.primary/src/new_ftp_backend.c

index b4c408c..d2c37b2 100644 (file)
@@ -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;
index 5b32915..5774b51 100644 (file)
@@ -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;
 }