diff --git a/spec/stores/task-queue-spec.coffee b/spec/stores/task-queue-spec.coffee index 0633d48ea..6712ecc63 100644 --- a/spec/stores/task-queue-spec.coffee +++ b/spec/stores/task-queue-spec.coffee @@ -54,6 +54,14 @@ describe "TaskQueue", -> expect(@retryInFutureTask.queueState.retryDelay).toEqual(undefined) expect(TaskQueue._updateSoon).toHaveBeenCalled() + it "should remove any items in the queue which were not deserialized as tasks", -> + queue = [@processingTask, {type: 'bla'}, @retryInFutureTask] + spyOn(DatabaseStore, 'findJSONBlob').andCallFake => Promise.resolve(queue) + spyOn(TaskQueue, '_updateSoon') + waitsForPromise => + TaskQueue._restoreQueue().then => + expect(TaskQueue._queue).toEqual([@processingTask, @retryInFutureTask]) + describe "findTask", -> beforeEach -> @subclassA = new TaskSubclassA() diff --git a/src/flux/stores/task-queue.coffee b/src/flux/stores/task-queue.coffee index 813148f8b..2ce35512c 100644 --- a/src/flux/stores/task-queue.coffee +++ b/src/flux/stores/task-queue.coffee @@ -6,6 +6,7 @@ path = require 'path' CoffeeHelpers = require '../coffee-helpers' Task = require("../tasks/task").default +TaskRegistry = require('../../task-registry').default Utils = require "../models/utils" Reflux = require 'reflux' Actions = require '../actions' @@ -112,6 +113,8 @@ class TaskQueue enqueue: (task) => if not (task instanceof Task) throw new Error("You must queue a `Task` instance") + if not (TaskRegistry.isInRegistry(task.constructor.name)) + throw new Error("You must queue a `Task` instance which is registred with the TaskRegistry") if not task.id throw new Error("Tasks must have an ID prior to being queued. Check that your Task constructor is calling `super`") if not task.queueState @@ -297,6 +300,11 @@ class TaskQueue delete task.queueState['retryAfter'] delete task.queueState['retryDelay'] + # The Task queue is completely wrecked if an item in the queue is not a + # task instance. This can happen if we removed or renamed the Task class, + # or if it was not registred with the TaskRegistry properly. + queue = queue.filter (task) => task instanceof Task + @_queue = queue @_updateSoon()