You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

admin.go 15KB

10 years ago
10 years ago
Graceful Queues: Issue Indexing and Tasks (#9363) * Queue: Add generic graceful queues with settings * Queue & Setting: Add worker pool implementation * Queue: Add worker settings * Queue: Make resizing worker pools * Queue: Add name variable to queues * Queue: Add monitoring * Queue: Improve logging * Issues: Gracefulise the issues indexer Remove the old now unused specific queues * Task: Move to generic queue and gracefulise * Issues: Standardise the issues indexer queue settings * Fix test * Queue: Allow Redis to connect to unix * Prevent deadlock during early shutdown of issue indexer * Add MaxWorker settings to queues * Merge branch 'master' into graceful-queues * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/queue/queue_channel.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/queue/queue_disk.go * Update modules/queue/queue_disk_channel.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Rename queue.Description to queue.ManagedQueue as per @guillep2k * Cancel pool workers when removed * Remove dependency on queue from setting * Update modules/queue/queue_redis.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * As per @guillep2k add mutex locks on shutdown/terminate * move unlocking out of setInternal * Add warning if number of workers < 0 * Small changes as per @guillep2k * No redis host specified not found * Clean up documentation for queues * Update docs/content/doc/advanced/config-cheat-sheet.en-us.md * Update modules/indexer/issues/indexer_test.go * Ensure that persistable channel queue is added to manager * Rename QUEUE_NAME REDIS_QUEUE_NAME * Revert "Rename QUEUE_NAME REDIS_QUEUE_NAME" This reverts commit 1f83b4fc9b9dabda186257b38c265fe7012f90df. Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
4 years ago
Graceful Queues: Issue Indexing and Tasks (#9363) * Queue: Add generic graceful queues with settings * Queue & Setting: Add worker pool implementation * Queue: Add worker settings * Queue: Make resizing worker pools * Queue: Add name variable to queues * Queue: Add monitoring * Queue: Improve logging * Issues: Gracefulise the issues indexer Remove the old now unused specific queues * Task: Move to generic queue and gracefulise * Issues: Standardise the issues indexer queue settings * Fix test * Queue: Allow Redis to connect to unix * Prevent deadlock during early shutdown of issue indexer * Add MaxWorker settings to queues * Merge branch 'master' into graceful-queues * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/queue/queue_channel.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/queue/queue_disk.go * Update modules/queue/queue_disk_channel.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Rename queue.Description to queue.ManagedQueue as per @guillep2k * Cancel pool workers when removed * Remove dependency on queue from setting * Update modules/queue/queue_redis.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * As per @guillep2k add mutex locks on shutdown/terminate * move unlocking out of setInternal * Add warning if number of workers < 0 * Small changes as per @guillep2k * No redis host specified not found * Clean up documentation for queues * Update docs/content/doc/advanced/config-cheat-sheet.en-us.md * Update modules/indexer/issues/indexer_test.go * Ensure that persistable channel queue is added to manager * Rename QUEUE_NAME REDIS_QUEUE_NAME * Revert "Rename QUEUE_NAME REDIS_QUEUE_NAME" This reverts commit 1f83b4fc9b9dabda186257b38c265fe7012f90df. Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
4 years ago
10 years ago
Graceful Queues: Issue Indexing and Tasks (#9363) * Queue: Add generic graceful queues with settings * Queue & Setting: Add worker pool implementation * Queue: Add worker settings * Queue: Make resizing worker pools * Queue: Add name variable to queues * Queue: Add monitoring * Queue: Improve logging * Issues: Gracefulise the issues indexer Remove the old now unused specific queues * Task: Move to generic queue and gracefulise * Issues: Standardise the issues indexer queue settings * Fix test * Queue: Allow Redis to connect to unix * Prevent deadlock during early shutdown of issue indexer * Add MaxWorker settings to queues * Merge branch 'master' into graceful-queues * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/queue/queue_channel.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/queue/queue_disk.go * Update modules/queue/queue_disk_channel.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Rename queue.Description to queue.ManagedQueue as per @guillep2k * Cancel pool workers when removed * Remove dependency on queue from setting * Update modules/queue/queue_redis.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * As per @guillep2k add mutex locks on shutdown/terminate * move unlocking out of setInternal * Add warning if number of workers < 0 * Small changes as per @guillep2k * No redis host specified not found * Clean up documentation for queues * Update docs/content/doc/advanced/config-cheat-sheet.en-us.md * Update modules/indexer/issues/indexer_test.go * Ensure that persistable channel queue is added to manager * Rename QUEUE_NAME REDIS_QUEUE_NAME * Revert "Rename QUEUE_NAME REDIS_QUEUE_NAME" This reverts commit 1f83b4fc9b9dabda186257b38c265fe7012f90df. Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
4 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
8 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
Add support for federated avatars (#3320) * Add support for federated avatars Fixes #3105 Removes avatar fetching duplication code Adds an "Enable Federated Avatar" checkbox in user settings (defaults to unchecked) Moves avatar settings all in the same form, making local and remote avatars mutually exclusive Renames UploadAvatarForm to AvatarForm as it's not anymore only for uploading * Run gofmt on all modified files * Move Avatar form in its own page * Add go-libravatar dependency to vendor/ dir Hopefully helps with accepting the contribution. See also #3214 * Revert "Add go-libravatar dependency to vendor/ dir" This reverts commit a8cb93ae640bbb90f7d25012fc257bda9fae9b82. * Make federated avatar setting a global configuration Removes the per-user setting * Move avatar handling back to base tool, disable federated avatar in offline mode * Format, handle error * Properly set fallback host * Use unsupported github.com mirror for importing go-libravatar * Remove comment showing life exists outside of github.com ... pity, but contribution would not be accepted otherwise * Use Combo for Get and Post methods over /avatar * FEDERATED_AVATAR -> ENABLE_FEDERATED_AVATAR * Fix persistance of federated avatar lookup checkbox at install time * Federated Avatars -> Enable Federated Avatars * Use len(string) == 0 instead of string == "" * Move import line where it belong See https://github.com/Unknwon/go-code-convention/blob/master/en-US/import_packages.md Pity the import url is still the unofficial one, but oh well... * Save a line (and waste much more expensive time) * Remove redundant parens * Remove an empty line * Remove empty lines * Reorder lines to make diff smaller * Remove another newline Unknwon review got me start a fight against newlines * Move DISABLE_GRAVATAR and ENABLE_FEDERATED_AVATAR after OFFLINE_MODE On re-reading the diff I figured what Unknwon meant here: https://github.com/gogits/gogs/pull/3320/files#r73741106 * Remove newlines that weren't there before my intervention
7 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
5 years ago
Graceful Queues: Issue Indexing and Tasks (#9363) * Queue: Add generic graceful queues with settings * Queue & Setting: Add worker pool implementation * Queue: Add worker settings * Queue: Make resizing worker pools * Queue: Add name variable to queues * Queue: Add monitoring * Queue: Improve logging * Issues: Gracefulise the issues indexer Remove the old now unused specific queues * Task: Move to generic queue and gracefulise * Issues: Standardise the issues indexer queue settings * Fix test * Queue: Allow Redis to connect to unix * Prevent deadlock during early shutdown of issue indexer * Add MaxWorker settings to queues * Merge branch 'master' into graceful-queues * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/queue/queue_channel.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/queue/queue_disk.go * Update modules/queue/queue_disk_channel.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Rename queue.Description to queue.ManagedQueue as per @guillep2k * Cancel pool workers when removed * Remove dependency on queue from setting * Update modules/queue/queue_redis.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * As per @guillep2k add mutex locks on shutdown/terminate * move unlocking out of setInternal * Add warning if number of workers < 0 * Small changes as per @guillep2k * No redis host specified not found * Clean up documentation for queues * Update docs/content/doc/advanced/config-cheat-sheet.en-us.md * Update modules/indexer/issues/indexer_test.go * Ensure that persistable channel queue is added to manager * Rename QUEUE_NAME REDIS_QUEUE_NAME * Revert "Rename QUEUE_NAME REDIS_QUEUE_NAME" This reverts commit 1f83b4fc9b9dabda186257b38c265fe7012f90df. Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
4 years ago
Graceful Queues: Issue Indexing and Tasks (#9363) * Queue: Add generic graceful queues with settings * Queue & Setting: Add worker pool implementation * Queue: Add worker settings * Queue: Make resizing worker pools * Queue: Add name variable to queues * Queue: Add monitoring * Queue: Improve logging * Issues: Gracefulise the issues indexer Remove the old now unused specific queues * Task: Move to generic queue and gracefulise * Issues: Standardise the issues indexer queue settings * Fix test * Queue: Allow Redis to connect to unix * Prevent deadlock during early shutdown of issue indexer * Add MaxWorker settings to queues * Merge branch 'master' into graceful-queues * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/queue/queue_channel.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/queue/queue_disk.go * Update modules/queue/queue_disk_channel.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Rename queue.Description to queue.ManagedQueue as per @guillep2k * Cancel pool workers when removed * Remove dependency on queue from setting * Update modules/queue/queue_redis.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * As per @guillep2k add mutex locks on shutdown/terminate * move unlocking out of setInternal * Add warning if number of workers < 0 * Small changes as per @guillep2k * No redis host specified not found * Clean up documentation for queues * Update docs/content/doc/advanced/config-cheat-sheet.en-us.md * Update modules/indexer/issues/indexer_test.go * Ensure that persistable channel queue is added to manager * Rename QUEUE_NAME REDIS_QUEUE_NAME * Revert "Rename QUEUE_NAME REDIS_QUEUE_NAME" This reverts commit 1f83b4fc9b9dabda186257b38c265fe7012f90df. Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
4 years ago
Graceful Queues: Issue Indexing and Tasks (#9363) * Queue: Add generic graceful queues with settings * Queue & Setting: Add worker pool implementation * Queue: Add worker settings * Queue: Make resizing worker pools * Queue: Add name variable to queues * Queue: Add monitoring * Queue: Improve logging * Issues: Gracefulise the issues indexer Remove the old now unused specific queues * Task: Move to generic queue and gracefulise * Issues: Standardise the issues indexer queue settings * Fix test * Queue: Allow Redis to connect to unix * Prevent deadlock during early shutdown of issue indexer * Add MaxWorker settings to queues * Merge branch 'master' into graceful-queues * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/queue/queue_channel.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/queue/queue_disk.go * Update modules/queue/queue_disk_channel.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Rename queue.Description to queue.ManagedQueue as per @guillep2k * Cancel pool workers when removed * Remove dependency on queue from setting * Update modules/queue/queue_redis.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * As per @guillep2k add mutex locks on shutdown/terminate * move unlocking out of setInternal * Add warning if number of workers < 0 * Small changes as per @guillep2k * No redis host specified not found * Clean up documentation for queues * Update docs/content/doc/advanced/config-cheat-sheet.en-us.md * Update modules/indexer/issues/indexer_test.go * Ensure that persistable channel queue is added to manager * Rename QUEUE_NAME REDIS_QUEUE_NAME * Revert "Rename QUEUE_NAME REDIS_QUEUE_NAME" This reverts commit 1f83b4fc9b9dabda186257b38c265fe7012f90df. Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
4 years ago
Graceful Queues: Issue Indexing and Tasks (#9363) * Queue: Add generic graceful queues with settings * Queue & Setting: Add worker pool implementation * Queue: Add worker settings * Queue: Make resizing worker pools * Queue: Add name variable to queues * Queue: Add monitoring * Queue: Improve logging * Issues: Gracefulise the issues indexer Remove the old now unused specific queues * Task: Move to generic queue and gracefulise * Issues: Standardise the issues indexer queue settings * Fix test * Queue: Allow Redis to connect to unix * Prevent deadlock during early shutdown of issue indexer * Add MaxWorker settings to queues * Merge branch 'master' into graceful-queues * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/queue/queue_channel.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/queue/queue_disk.go * Update modules/queue/queue_disk_channel.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Rename queue.Description to queue.ManagedQueue as per @guillep2k * Cancel pool workers when removed * Remove dependency on queue from setting * Update modules/queue/queue_redis.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * As per @guillep2k add mutex locks on shutdown/terminate * move unlocking out of setInternal * Add warning if number of workers < 0 * Small changes as per @guillep2k * No redis host specified not found * Clean up documentation for queues * Update docs/content/doc/advanced/config-cheat-sheet.en-us.md * Update modules/indexer/issues/indexer_test.go * Ensure that persistable channel queue is added to manager * Rename QUEUE_NAME REDIS_QUEUE_NAME * Revert "Rename QUEUE_NAME REDIS_QUEUE_NAME" This reverts commit 1f83b4fc9b9dabda186257b38c265fe7012f90df. Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
4 years ago
Graceful Queues: Issue Indexing and Tasks (#9363) * Queue: Add generic graceful queues with settings * Queue & Setting: Add worker pool implementation * Queue: Add worker settings * Queue: Make resizing worker pools * Queue: Add name variable to queues * Queue: Add monitoring * Queue: Improve logging * Issues: Gracefulise the issues indexer Remove the old now unused specific queues * Task: Move to generic queue and gracefulise * Issues: Standardise the issues indexer queue settings * Fix test * Queue: Allow Redis to connect to unix * Prevent deadlock during early shutdown of issue indexer * Add MaxWorker settings to queues * Merge branch 'master' into graceful-queues * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/queue/queue_channel.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/queue/queue_disk.go * Update modules/queue/queue_disk_channel.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Rename queue.Description to queue.ManagedQueue as per @guillep2k * Cancel pool workers when removed * Remove dependency on queue from setting * Update modules/queue/queue_redis.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * As per @guillep2k add mutex locks on shutdown/terminate * move unlocking out of setInternal * Add warning if number of workers < 0 * Small changes as per @guillep2k * No redis host specified not found * Clean up documentation for queues * Update docs/content/doc/advanced/config-cheat-sheet.en-us.md * Update modules/indexer/issues/indexer_test.go * Ensure that persistable channel queue is added to manager * Rename QUEUE_NAME REDIS_QUEUE_NAME * Revert "Rename QUEUE_NAME REDIS_QUEUE_NAME" This reverts commit 1f83b4fc9b9dabda186257b38c265fe7012f90df. Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
4 years ago
Graceful Queues: Issue Indexing and Tasks (#9363) * Queue: Add generic graceful queues with settings * Queue & Setting: Add worker pool implementation * Queue: Add worker settings * Queue: Make resizing worker pools * Queue: Add name variable to queues * Queue: Add monitoring * Queue: Improve logging * Issues: Gracefulise the issues indexer Remove the old now unused specific queues * Task: Move to generic queue and gracefulise * Issues: Standardise the issues indexer queue settings * Fix test * Queue: Allow Redis to connect to unix * Prevent deadlock during early shutdown of issue indexer * Add MaxWorker settings to queues * Merge branch 'master' into graceful-queues * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/queue/queue_channel.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/queue/queue_disk.go * Update modules/queue/queue_disk_channel.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Rename queue.Description to queue.ManagedQueue as per @guillep2k * Cancel pool workers when removed * Remove dependency on queue from setting * Update modules/queue/queue_redis.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * As per @guillep2k add mutex locks on shutdown/terminate * move unlocking out of setInternal * Add warning if number of workers < 0 * Small changes as per @guillep2k * No redis host specified not found * Clean up documentation for queues * Update docs/content/doc/advanced/config-cheat-sheet.en-us.md * Update modules/indexer/issues/indexer_test.go * Ensure that persistable channel queue is added to manager * Rename QUEUE_NAME REDIS_QUEUE_NAME * Revert "Rename QUEUE_NAME REDIS_QUEUE_NAME" This reverts commit 1f83b4fc9b9dabda186257b38c265fe7012f90df. Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
4 years ago
Graceful Queues: Issue Indexing and Tasks (#9363) * Queue: Add generic graceful queues with settings * Queue & Setting: Add worker pool implementation * Queue: Add worker settings * Queue: Make resizing worker pools * Queue: Add name variable to queues * Queue: Add monitoring * Queue: Improve logging * Issues: Gracefulise the issues indexer Remove the old now unused specific queues * Task: Move to generic queue and gracefulise * Issues: Standardise the issues indexer queue settings * Fix test * Queue: Allow Redis to connect to unix * Prevent deadlock during early shutdown of issue indexer * Add MaxWorker settings to queues * Merge branch 'master' into graceful-queues * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/indexer/issues/indexer.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/queue/queue_channel.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Update modules/queue/queue_disk.go * Update modules/queue/queue_disk_channel.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Rename queue.Description to queue.ManagedQueue as per @guillep2k * Cancel pool workers when removed * Remove dependency on queue from setting * Update modules/queue/queue_redis.go Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * As per @guillep2k add mutex locks on shutdown/terminate * move unlocking out of setInternal * Add warning if number of workers < 0 * Small changes as per @guillep2k * No redis host specified not found * Clean up documentation for queues * Update docs/content/doc/advanced/config-cheat-sheet.en-us.md * Update modules/indexer/issues/indexer_test.go * Ensure that persistable channel queue is added to manager * Rename QUEUE_NAME REDIS_QUEUE_NAME * Revert "Rename QUEUE_NAME REDIS_QUEUE_NAME" This reverts commit 1f83b4fc9b9dabda186257b38c265fe7012f90df. Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2019 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package admin
  6. import (
  7. "encoding/json"
  8. "fmt"
  9. "net/url"
  10. "os"
  11. "runtime"
  12. "strconv"
  13. "strings"
  14. "time"
  15. "code.gitea.io/gitea/models"
  16. "code.gitea.io/gitea/modules/auth"
  17. "code.gitea.io/gitea/modules/base"
  18. "code.gitea.io/gitea/modules/context"
  19. "code.gitea.io/gitea/modules/cron"
  20. "code.gitea.io/gitea/modules/git"
  21. "code.gitea.io/gitea/modules/log"
  22. "code.gitea.io/gitea/modules/process"
  23. "code.gitea.io/gitea/modules/queue"
  24. "code.gitea.io/gitea/modules/setting"
  25. "code.gitea.io/gitea/modules/timeutil"
  26. "code.gitea.io/gitea/services/mailer"
  27. "gitea.com/macaron/macaron"
  28. "gitea.com/macaron/session"
  29. )
  30. const (
  31. tplDashboard base.TplName = "admin/dashboard"
  32. tplConfig base.TplName = "admin/config"
  33. tplMonitor base.TplName = "admin/monitor"
  34. tplQueue base.TplName = "admin/queue"
  35. )
  36. var (
  37. startTime = time.Now()
  38. )
  39. var sysStatus struct {
  40. Uptime string
  41. NumGoroutine int
  42. // General statistics.
  43. MemAllocated string // bytes allocated and still in use
  44. MemTotal string // bytes allocated (even if freed)
  45. MemSys string // bytes obtained from system (sum of XxxSys below)
  46. Lookups uint64 // number of pointer lookups
  47. MemMallocs uint64 // number of mallocs
  48. MemFrees uint64 // number of frees
  49. // Main allocation heap statistics.
  50. HeapAlloc string // bytes allocated and still in use
  51. HeapSys string // bytes obtained from system
  52. HeapIdle string // bytes in idle spans
  53. HeapInuse string // bytes in non-idle span
  54. HeapReleased string // bytes released to the OS
  55. HeapObjects uint64 // total number of allocated objects
  56. // Low-level fixed-size structure allocator statistics.
  57. // Inuse is bytes used now.
  58. // Sys is bytes obtained from system.
  59. StackInuse string // bootstrap stacks
  60. StackSys string
  61. MSpanInuse string // mspan structures
  62. MSpanSys string
  63. MCacheInuse string // mcache structures
  64. MCacheSys string
  65. BuckHashSys string // profiling bucket hash table
  66. GCSys string // GC metadata
  67. OtherSys string // other system allocations
  68. // Garbage collector statistics.
  69. NextGC string // next run in HeapAlloc time (bytes)
  70. LastGC string // last run in absolute time (ns)
  71. PauseTotalNs string
  72. PauseNs string // circular buffer of recent GC pause times, most recent at [(NumGC+255)%256]
  73. NumGC uint32
  74. }
  75. func updateSystemStatus() {
  76. sysStatus.Uptime = timeutil.TimeSincePro(startTime, "en")
  77. m := new(runtime.MemStats)
  78. runtime.ReadMemStats(m)
  79. sysStatus.NumGoroutine = runtime.NumGoroutine()
  80. sysStatus.MemAllocated = base.FileSize(int64(m.Alloc))
  81. sysStatus.MemTotal = base.FileSize(int64(m.TotalAlloc))
  82. sysStatus.MemSys = base.FileSize(int64(m.Sys))
  83. sysStatus.Lookups = m.Lookups
  84. sysStatus.MemMallocs = m.Mallocs
  85. sysStatus.MemFrees = m.Frees
  86. sysStatus.HeapAlloc = base.FileSize(int64(m.HeapAlloc))
  87. sysStatus.HeapSys = base.FileSize(int64(m.HeapSys))
  88. sysStatus.HeapIdle = base.FileSize(int64(m.HeapIdle))
  89. sysStatus.HeapInuse = base.FileSize(int64(m.HeapInuse))
  90. sysStatus.HeapReleased = base.FileSize(int64(m.HeapReleased))
  91. sysStatus.HeapObjects = m.HeapObjects
  92. sysStatus.StackInuse = base.FileSize(int64(m.StackInuse))
  93. sysStatus.StackSys = base.FileSize(int64(m.StackSys))
  94. sysStatus.MSpanInuse = base.FileSize(int64(m.MSpanInuse))
  95. sysStatus.MSpanSys = base.FileSize(int64(m.MSpanSys))
  96. sysStatus.MCacheInuse = base.FileSize(int64(m.MCacheInuse))
  97. sysStatus.MCacheSys = base.FileSize(int64(m.MCacheSys))
  98. sysStatus.BuckHashSys = base.FileSize(int64(m.BuckHashSys))
  99. sysStatus.GCSys = base.FileSize(int64(m.GCSys))
  100. sysStatus.OtherSys = base.FileSize(int64(m.OtherSys))
  101. sysStatus.NextGC = base.FileSize(int64(m.NextGC))
  102. sysStatus.LastGC = fmt.Sprintf("%.1fs", float64(time.Now().UnixNano()-int64(m.LastGC))/1000/1000/1000)
  103. sysStatus.PauseTotalNs = fmt.Sprintf("%.1fs", float64(m.PauseTotalNs)/1000/1000/1000)
  104. sysStatus.PauseNs = fmt.Sprintf("%.3fs", float64(m.PauseNs[(m.NumGC+255)%256])/1000/1000/1000)
  105. sysStatus.NumGC = m.NumGC
  106. }
  107. // Dashboard show admin panel dashboard
  108. func Dashboard(ctx *context.Context) {
  109. ctx.Data["Title"] = ctx.Tr("admin.dashboard")
  110. ctx.Data["PageIsAdmin"] = true
  111. ctx.Data["PageIsAdminDashboard"] = true
  112. ctx.Data["Stats"] = models.GetStatistic()
  113. // FIXME: update periodically
  114. updateSystemStatus()
  115. ctx.Data["SysStatus"] = sysStatus
  116. ctx.HTML(200, tplDashboard)
  117. }
  118. // DashboardPost run an admin operation
  119. func DashboardPost(ctx *context.Context, form auth.AdminDashboardForm) {
  120. ctx.Data["Title"] = ctx.Tr("admin.dashboard")
  121. ctx.Data["PageIsAdmin"] = true
  122. ctx.Data["PageIsAdminDashboard"] = true
  123. ctx.Data["Stats"] = models.GetStatistic()
  124. updateSystemStatus()
  125. ctx.Data["SysStatus"] = sysStatus
  126. // Run operation.
  127. if form.Op != "" {
  128. task := cron.GetTask(form.Op)
  129. if task != nil {
  130. go task.RunWithUser(ctx.User, nil)
  131. ctx.Flash.Success(ctx.Tr("admin.dashboard.task.started", ctx.Tr("admin.dashboard."+form.Op)))
  132. } else {
  133. ctx.Flash.Error(ctx.Tr("admin.dashboard.task.unknown", form.Op))
  134. }
  135. }
  136. if form.From == "monitor" {
  137. ctx.Redirect(setting.AppSubURL + "/admin/monitor")
  138. } else {
  139. ctx.Redirect(setting.AppSubURL + "/admin")
  140. }
  141. }
  142. // SendTestMail send test mail to confirm mail service is OK
  143. func SendTestMail(ctx *context.Context) {
  144. email := ctx.Query("email")
  145. // Send a test email to the user's email address and redirect back to Config
  146. if err := mailer.SendTestMail(email); err != nil {
  147. ctx.Flash.Error(ctx.Tr("admin.config.test_mail_failed", email, err))
  148. } else {
  149. ctx.Flash.Info(ctx.Tr("admin.config.test_mail_sent", email))
  150. }
  151. ctx.Redirect(setting.AppSubURL + "/admin/config")
  152. }
  153. func shadowPasswordKV(cfgItem, splitter string) string {
  154. fields := strings.Split(cfgItem, splitter)
  155. for i := 0; i < len(fields); i++ {
  156. if strings.HasPrefix(fields[i], "password=") {
  157. fields[i] = "password=******"
  158. break
  159. }
  160. }
  161. return strings.Join(fields, splitter)
  162. }
  163. func shadowURL(provider, cfgItem string) string {
  164. u, err := url.Parse(cfgItem)
  165. if err != nil {
  166. log.Error("Shadowing Password for %v failed: %v", provider, err)
  167. return cfgItem
  168. }
  169. if u.User != nil {
  170. atIdx := strings.Index(cfgItem, "@")
  171. if atIdx > 0 {
  172. colonIdx := strings.LastIndex(cfgItem[:atIdx], ":")
  173. if colonIdx > 0 {
  174. return cfgItem[:colonIdx+1] + "******" + cfgItem[atIdx:]
  175. }
  176. }
  177. }
  178. return cfgItem
  179. }
  180. func shadowPassword(provider, cfgItem string) string {
  181. switch provider {
  182. case "redis":
  183. return shadowPasswordKV(cfgItem, ",")
  184. case "mysql":
  185. //root:@tcp(localhost:3306)/macaron?charset=utf8
  186. atIdx := strings.Index(cfgItem, "@")
  187. if atIdx > 0 {
  188. colonIdx := strings.Index(cfgItem[:atIdx], ":")
  189. if colonIdx > 0 {
  190. return cfgItem[:colonIdx+1] + "******" + cfgItem[atIdx:]
  191. }
  192. }
  193. return cfgItem
  194. case "postgres":
  195. // user=jiahuachen dbname=macaron port=5432 sslmode=disable
  196. if !strings.HasPrefix(cfgItem, "postgres://") {
  197. return shadowPasswordKV(cfgItem, " ")
  198. }
  199. fallthrough
  200. case "couchbase":
  201. return shadowURL(provider, cfgItem)
  202. // postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full
  203. // Notice: use shadowURL
  204. }
  205. return cfgItem
  206. }
  207. // Config show admin config page
  208. func Config(ctx *context.Context) {
  209. ctx.Data["Title"] = ctx.Tr("admin.config")
  210. ctx.Data["PageIsAdmin"] = true
  211. ctx.Data["PageIsAdminConfig"] = true
  212. ctx.Data["CustomConf"] = setting.CustomConf
  213. ctx.Data["AppUrl"] = setting.AppURL
  214. ctx.Data["Domain"] = setting.Domain
  215. ctx.Data["OfflineMode"] = setting.OfflineMode
  216. ctx.Data["DisableRouterLog"] = setting.DisableRouterLog
  217. ctx.Data["RunUser"] = setting.RunUser
  218. ctx.Data["RunMode"] = strings.Title(macaron.Env)
  219. ctx.Data["GitVersion"], _ = git.BinVersion()
  220. ctx.Data["RepoRootPath"] = setting.RepoRootPath
  221. ctx.Data["CustomRootPath"] = setting.CustomPath
  222. ctx.Data["StaticRootPath"] = setting.StaticRootPath
  223. ctx.Data["LogRootPath"] = setting.LogRootPath
  224. ctx.Data["ScriptType"] = setting.ScriptType
  225. ctx.Data["ReverseProxyAuthUser"] = setting.ReverseProxyAuthUser
  226. ctx.Data["ReverseProxyAuthEmail"] = setting.ReverseProxyAuthEmail
  227. ctx.Data["SSH"] = setting.SSH
  228. ctx.Data["LFS"] = setting.LFS
  229. ctx.Data["Service"] = setting.Service
  230. ctx.Data["DbCfg"] = setting.Database
  231. ctx.Data["Webhook"] = setting.Webhook
  232. ctx.Data["MailerEnabled"] = false
  233. if setting.MailService != nil {
  234. ctx.Data["MailerEnabled"] = true
  235. ctx.Data["Mailer"] = setting.MailService
  236. }
  237. ctx.Data["CacheAdapter"] = setting.CacheService.Adapter
  238. ctx.Data["CacheInterval"] = setting.CacheService.Interval
  239. ctx.Data["CacheConn"] = shadowPassword(setting.CacheService.Adapter, setting.CacheService.Conn)
  240. ctx.Data["CacheItemTTL"] = setting.CacheService.TTL
  241. sessionCfg := setting.SessionConfig
  242. if sessionCfg.Provider == "VirtualSession" {
  243. var realSession session.Options
  244. if err := json.Unmarshal([]byte(sessionCfg.ProviderConfig), &realSession); err != nil {
  245. log.Error("Unable to unmarshall session config for virtualed provider config: %s\nError: %v", sessionCfg.ProviderConfig, err)
  246. }
  247. sessionCfg.Provider = realSession.Provider
  248. sessionCfg.ProviderConfig = realSession.ProviderConfig
  249. sessionCfg.CookieName = realSession.CookieName
  250. sessionCfg.CookiePath = realSession.CookiePath
  251. sessionCfg.Gclifetime = realSession.Gclifetime
  252. sessionCfg.Maxlifetime = realSession.Maxlifetime
  253. sessionCfg.Secure = realSession.Secure
  254. sessionCfg.Domain = realSession.Domain
  255. }
  256. sessionCfg.ProviderConfig = shadowPassword(sessionCfg.Provider, sessionCfg.ProviderConfig)
  257. ctx.Data["SessionConfig"] = sessionCfg
  258. ctx.Data["DisableGravatar"] = setting.DisableGravatar
  259. ctx.Data["EnableFederatedAvatar"] = setting.EnableFederatedAvatar
  260. ctx.Data["Git"] = setting.Git
  261. type envVar struct {
  262. Name, Value string
  263. }
  264. envVars := map[string]*envVar{}
  265. if len(os.Getenv("GITEA_WORK_DIR")) > 0 {
  266. envVars["GITEA_WORK_DIR"] = &envVar{"GITEA_WORK_DIR", os.Getenv("GITEA_WORK_DIR")}
  267. }
  268. if len(os.Getenv("GITEA_CUSTOM")) > 0 {
  269. envVars["GITEA_CUSTOM"] = &envVar{"GITEA_CUSTOM", os.Getenv("GITEA_CUSTOM")}
  270. }
  271. ctx.Data["EnvVars"] = envVars
  272. ctx.Data["Loggers"] = setting.GetLogDescriptions()
  273. ctx.Data["RedirectMacaronLog"] = setting.RedirectMacaronLog
  274. ctx.Data["EnableAccessLog"] = setting.EnableAccessLog
  275. ctx.Data["AccessLogTemplate"] = setting.AccessLogTemplate
  276. ctx.Data["DisableRouterLog"] = setting.DisableRouterLog
  277. ctx.Data["EnableXORMLog"] = setting.EnableXORMLog
  278. ctx.Data["LogSQL"] = setting.Database.LogSQL
  279. ctx.HTML(200, tplConfig)
  280. }
  281. // Monitor show admin monitor page
  282. func Monitor(ctx *context.Context) {
  283. ctx.Data["Title"] = ctx.Tr("admin.monitor")
  284. ctx.Data["PageIsAdmin"] = true
  285. ctx.Data["PageIsAdminMonitor"] = true
  286. ctx.Data["Processes"] = process.GetManager().Processes()
  287. ctx.Data["Entries"] = cron.ListTasks()
  288. ctx.Data["Queues"] = queue.GetManager().ManagedQueues()
  289. ctx.HTML(200, tplMonitor)
  290. }
  291. // MonitorCancel cancels a process
  292. func MonitorCancel(ctx *context.Context) {
  293. pid := ctx.ParamsInt64("pid")
  294. process.GetManager().Cancel(pid)
  295. ctx.JSON(200, map[string]interface{}{
  296. "redirect": setting.AppSubURL + "/admin/monitor",
  297. })
  298. }
  299. // Queue shows details for a specific queue
  300. func Queue(ctx *context.Context) {
  301. qid := ctx.ParamsInt64("qid")
  302. mq := queue.GetManager().GetManagedQueue(qid)
  303. if mq == nil {
  304. ctx.Status(404)
  305. return
  306. }
  307. ctx.Data["Title"] = ctx.Tr("admin.monitor.queue", mq.Name)
  308. ctx.Data["PageIsAdmin"] = true
  309. ctx.Data["PageIsAdminMonitor"] = true
  310. ctx.Data["Queue"] = mq
  311. ctx.HTML(200, tplQueue)
  312. }
  313. // WorkerCancel cancels a worker group
  314. func WorkerCancel(ctx *context.Context) {
  315. qid := ctx.ParamsInt64("qid")
  316. mq := queue.GetManager().GetManagedQueue(qid)
  317. if mq == nil {
  318. ctx.Status(404)
  319. return
  320. }
  321. pid := ctx.ParamsInt64("pid")
  322. mq.CancelWorkers(pid)
  323. ctx.Flash.Info(ctx.Tr("admin.monitor.queue.pool.cancelling"))
  324. ctx.JSON(200, map[string]interface{}{
  325. "redirect": setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid),
  326. })
  327. }
  328. // Flush flushes a queue
  329. func Flush(ctx *context.Context) {
  330. qid := ctx.ParamsInt64("qid")
  331. mq := queue.GetManager().GetManagedQueue(qid)
  332. if mq == nil {
  333. ctx.Status(404)
  334. return
  335. }
  336. timeout, err := time.ParseDuration(ctx.Query("timeout"))
  337. if err != nil {
  338. timeout = -1
  339. }
  340. ctx.Flash.Info(ctx.Tr("admin.monitor.queue.pool.flush.added", mq.Name))
  341. go func() {
  342. err := mq.Flush(timeout)
  343. if err != nil {
  344. log.Error("Flushing failure for %s: Error %v", mq.Name, err)
  345. }
  346. }()
  347. ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid))
  348. }
  349. // AddWorkers adds workers to a worker group
  350. func AddWorkers(ctx *context.Context) {
  351. qid := ctx.ParamsInt64("qid")
  352. mq := queue.GetManager().GetManagedQueue(qid)
  353. if mq == nil {
  354. ctx.Status(404)
  355. return
  356. }
  357. number := ctx.QueryInt("number")
  358. if number < 1 {
  359. ctx.Flash.Error(ctx.Tr("admin.monitor.queue.pool.addworkers.mustnumbergreaterzero"))
  360. ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid))
  361. return
  362. }
  363. timeout, err := time.ParseDuration(ctx.Query("timeout"))
  364. if err != nil {
  365. ctx.Flash.Error(ctx.Tr("admin.monitor.queue.pool.addworkers.musttimeoutduration"))
  366. ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid))
  367. return
  368. }
  369. if _, ok := mq.Managed.(queue.ManagedPool); !ok {
  370. ctx.Flash.Error(ctx.Tr("admin.monitor.queue.pool.none"))
  371. ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid))
  372. return
  373. }
  374. mq.AddWorkers(number, timeout)
  375. ctx.Flash.Success(ctx.Tr("admin.monitor.queue.pool.added"))
  376. ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid))
  377. }
  378. // SetQueueSettings sets the maximum number of workers and other settings for this queue
  379. func SetQueueSettings(ctx *context.Context) {
  380. qid := ctx.ParamsInt64("qid")
  381. mq := queue.GetManager().GetManagedQueue(qid)
  382. if mq == nil {
  383. ctx.Status(404)
  384. return
  385. }
  386. if _, ok := mq.Managed.(queue.ManagedPool); !ok {
  387. ctx.Flash.Error(ctx.Tr("admin.monitor.queue.pool.none"))
  388. ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid))
  389. return
  390. }
  391. maxNumberStr := ctx.Query("max-number")
  392. numberStr := ctx.Query("number")
  393. timeoutStr := ctx.Query("timeout")
  394. var err error
  395. var maxNumber, number int
  396. var timeout time.Duration
  397. if len(maxNumberStr) > 0 {
  398. maxNumber, err = strconv.Atoi(maxNumberStr)
  399. if err != nil {
  400. ctx.Flash.Error(ctx.Tr("admin.monitor.queue.settings.maxnumberworkers.error"))
  401. ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid))
  402. return
  403. }
  404. if maxNumber < -1 {
  405. maxNumber = -1
  406. }
  407. } else {
  408. maxNumber = mq.MaxNumberOfWorkers()
  409. }
  410. if len(numberStr) > 0 {
  411. number, err = strconv.Atoi(numberStr)
  412. if err != nil || number < 0 {
  413. ctx.Flash.Error(ctx.Tr("admin.monitor.queue.settings.numberworkers.error"))
  414. ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid))
  415. return
  416. }
  417. } else {
  418. number = mq.BoostWorkers()
  419. }
  420. if len(timeoutStr) > 0 {
  421. timeout, err = time.ParseDuration(timeoutStr)
  422. if err != nil {
  423. ctx.Flash.Error(ctx.Tr("admin.monitor.queue.settings.timeout.error"))
  424. ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid))
  425. return
  426. }
  427. } else {
  428. timeout = mq.BoostTimeout()
  429. }
  430. mq.SetPoolSettings(maxNumber, number, timeout)
  431. ctx.Flash.Success(ctx.Tr("admin.monitor.queue.settings.changed"))
  432. ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid))
  433. }