mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Tame BackgroundRunner: stop running when no more job (#6605)
A BackgroundRunner plugin instance will stop running (rescheduling a check every 2 seconds) when there is no (or no more) job to run. Clients of this service now have to emit an event after adding a job into PluginShare.backgroundJobs, so an already loaded but stopped BackgroundRunner can notice it and start running again.
This commit is contained in:
@@ -4,12 +4,19 @@ describe("BackgroundTaskPlugin", function()
|
||||
local MockTime = require("mock_time")
|
||||
local UIManager = require("ui/uimanager")
|
||||
|
||||
local BackgroundTaskPlugin_schedule_orig = BackgroundTaskPlugin._schedule
|
||||
setup(function()
|
||||
MockTime:install()
|
||||
local Device = require("device")
|
||||
Device.input.waitEvent = function() end
|
||||
UIManager._run_forever = true
|
||||
requireBackgroundRunner()
|
||||
-- Monkey patch this method to notify BackgroundRunner
|
||||
-- as it is not accessible to UIManager in these tests
|
||||
BackgroundTaskPlugin._schedule = function(...)
|
||||
BackgroundTaskPlugin_schedule_orig(...)
|
||||
notifyBackgroundJobsUpdated()
|
||||
end
|
||||
end)
|
||||
|
||||
teardown(function()
|
||||
@@ -17,6 +24,7 @@ describe("BackgroundTaskPlugin", function()
|
||||
package.unloadAll()
|
||||
require("document/canvascontext"):init(require("device"))
|
||||
stopBackgroundRunner()
|
||||
BackgroundTaskPlugin._schedule = BackgroundTaskPlugin_schedule_orig
|
||||
end)
|
||||
|
||||
local createTestPlugin = function(executable)
|
||||
|
||||
Reference in New Issue
Block a user