chiark / gitweb /
Log discarded junk events.
[disorder] / server / schedule.c
index 47cb6aa93dc197434bd868190cbbc3688d5d612c..a932f2d4139db9529e38ec8b02a7ac2bd31f8814 100644 (file)
@@ -208,6 +208,7 @@ static int schedule_init_tid(ev_source *ev,
       if(priority && !strcmp(priority, "junk")) {
         /* Junk actions that are in the past are discarded during startup */
        /* TODO recurring events should be handled differently here */
+        info("junk event %s is in the past, discarding", id);
        if(cdel(cursor))
          goto deadlocked;
         /* Skip this time */
@@ -249,8 +250,6 @@ void schedule_init(ev_source *ev) {
 /** @brief Create a scheduled event
  * @param ev Event loop
  * @param actiondata Action data
- *
- * The caller should set the timeout themselves.
  */
 static int schedule_add_tid(const char *id,
                            struct kvp *actiondata,
@@ -262,7 +261,8 @@ static int schedule_add_tid(const char *id,
   k.data = (void *)id;
   k.size = strlen(id);
   switch(err = trackdb_scheduledb->put(trackdb_scheduledb, tid, &k,
-                                       encode_data(&d, actiondata), 0)) {
+                                       encode_data(&d, actiondata),
+                                      DB_NOOVERWRITE)) {
   case 0:
     break;
   case DB_LOCK_DEADLOCK:
@@ -285,10 +285,10 @@ static int schedule_add_tid(const char *id,
  * is not allowed to perform them or if they are scheduled for a time
  * in the past.
  */
-char *schedule_add(ev_source *ev,
-                  struct kvp *actiondata) {
+const char *schedule_add(ev_source *ev,
+                        struct kvp *actiondata) {
   int e, n;
-  char *id;
+  const char *id;
   struct timeval when;
 
   /* TODO: handle recurring events */
@@ -314,7 +314,7 @@ char *schedule_add(ev_source *ev,
     id = random_id();
     WITH_TRANSACTION(schedule_add_tid(id, actiondata, tid));
   } while(e == DB_KEYEXIST);
-  ev_timeout(ev, 0/*handlep*/, &when, schedule_trigger, id);
+  ev_timeout(ev, 0/*handlep*/, &when, schedule_trigger, (void *)id);
   return id;
 }
 
@@ -363,6 +363,7 @@ char **schedule_list(int *neventsp) {
   int e;
   struct vector v[1];
 
+  vector_init(v);
   WITH_TRANSACTION(trackdb_listkeys(trackdb_scheduledb, v, tid));
   if(neventsp)
     *neventsp = v->nvec;