aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/schedulers/plugins-check-scheduler.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/schedulers/plugins-check-scheduler.ts')
-rw-r--r--server/lib/schedulers/plugins-check-scheduler.ts30
1 files changed, 19 insertions, 11 deletions
diff --git a/server/lib/schedulers/plugins-check-scheduler.ts b/server/lib/schedulers/plugins-check-scheduler.ts
index 9c60dbcd4..8dfdd5177 100644
--- a/server/lib/schedulers/plugins-check-scheduler.ts
+++ b/server/lib/schedulers/plugins-check-scheduler.ts
@@ -1,6 +1,5 @@
1import { logger } from '../../helpers/logger' 1import { logger } from '../../helpers/logger'
2import { AbstractScheduler } from './abstract-scheduler' 2import { AbstractScheduler } from './abstract-scheduler'
3import { retryTransactionWrapper } from '../../helpers/database-utils'
4import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants' 3import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
5import { CONFIG } from '../../initializers/config' 4import { CONFIG } from '../../initializers/config'
6import { PluginModel } from '../../models/server/plugin' 5import { PluginModel } from '../../models/server/plugin'
@@ -19,13 +18,13 @@ export class PluginsCheckScheduler extends AbstractScheduler {
19 } 18 }
20 19
21 protected async internalExecute () { 20 protected async internalExecute () {
22 return retryTransactionWrapper(this.checkLatestPluginsVersion.bind(this)) 21 return this.checkLatestPluginsVersion()
23 } 22 }
24 23
25 private async checkLatestPluginsVersion () { 24 private async checkLatestPluginsVersion () {
26 if (CONFIG.PLUGINS.INDEX.ENABLED === false) return 25 if (CONFIG.PLUGINS.INDEX.ENABLED === false) return
27 26
28 logger.info('Checkin latest plugins version.') 27 logger.info('Checking latest plugins version.')
29 28
30 const plugins = await PluginModel.listInstalled() 29 const plugins = await PluginModel.listInstalled()
31 30
@@ -39,19 +38,28 @@ export class PluginsCheckScheduler extends AbstractScheduler {
39 } 38 }
40 39
41 const npmNames = Object.keys(pluginIndex) 40 const npmNames = Object.keys(pluginIndex)
42 const results = await getLatestPluginsVersion(npmNames)
43 41
44 for (const result of results) { 42 try {
45 const plugin = pluginIndex[result.npmName] 43 const results = await getLatestPluginsVersion(npmNames)
46 if (!result.latestVersion) continue
47 44
48 if (plugin.latestVersion !== result.latestVersion && compareSemVer(plugin.latestVersion, result.latestVersion) < 0) { 45 for (const result of results) {
49 plugin.latestVersion = result.latestVersion 46 const plugin = pluginIndex[ result.npmName ]
50 await plugin.save() 47 if (!result.latestVersion) continue
48
49 if (
50 !plugin.latestVersion ||
51 (plugin.latestVersion !== result.latestVersion && compareSemVer(plugin.latestVersion, result.latestVersion) < 0)
52 ) {
53 plugin.latestVersion = result.latestVersion
54 await plugin.save()
55
56 logger.info('Plugin %s has a new latest version %s.', PluginModel.buildNpmName(plugin.name, plugin.type), plugin.latestVersion)
57 }
51 } 58 }
59 } catch (err) {
60 logger.error('Cannot get latest plugins version.', { npmNames, err })
52 } 61 }
53 } 62 }
54
55 } 63 }
56 64
57 static get Instance () { 65 static get Instance () {