From 43c5a592cdcb5c35e7bbfef7155bc16100018929 Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Sat, 26 Sep 2015 17:03:01 +0100 Subject: [PATCH] Archive completed gathers --- lib/gather/gather_singleton.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/gather/gather_singleton.js b/lib/gather/gather_singleton.js index b890257..445f0b7 100644 --- a/lib/gather/gather_singleton.js +++ b/lib/gather/gather_singleton.js @@ -2,6 +2,9 @@ let Gather = require("./gather"); let gatherCallbacks = {}; +let winston = require("winston"); +let mongoose = require("mongoose"); +let ArchivedGather = mongoose.model("ArchivedGather"); // Register initial callback to reset gather when state is `done` gatherCallbacks['onDone'] = [function () { @@ -27,8 +30,17 @@ let newGather = () => { }); }; +let archiveGather = gather => { + ArchivedGather.archive(gather, (error, result) => { + if (error) winston.error(error); + }); +}; + let rotateGather = () => { - if (SingletonClass.current) SingletonClass.previous = SingletonClass.current; + if (SingletonClass.current) { + SingletonClass.previous = SingletonClass.current; + archiveGather(SingletonClass.previous); + } return newGather(); }