diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-25 15:05:18 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-25 18:41:17 +0100 |
commit | 94a5ff8a4a75d75bb9df542a39ce8769e7a7e6a4 (patch) | |
tree | 32a9148e0e4567f0c4ffae0412cbed20b84e8873 /server/initializers | |
parent | d765fafc3faf0db9818eb1a07161df1cb1bc0efa (diff) | |
download | PeerTube-94a5ff8a4a75d75bb9df542a39ce8769e7a7e6a4.tar.gz PeerTube-94a5ff8a4a75d75bb9df542a39ce8769e7a7e6a4.tar.zst PeerTube-94a5ff8a4a75d75bb9df542a39ce8769e7a7e6a4.zip |
Move job queue to redis
We'll use it as cache in the future.
/!\ You'll loose your old jobs (pending jobs too) so upgrade only when
you don't have pending job anymore.
Diffstat (limited to 'server/initializers')
-rw-r--r-- | server/initializers/constants.ts | 49 | ||||
-rw-r--r-- | server/initializers/database.ts | 2 | ||||
-rw-r--r-- | server/initializers/migrations/0100-activitypub.ts | 5 | ||||
-rw-r--r-- | server/initializers/migrations/0180-job-table-delete.ts | 18 |
4 files changed, 44 insertions, 30 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index cb043251a..329d0ffe8 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { IConfig } from 'config' | 1 | import { IConfig } from 'config' |
2 | import { dirname, join } from 'path' | 2 | import { dirname, join } from 'path' |
3 | import { JobCategory, JobState, VideoRateType } from '../../shared/models' | 3 | import { JobType, VideoRateType } from '../../shared/models' |
4 | import { ActivityPubActorType } from '../../shared/models/activitypub' | 4 | import { ActivityPubActorType } from '../../shared/models/activitypub' |
5 | import { FollowState } from '../../shared/models/actors' | 5 | import { FollowState } from '../../shared/models/actors' |
6 | import { VideoPrivacy } from '../../shared/models/videos' | 6 | import { VideoPrivacy } from '../../shared/models/videos' |
@@ -12,7 +12,7 @@ let config: IConfig = require('config') | |||
12 | 12 | ||
13 | // --------------------------------------------------------------------------- | 13 | // --------------------------------------------------------------------------- |
14 | 14 | ||
15 | const LAST_MIGRATION_VERSION = 175 | 15 | const LAST_MIGRATION_VERSION = 180 |
16 | 16 | ||
17 | // --------------------------------------------------------------------------- | 17 | // --------------------------------------------------------------------------- |
18 | 18 | ||
@@ -26,7 +26,7 @@ const PAGINATION_COUNT_DEFAULT = 15 | |||
26 | const SORTABLE_COLUMNS = { | 26 | const SORTABLE_COLUMNS = { |
27 | USERS: [ 'id', 'username', 'createdAt' ], | 27 | USERS: [ 'id', 'username', 'createdAt' ], |
28 | ACCOUNTS: [ 'createdAt' ], | 28 | ACCOUNTS: [ 'createdAt' ], |
29 | JOBS: [ 'id', 'createdAt' ], | 29 | JOBS: [ 'createdAt' ], |
30 | VIDEO_ABUSES: [ 'id', 'createdAt' ], | 30 | VIDEO_ABUSES: [ 'id', 'createdAt' ], |
31 | VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ], | 31 | VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ], |
32 | VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ], | 32 | VIDEOS: [ 'name', 'duration', 'createdAt', 'views', 'likes' ], |
@@ -61,23 +61,20 @@ const REMOTE_SCHEME = { | |||
61 | WS: 'wss' | 61 | WS: 'wss' |
62 | } | 62 | } |
63 | 63 | ||
64 | const JOB_STATES: { [ id: string ]: JobState } = { | 64 | const JOB_ATTEMPTS: { [ id in JobType ]: number } = { |
65 | PENDING: 'pending', | 65 | 'activitypub-http-broadcast': 5, |
66 | PROCESSING: 'processing', | 66 | 'activitypub-http-unicast': 5, |
67 | ERROR: 'error', | 67 | 'activitypub-http-fetcher': 5, |
68 | SUCCESS: 'success' | 68 | 'video-file': 1 |
69 | } | ||
70 | const JOB_CATEGORIES: { [ id: string ]: JobCategory } = { | ||
71 | TRANSCODING: 'transcoding', | ||
72 | ACTIVITYPUB_HTTP: 'activitypub-http' | ||
73 | } | 69 | } |
74 | // How many maximum jobs we fetch from the database per cycle | 70 | const JOB_CONCURRENCY: { [ id in JobType ]: number } = { |
75 | const JOBS_FETCH_LIMIT_PER_CYCLE = { | 71 | 'activitypub-http-broadcast': 1, |
76 | transcoding: 10, | 72 | 'activitypub-http-unicast': 5, |
77 | httpRequest: 20 | 73 | 'activitypub-http-fetcher': 1, |
74 | 'video-file': 1 | ||
78 | } | 75 | } |
79 | // 1 minutes | 76 | // 2 days |
80 | let JOBS_FETCHING_INTERVAL = 60000 | 77 | const JOB_COMPLETED_LIFETIME = 60000 * 60 * 24 * 2 |
81 | 78 | ||
82 | // 1 hour | 79 | // 1 hour |
83 | let SCHEDULER_INTERVAL = 60000 * 60 | 80 | let SCHEDULER_INTERVAL = 60000 * 60 |
@@ -96,6 +93,11 @@ const CONFIG = { | |||
96 | USERNAME: config.get<string>('database.username'), | 93 | USERNAME: config.get<string>('database.username'), |
97 | PASSWORD: config.get<string>('database.password') | 94 | PASSWORD: config.get<string>('database.password') |
98 | }, | 95 | }, |
96 | REDIS: { | ||
97 | HOSTNAME: config.get<string>('redis.hostname'), | ||
98 | PORT: config.get<string>('redis.port'), | ||
99 | AUTH: config.get<string>('redis.auth') | ||
100 | }, | ||
99 | STORAGE: { | 101 | STORAGE: { |
100 | AVATARS_DIR: buildPath(config.get<string>('storage.avatars')), | 102 | AVATARS_DIR: buildPath(config.get<string>('storage.avatars')), |
101 | LOG_DIR: buildPath(config.get<string>('storage.logs')), | 103 | LOG_DIR: buildPath(config.get<string>('storage.logs')), |
@@ -284,7 +286,6 @@ const ACTIVITY_PUB = { | |||
284 | PUBLIC: 'https://www.w3.org/ns/activitystreams#Public', | 286 | PUBLIC: 'https://www.w3.org/ns/activitystreams#Public', |
285 | COLLECTION_ITEMS_PER_PAGE: 10, | 287 | COLLECTION_ITEMS_PER_PAGE: 10, |
286 | FETCH_PAGE_LIMIT: 100, | 288 | FETCH_PAGE_LIMIT: 100, |
287 | MAX_HTTP_ATTEMPT: 5, | ||
288 | URL_MIME_TYPES: { | 289 | URL_MIME_TYPES: { |
289 | VIDEO: Object.keys(VIDEO_MIMETYPE_EXT), | 290 | VIDEO: Object.keys(VIDEO_MIMETYPE_EXT), |
290 | TORRENT: [ 'application/x-bittorrent' ], | 291 | TORRENT: [ 'application/x-bittorrent' ], |
@@ -358,7 +359,6 @@ const OPENGRAPH_AND_OEMBED_COMMENT = '<!-- open graph and oembed tags -->' | |||
358 | // Special constants for a test instance | 359 | // Special constants for a test instance |
359 | if (isTestInstance() === true) { | 360 | if (isTestInstance() === true) { |
360 | ACTOR_FOLLOW_SCORE.BASE = 20 | 361 | ACTOR_FOLLOW_SCORE.BASE = 20 |
361 | JOBS_FETCHING_INTERVAL = 1000 | ||
362 | REMOTE_SCHEME.HTTP = 'http' | 362 | REMOTE_SCHEME.HTTP = 'http' |
363 | REMOTE_SCHEME.WS = 'ws' | 363 | REMOTE_SCHEME.WS = 'ws' |
364 | STATIC_MAX_AGE = '0' | 364 | STATIC_MAX_AGE = '0' |
@@ -381,10 +381,8 @@ export { | |||
381 | CONFIG, | 381 | CONFIG, |
382 | CONSTRAINTS_FIELDS, | 382 | CONSTRAINTS_FIELDS, |
383 | EMBED_SIZE, | 383 | EMBED_SIZE, |
384 | JOB_STATES, | 384 | JOB_CONCURRENCY, |
385 | JOBS_FETCH_LIMIT_PER_CYCLE, | 385 | JOB_ATTEMPTS, |
386 | JOBS_FETCHING_INTERVAL, | ||
387 | JOB_CATEGORIES, | ||
388 | LAST_MIGRATION_VERSION, | 386 | LAST_MIGRATION_VERSION, |
389 | OAUTH_LIFETIME, | 387 | OAUTH_LIFETIME, |
390 | OPENGRAPH_AND_OEMBED_COMMENT, | 388 | OPENGRAPH_AND_OEMBED_COMMENT, |
@@ -408,7 +406,8 @@ export { | |||
408 | VIDEO_RATE_TYPES, | 406 | VIDEO_RATE_TYPES, |
409 | VIDEO_MIMETYPE_EXT, | 407 | VIDEO_MIMETYPE_EXT, |
410 | AVATAR_MIMETYPE_EXT, | 408 | AVATAR_MIMETYPE_EXT, |
411 | SCHEDULER_INTERVAL | 409 | SCHEDULER_INTERVAL, |
410 | JOB_COMPLETED_LIFETIME | ||
412 | } | 411 | } |
413 | 412 | ||
414 | // --------------------------------------------------------------------------- | 413 | // --------------------------------------------------------------------------- |
diff --git a/server/initializers/database.ts b/server/initializers/database.ts index 852db68a0..b537ee59a 100644 --- a/server/initializers/database.ts +++ b/server/initializers/database.ts | |||
@@ -9,7 +9,6 @@ import { ActorModel } from '../models/activitypub/actor' | |||
9 | import { ActorFollowModel } from '../models/activitypub/actor-follow' | 9 | import { ActorFollowModel } from '../models/activitypub/actor-follow' |
10 | import { ApplicationModel } from '../models/application/application' | 10 | import { ApplicationModel } from '../models/application/application' |
11 | import { AvatarModel } from '../models/avatar/avatar' | 11 | import { AvatarModel } from '../models/avatar/avatar' |
12 | import { JobModel } from '../models/job/job' | ||
13 | import { OAuthClientModel } from '../models/oauth/oauth-client' | 12 | import { OAuthClientModel } from '../models/oauth/oauth-client' |
14 | import { OAuthTokenModel } from '../models/oauth/oauth-token' | 13 | import { OAuthTokenModel } from '../models/oauth/oauth-token' |
15 | import { ServerModel } from '../models/server/server' | 14 | import { ServerModel } from '../models/server/server' |
@@ -61,7 +60,6 @@ async function initDatabaseModels (silent: boolean) { | |||
61 | ActorFollowModel, | 60 | ActorFollowModel, |
62 | AvatarModel, | 61 | AvatarModel, |
63 | AccountModel, | 62 | AccountModel, |
64 | JobModel, | ||
65 | OAuthClientModel, | 63 | OAuthClientModel, |
66 | OAuthTokenModel, | 64 | OAuthTokenModel, |
67 | ServerModel, | 65 | ServerModel, |
diff --git a/server/initializers/migrations/0100-activitypub.ts b/server/initializers/migrations/0100-activitypub.ts index 8c5198f85..a7ebd804c 100644 --- a/server/initializers/migrations/0100-activitypub.ts +++ b/server/initializers/migrations/0100-activitypub.ts | |||
@@ -1,11 +1,10 @@ | |||
1 | import { values } from 'lodash' | ||
2 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
3 | import { createPrivateAndPublicKeys } from '../../helpers/peertube-crypto' | 2 | import { createPrivateAndPublicKeys } from '../../helpers/peertube-crypto' |
4 | import { shareVideoByServerAndChannel } from '../../lib/activitypub/share' | 3 | import { shareVideoByServerAndChannel } from '../../lib/activitypub/share' |
5 | import { getVideoActivityPubUrl, getVideoChannelActivityPubUrl } from '../../lib/activitypub/url' | 4 | import { getVideoActivityPubUrl, getVideoChannelActivityPubUrl } from '../../lib/activitypub/url' |
6 | import { createLocalAccountWithoutKeys } from '../../lib/user' | 5 | import { createLocalAccountWithoutKeys } from '../../lib/user' |
7 | import { ApplicationModel } from '../../models/application/application' | 6 | import { ApplicationModel } from '../../models/application/application' |
8 | import { JOB_CATEGORIES, SERVER_ACTOR_NAME } from '../constants' | 7 | import { SERVER_ACTOR_NAME } from '../constants' |
9 | 8 | ||
10 | async function up (utils: { | 9 | async function up (utils: { |
11 | transaction: Sequelize.Transaction, | 10 | transaction: Sequelize.Transaction, |
@@ -161,7 +160,7 @@ async function up (utils: { | |||
161 | 160 | ||
162 | { | 161 | { |
163 | const data = { | 162 | const data = { |
164 | type: Sequelize.ENUM(values(JOB_CATEGORIES)), | 163 | type: Sequelize.ENUM('transcoding', 'activitypub-http'), |
165 | defaultValue: 'transcoding', | 164 | defaultValue: 'transcoding', |
166 | allowNull: false | 165 | allowNull: false |
167 | } | 166 | } |
diff --git a/server/initializers/migrations/0180-job-table-delete.ts b/server/initializers/migrations/0180-job-table-delete.ts new file mode 100644 index 000000000..df29145d0 --- /dev/null +++ b/server/initializers/migrations/0180-job-table-delete.ts | |||
@@ -0,0 +1,18 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | |||
3 | async function up (utils: { | ||
4 | transaction: Sequelize.Transaction, | ||
5 | queryInterface: Sequelize.QueryInterface, | ||
6 | sequelize: Sequelize.Sequelize | ||
7 | }): Promise<void> { | ||
8 | await utils.queryInterface.dropTable('job') | ||
9 | } | ||
10 | |||
11 | function down (options) { | ||
12 | throw new Error('Not implemented.') | ||
13 | } | ||
14 | |||
15 | export { | ||
16 | up, | ||
17 | down | ||
18 | } | ||