Migrate to stateless app.App (#17542)
* add request context * move initialialization to server * use app interface instead of global app functions * remove app context from webconn * cleanup * remove duplicated services * move context to separate package * remove finalize init method and move content to NewServer function * restart workers and schedulers after adding license for tests * reflect review comments Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c09369f14a
Коммит
5ea06e51d0
@@ -12,6 +12,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/app/request"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/plugin"
|
||||
"github.com/mattermost/mattermost-server/v5/shared/mlog"
|
||||
@@ -21,7 +22,7 @@ import (
|
||||
const minFirstPartSize = 5 * 1024 * 1024 // 5MB
|
||||
const IncompleteUploadSuffix = ".tmp"
|
||||
|
||||
func (a *App) runPluginsHook(info *model.FileInfo, file io.Reader) *model.AppError {
|
||||
func (a *App) runPluginsHook(c *request.Context, info *model.FileInfo, file io.Reader) *model.AppError {
|
||||
pluginsEnvironment := a.GetPluginsEnvironment()
|
||||
if pluginsEnvironment == nil {
|
||||
return nil
|
||||
@@ -39,7 +40,7 @@ func (a *App) runPluginsHook(info *model.FileInfo, file io.Reader) *model.AppErr
|
||||
defer close(errChan)
|
||||
var rejErr *model.AppError
|
||||
var once sync.Once
|
||||
pluginContext := a.PluginContext()
|
||||
pluginContext := pluginContext(c)
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
once.Do(func() {
|
||||
hookHasRunCh <- struct{}{}
|
||||
@@ -162,7 +163,7 @@ func (a *App) GetUploadSessionsForUser(userID string) ([]*model.UploadSession, *
|
||||
return uss, nil
|
||||
}
|
||||
|
||||
func (a *App) UploadData(us *model.UploadSession, rd io.Reader) (*model.FileInfo, *model.AppError) {
|
||||
func (a *App) UploadData(c *request.Context, us *model.UploadSession, rd io.Reader) (*model.FileInfo, *model.AppError) {
|
||||
// prevent more than one caller to upload data at the same time for a given upload session.
|
||||
// This is to avoid possible inconsistencies.
|
||||
a.Srv().uploadLockMapMut.Lock()
|
||||
@@ -258,7 +259,7 @@ func (a *App) UploadData(us *model.UploadSession, rd io.Reader) (*model.FileInfo
|
||||
}
|
||||
|
||||
// run plugins upload hook
|
||||
if err := a.runPluginsHook(info, file); err != nil {
|
||||
if err := a.runPluginsHook(c, info, file); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user