mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-24 08:04:11 +08:00
fix(tasks): Check Task is in registry, remove any non-tasks when loading
This commit is contained in:
parent
c8097f1cd9
commit
c6f6c7c3a0
2 changed files with 16 additions and 0 deletions
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in a new issue