aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/schedulers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-16 11:33:22 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commit6702a1b2ccd666285dee9c72b5bace641d2fce8b (patch)
tree78b7125d664b6f6b6c993c4e8483e1bdd24a0a30 /server/lib/schedulers
parent503c6f440abc8f5924c38c4bd63591cb6cefacec (diff)
downloadPeerTube-6702a1b2ccd666285dee9c72b5bace641d2fce8b.tar.gz
PeerTube-6702a1b2ccd666285dee9c72b5bace641d2fce8b.tar.zst
PeerTube-6702a1b2ccd666285dee9c72b5bace641d2fce8b.zip
Add ability to search available plugins
Diffstat (limited to 'server/lib/schedulers')
-rw-r--r--server/lib/schedulers/plugins-check-scheduler.ts60
1 files changed, 60 insertions, 0 deletions
diff --git a/server/lib/schedulers/plugins-check-scheduler.ts b/server/lib/schedulers/plugins-check-scheduler.ts
new file mode 100644
index 000000000..9c60dbcd4
--- /dev/null
+++ b/server/lib/schedulers/plugins-check-scheduler.ts
@@ -0,0 +1,60 @@
1import { logger } from '../../helpers/logger'
2import { AbstractScheduler } from './abstract-scheduler'
3import { retryTransactionWrapper } from '../../helpers/database-utils'
4import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants'
5import { CONFIG } from '../../initializers/config'
6import { PluginModel } from '../../models/server/plugin'
7import { chunk } from 'lodash'
8import { getLatestPluginsVersion } from '../plugins/plugin-index'
9import { compareSemVer } from '../../../shared/core-utils/miscs/miscs'
10
11export class PluginsCheckScheduler extends AbstractScheduler {
12
13 private static instance: AbstractScheduler
14
15 protected schedulerIntervalMs = SCHEDULER_INTERVALS_MS.checkPlugins
16
17 private constructor () {
18 super()
19 }
20
21 protected async internalExecute () {
22 return retryTransactionWrapper(this.checkLatestPluginsVersion.bind(this))
23 }
24
25 private async checkLatestPluginsVersion () {
26 if (CONFIG.PLUGINS.INDEX.ENABLED === false) return
27
28 logger.info('Checkin latest plugins version.')
29
30 const plugins = await PluginModel.listInstalled()
31
32 // Process 10 plugins in 1 HTTP request
33 const chunks = chunk(plugins, 10)
34 for (const chunk of chunks) {
35 // Find plugins according to their npm name
36 const pluginIndex: { [npmName: string]: PluginModel} = {}
37 for (const plugin of chunk) {
38 pluginIndex[PluginModel.buildNpmName(plugin.name, plugin.type)] = plugin
39 }
40
41 const npmNames = Object.keys(pluginIndex)
42 const results = await getLatestPluginsVersion(npmNames)
43
44 for (const result of results) {
45 const plugin = pluginIndex[result.npmName]
46 if (!result.latestVersion) continue
47
48 if (plugin.latestVersion !== result.latestVersion && compareSemVer(plugin.latestVersion, result.latestVersion) < 0) {
49 plugin.latestVersion = result.latestVersion
50 await plugin.save()
51 }
52 }
53 }
54
55 }
56
57 static get Instance () {
58 return this.instance || (this.instance = new this())
59 }
60}