diff options
author | Chocobozzz <me@florianbigard.com> | 2022-07-06 15:44:14 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-07-06 16:12:17 +0200 |
commit | 9452d4fd3321148fb80b64a67bd9983fee6c208e (patch) | |
tree | 62ad9be8d3f4bfcf63196274ad4b736372c05f2c /server/initializers | |
parent | 630d0a1bf5897fff203cb07e426223f55dcc882d (diff) | |
download | PeerTube-9452d4fd3321148fb80b64a67bd9983fee6c208e.tar.gz PeerTube-9452d4fd3321148fb80b64a67bd9983fee6c208e.tar.zst PeerTube-9452d4fd3321148fb80b64a67bd9983fee6c208e.zip |
/!\ Use a dedicated config file for development
It means you have to replace NODE_ENV=test to NODE_ENV=dev if you use it
npm run dev:* commands are already updated
Diffstat (limited to 'server/initializers')
-rw-r--r-- | server/initializers/checker-after-init.ts | 7 | ||||
-rw-r--r-- | server/initializers/constants.ts | 81 | ||||
-rw-r--r-- | server/initializers/database.ts | 8 |
3 files changed, 52 insertions, 44 deletions
diff --git a/server/initializers/checker-after-init.ts b/server/initializers/checker-after-init.ts index f65798c42..e542a5395 100644 --- a/server/initializers/checker-after-init.ts +++ b/server/initializers/checker-after-init.ts | |||
@@ -4,7 +4,7 @@ import { URL } from 'url' | |||
4 | import { getFFmpegVersion } from '@server/helpers/ffmpeg' | 4 | import { getFFmpegVersion } from '@server/helpers/ffmpeg' |
5 | import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type' | 5 | import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type' |
6 | import { RecentlyAddedStrategy } from '../../shared/models/redundancy' | 6 | import { RecentlyAddedStrategy } from '../../shared/models/redundancy' |
7 | import { isProdInstance, isTestInstance, parseSemVersion } from '../helpers/core-utils' | 7 | import { isProdInstance, parseSemVersion } from '../helpers/core-utils' |
8 | import { isArray } from '../helpers/custom-validators/misc' | 8 | import { isArray } from '../helpers/custom-validators/misc' |
9 | import { logger } from '../helpers/logger' | 9 | import { logger } from '../helpers/logger' |
10 | import { ApplicationModel, getServerActor } from '../models/application/application' | 10 | import { ApplicationModel, getServerActor } from '../models/application/application' |
@@ -34,6 +34,9 @@ async function checkActivityPubUrls () { | |||
34 | // Some checks on configuration files or throw if there is an error | 34 | // Some checks on configuration files or throw if there is an error |
35 | function checkConfig () { | 35 | function checkConfig () { |
36 | 36 | ||
37 | const configFiles = config.util.getConfigSources().map(s => s.name).join(' -> ') | ||
38 | logger.info('Using following configuration file hierarchy: %s.', configFiles) | ||
39 | |||
37 | // Moved configuration keys | 40 | // Moved configuration keys |
38 | if (config.has('services.csp-logger')) { | 41 | if (config.has('services.csp-logger')) { |
39 | logger.warn('services.csp-logger configuration has been renamed to csp.report_uri. Please update your configuration file.') | 42 | logger.warn('services.csp-logger configuration has been renamed to csp.report_uri. Please update your configuration file.') |
@@ -128,7 +131,7 @@ function checkLocalRedundancyConfig () { | |||
128 | } | 131 | } |
129 | 132 | ||
130 | // Lifetime should not be < 10 hours | 133 | // Lifetime should not be < 10 hours |
131 | if (!isTestInstance() && r.minLifetime < 1000 * 3600 * 10) { | 134 | if (isProdInstance() && r.minLifetime < 1000 * 3600 * 10) { |
132 | throw new Error('Video redundancy minimum lifetime should be >= 10 hours for strategy ' + r.strategy) | 135 | throw new Error('Video redundancy minimum lifetime should be >= 10 hours for strategy ' + r.strategy) |
133 | } | 136 | } |
134 | } | 137 | } |
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index e3683269c..009f878fc 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -19,7 +19,7 @@ import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' | |||
19 | import { VideoPlaylistPrivacy } from '../../shared/models/videos/playlist/video-playlist-privacy.model' | 19 | import { VideoPlaylistPrivacy } from '../../shared/models/videos/playlist/video-playlist-privacy.model' |
20 | import { VideoPlaylistType } from '../../shared/models/videos/playlist/video-playlist-type.model' | 20 | import { VideoPlaylistType } from '../../shared/models/videos/playlist/video-playlist-type.model' |
21 | // Do not use barrels, remain constants as independent as possible | 21 | // Do not use barrels, remain constants as independent as possible |
22 | import { isTestInstance, parseDurationToMs, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' | 22 | import { isTestInstance, isTestOrDevInstance, parseDurationToMs, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' |
23 | import { CONFIG, registerConfigChangedHandler } from './config' | 23 | import { CONFIG, registerConfigChangedHandler } from './config' |
24 | 24 | ||
25 | // --------------------------------------------------------------------------- | 25 | // --------------------------------------------------------------------------- |
@@ -822,57 +822,62 @@ const STATS_TIMESERIE = { | |||
822 | // --------------------------------------------------------------------------- | 822 | // --------------------------------------------------------------------------- |
823 | 823 | ||
824 | // Special constants for a test instance | 824 | // Special constants for a test instance |
825 | if (isTestInstance() === true && process.env.PRODUCTION_CONSTANTS !== 'true') { | 825 | if (process.env.PRODUCTION_CONSTANTS !== 'true') { |
826 | PRIVATE_RSA_KEY_SIZE = 1024 | 826 | if (isTestOrDevInstance()) { |
827 | PRIVATE_RSA_KEY_SIZE = 1024 | ||
827 | 828 | ||
828 | ACTOR_FOLLOW_SCORE.BASE = 20 | 829 | ACTOR_FOLLOW_SCORE.BASE = 20 |
829 | 830 | ||
830 | REMOTE_SCHEME.HTTP = 'http' | 831 | REMOTE_SCHEME.HTTP = 'http' |
831 | REMOTE_SCHEME.WS = 'ws' | 832 | REMOTE_SCHEME.WS = 'ws' |
832 | 833 | ||
833 | STATIC_MAX_AGE.SERVER = '0' | 834 | STATIC_MAX_AGE.SERVER = '0' |
834 | 835 | ||
835 | ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2 | 836 | SCHEDULER_INTERVALS_MS.ACTOR_FOLLOW_SCORES = 1000 |
836 | ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 10 * 1000 // 10 seconds | 837 | SCHEDULER_INTERVALS_MS.REMOVE_OLD_JOBS = 10000 |
837 | ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL = 10 * 1000 // 10 seconds | 838 | SCHEDULER_INTERVALS_MS.REMOVE_OLD_HISTORY = 5000 |
838 | ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL = 10 * 1000 // 10 seconds | 839 | SCHEDULER_INTERVALS_MS.REMOVE_OLD_VIEWS = 5000 |
840 | SCHEDULER_INTERVALS_MS.UPDATE_VIDEOS = 5000 | ||
841 | SCHEDULER_INTERVALS_MS.AUTO_FOLLOW_INDEX_INSTANCES = 5000 | ||
842 | SCHEDULER_INTERVALS_MS.UPDATE_INBOX_STATS = 5000 | ||
843 | SCHEDULER_INTERVALS_MS.CHECK_PEERTUBE_VERSION = 2000 | ||
839 | 844 | ||
840 | CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max = 100 * 1024 // 100KB | 845 | REPEAT_JOBS['videos-views-stats'] = { every: 5000 } |
841 | CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max = 400 * 1024 // 400KB | ||
842 | 846 | ||
843 | SCHEDULER_INTERVALS_MS.ACTOR_FOLLOW_SCORES = 1000 | 847 | REPEAT_JOBS['activitypub-cleaner'] = { every: 5000 } |
844 | SCHEDULER_INTERVALS_MS.REMOVE_OLD_JOBS = 10000 | 848 | AP_CLEANER.PERIOD = 5000 |
845 | SCHEDULER_INTERVALS_MS.REMOVE_OLD_HISTORY = 5000 | ||
846 | SCHEDULER_INTERVALS_MS.REMOVE_OLD_VIEWS = 5000 | ||
847 | SCHEDULER_INTERVALS_MS.UPDATE_VIDEOS = 5000 | ||
848 | SCHEDULER_INTERVALS_MS.AUTO_FOLLOW_INDEX_INSTANCES = 5000 | ||
849 | SCHEDULER_INTERVALS_MS.UPDATE_INBOX_STATS = 5000 | ||
850 | SCHEDULER_INTERVALS_MS.CHECK_PEERTUBE_VERSION = 2000 | ||
851 | 849 | ||
852 | REPEAT_JOBS['videos-views-stats'] = { every: 5000 } | 850 | REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1 |
853 | 851 | ||
854 | REPEAT_JOBS['activitypub-cleaner'] = { every: 5000 } | 852 | CONTACT_FORM_LIFETIME = 1000 // 1 second |
855 | AP_CLEANER.PERIOD = 5000 | ||
856 | 853 | ||
857 | REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1 | 854 | JOB_ATTEMPTS['email'] = 1 |
858 | 855 | ||
859 | VIEW_LIFETIME.VIEWER_COUNTER = 1000 * 5 // 5 second | 856 | FILES_CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000 |
860 | VIEW_LIFETIME.VIEWER_STATS = 1000 * 5 // 5 second | 857 | MEMOIZE_TTL.OVERVIEWS_SAMPLE = 3000 |
861 | CONTACT_FORM_LIFETIME = 1000 // 1 second | 858 | MEMOIZE_TTL.LIVE_ABLE_TO_UPLOAD = 3000 |
859 | OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD = 2 | ||
862 | 860 | ||
863 | JOB_ATTEMPTS['email'] = 1 | 861 | PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 5000 |
862 | } | ||
863 | |||
864 | if (isTestInstance()) { | ||
865 | ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2 | ||
866 | ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 10 * 1000 // 10 seconds | ||
867 | ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL = 10 * 1000 // 10 seconds | ||
868 | ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL = 10 * 1000 // 10 seconds | ||
864 | 869 | ||
865 | FILES_CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000 | 870 | CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max = 100 * 1024 // 100KB |
866 | MEMOIZE_TTL.OVERVIEWS_SAMPLE = 3000 | 871 | CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max = 400 * 1024 // 400KB |
867 | MEMOIZE_TTL.LIVE_ABLE_TO_UPLOAD = 3000 | ||
868 | OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD = 2 | ||
869 | 872 | ||
870 | PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 5000 | 873 | VIEW_LIFETIME.VIEWER_COUNTER = 1000 * 5 // 5 second |
874 | VIEW_LIFETIME.VIEWER_STATS = 1000 * 5 // 5 second | ||
871 | 875 | ||
872 | VIDEO_LIVE.CLEANUP_DELAY = getIntEnv('PEERTUBE_TEST_CONSTANTS_VIDEO_LIVE_CLEANUP_DELAY') ?? 5000 | 876 | VIDEO_LIVE.CLEANUP_DELAY = getIntEnv('PEERTUBE_TEST_CONSTANTS_VIDEO_LIVE_CLEANUP_DELAY') ?? 5000 |
873 | VIDEO_LIVE.SEGMENT_TIME_SECONDS.DEFAULT_LATENCY = 2 | 877 | VIDEO_LIVE.SEGMENT_TIME_SECONDS.DEFAULT_LATENCY = 2 |
874 | VIDEO_LIVE.SEGMENT_TIME_SECONDS.SMALL_LATENCY = 1 | 878 | VIDEO_LIVE.SEGMENT_TIME_SECONDS.SMALL_LATENCY = 1 |
875 | VIDEO_LIVE.EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION = 1 | 879 | VIDEO_LIVE.EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION = 1 |
880 | } | ||
876 | } | 881 | } |
877 | 882 | ||
878 | updateWebserverUrls() | 883 | updateWebserverUrls() |
diff --git a/server/initializers/database.ts b/server/initializers/database.ts index 09786a91f..91286241b 100644 --- a/server/initializers/database.ts +++ b/server/initializers/database.ts | |||
@@ -8,9 +8,10 @@ import { UserNotificationModel } from '@server/models/user/user-notification' | |||
8 | import { UserVideoHistoryModel } from '@server/models/user/user-video-history' | 8 | import { UserVideoHistoryModel } from '@server/models/user/user-video-history' |
9 | import { VideoJobInfoModel } from '@server/models/video/video-job-info' | 9 | import { VideoJobInfoModel } from '@server/models/video/video-job-info' |
10 | import { VideoLiveSessionModel } from '@server/models/video/video-live-session' | 10 | import { VideoLiveSessionModel } from '@server/models/video/video-live-session' |
11 | import { VideoSourceModel } from '@server/models/video/video-source' | ||
11 | import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer' | 12 | import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer' |
12 | import { LocalVideoViewerWatchSectionModel } from '@server/models/view/local-video-viewer-watch-section' | 13 | import { LocalVideoViewerWatchSectionModel } from '@server/models/view/local-video-viewer-watch-section' |
13 | import { isTestInstance } from '../helpers/core-utils' | 14 | import { isTestOrDevInstance } from '../helpers/core-utils' |
14 | import { logger } from '../helpers/logger' | 15 | import { logger } from '../helpers/logger' |
15 | import { AbuseModel } from '../models/abuse/abuse' | 16 | import { AbuseModel } from '../models/abuse/abuse' |
16 | import { AbuseMessageModel } from '../models/abuse/abuse-message' | 17 | import { AbuseMessageModel } from '../models/abuse/abuse-message' |
@@ -49,7 +50,6 @@ import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-pla | |||
49 | import { VideoTagModel } from '../models/video/video-tag' | 50 | import { VideoTagModel } from '../models/video/video-tag' |
50 | import { VideoViewModel } from '../models/view/video-view' | 51 | import { VideoViewModel } from '../models/view/video-view' |
51 | import { CONFIG } from './config' | 52 | import { CONFIG } from './config' |
52 | import { VideoSourceModel } from '@server/models/video/video-source' | ||
53 | 53 | ||
54 | require('pg').defaults.parseInt8 = true // Avoid BIGINT to be converted to string | 54 | require('pg').defaults.parseInt8 = true // Avoid BIGINT to be converted to string |
55 | 55 | ||
@@ -81,13 +81,13 @@ const sequelizeTypescript = new SequelizeTypescript({ | |||
81 | pool: { | 81 | pool: { |
82 | max: poolMax | 82 | max: poolMax |
83 | }, | 83 | }, |
84 | benchmark: isTestInstance(), | 84 | benchmark: isTestOrDevInstance(), |
85 | isolationLevel: Transaction.ISOLATION_LEVELS.SERIALIZABLE, | 85 | isolationLevel: Transaction.ISOLATION_LEVELS.SERIALIZABLE, |
86 | logging: (message: string, benchmark: number) => { | 86 | logging: (message: string, benchmark: number) => { |
87 | if (process.env.NODE_DB_LOG === 'false') return | 87 | if (process.env.NODE_DB_LOG === 'false') return |
88 | 88 | ||
89 | let newMessage = 'Executed SQL request' | 89 | let newMessage = 'Executed SQL request' |
90 | if (isTestInstance() === true && benchmark !== undefined) { | 90 | if (isTestOrDevInstance() === true && benchmark !== undefined) { |
91 | newMessage += ' in ' + benchmark + 'ms' | 91 | newMessage += ' in ' + benchmark + 'ms' |
92 | } | 92 | } |
93 | 93 | ||