diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-16 14:52:24 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | e0ce715a1ded6e84c877004dae3e354c8716fb06 (patch) | |
tree | c2a48af098e27fea2c2c6bb47b2daa68103c1a0e /server/lib/schedulers/plugins-check-scheduler.ts | |
parent | 89c344dba4ae2fca39cf636c3c6f09f31a339493 (diff) | |
download | PeerTube-e0ce715a1ded6e84c877004dae3e354c8716fb06.tar.gz PeerTube-e0ce715a1ded6e84c877004dae3e354c8716fb06.tar.zst PeerTube-e0ce715a1ded6e84c877004dae3e354c8716fb06.zip |
Check latest plugins version
Diffstat (limited to 'server/lib/schedulers/plugins-check-scheduler.ts')
-rw-r--r-- | server/lib/schedulers/plugins-check-scheduler.ts | 30 |
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 @@ | |||
1 | import { logger } from '../../helpers/logger' | 1 | import { logger } from '../../helpers/logger' |
2 | import { AbstractScheduler } from './abstract-scheduler' | 2 | import { AbstractScheduler } from './abstract-scheduler' |
3 | import { retryTransactionWrapper } from '../../helpers/database-utils' | ||
4 | import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants' | 3 | import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants' |
5 | import { CONFIG } from '../../initializers/config' | 4 | import { CONFIG } from '../../initializers/config' |
6 | import { PluginModel } from '../../models/server/plugin' | 5 | import { 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 () { |