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

admin.go 16 kB

11 years ago
11 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>
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>
5 years ago
11 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>
5 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
9 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 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
8 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
6 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>
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>
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>
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>
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>
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>
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>
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  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/base"
  17. "code.gitea.io/gitea/modules/context"
  18. "code.gitea.io/gitea/modules/cron"
  19. "code.gitea.io/gitea/modules/git"
  20. "code.gitea.io/gitea/modules/graceful"
  21. "code.gitea.io/gitea/modules/log"
  22. "code.gitea.io/gitea/modules/process"
  23. "code.gitea.io/gitea/modules/queue"
  24. repo_module "code.gitea.io/gitea/modules/repository"
  25. "code.gitea.io/gitea/modules/setting"
  26. "code.gitea.io/gitea/modules/timeutil"
  27. "code.gitea.io/gitea/services/mailer"
  28. "gitea.com/macaron/macaron"
  29. "gitea.com/macaron/session"
  30. "github.com/unknwon/com"
  31. )
  32. const (
  33. tplDashboard base.TplName = "admin/dashboard"
  34. tplConfig base.TplName = "admin/config"
  35. tplMonitor base.TplName = "admin/monitor"
  36. tplQueue base.TplName = "admin/queue"
  37. )
  38. var (
  39. startTime = time.Now()
  40. )
  41. var sysStatus struct {
  42. Uptime string
  43. NumGoroutine int
  44. // General statistics.
  45. MemAllocated string // bytes allocated and still in use
  46. MemTotal string // bytes allocated (even if freed)
  47. MemSys string // bytes obtained from system (sum of XxxSys below)
  48. Lookups uint64 // number of pointer lookups
  49. MemMallocs uint64 // number of mallocs
  50. MemFrees uint64 // number of frees
  51. // Main allocation heap statistics.
  52. HeapAlloc string // bytes allocated and still in use
  53. HeapSys string // bytes obtained from system
  54. HeapIdle string // bytes in idle spans
  55. HeapInuse string // bytes in non-idle span
  56. HeapReleased string // bytes released to the OS
  57. HeapObjects uint64 // total number of allocated objects
  58. // Low-level fixed-size structure allocator statistics.
  59. // Inuse is bytes used now.
  60. // Sys is bytes obtained from system.
  61. StackInuse string // bootstrap stacks
  62. StackSys string
  63. MSpanInuse string // mspan structures
  64. MSpanSys string
  65. MCacheInuse string // mcache structures
  66. MCacheSys string
  67. BuckHashSys string // profiling bucket hash table
  68. GCSys string // GC metadata
  69. OtherSys string // other system allocations
  70. // Garbage collector statistics.
  71. NextGC string // next run in HeapAlloc time (bytes)
  72. LastGC string // last run in absolute time (ns)
  73. PauseTotalNs string
  74. PauseNs string // circular buffer of recent GC pause times, most recent at [(NumGC+255)%256]
  75. NumGC uint32
  76. }
  77. func updateSystemStatus() {
  78. sysStatus.Uptime = timeutil.TimeSincePro(startTime, "en")
  79. m := new(runtime.MemStats)
  80. runtime.ReadMemStats(m)
  81. sysStatus.NumGoroutine = runtime.NumGoroutine()
  82. sysStatus.MemAllocated = base.FileSize(int64(m.Alloc))
  83. sysStatus.MemTotal = base.FileSize(int64(m.TotalAlloc))
  84. sysStatus.MemSys = base.FileSize(int64(m.Sys))
  85. sysStatus.Lookups = m.Lookups
  86. sysStatus.MemMallocs = m.Mallocs
  87. sysStatus.MemFrees = m.Frees
  88. sysStatus.HeapAlloc = base.FileSize(int64(m.HeapAlloc))
  89. sysStatus.HeapSys = base.FileSize(int64(m.HeapSys))
  90. sysStatus.HeapIdle = base.FileSize(int64(m.HeapIdle))
  91. sysStatus.HeapInuse = base.FileSize(int64(m.HeapInuse))
  92. sysStatus.HeapReleased = base.FileSize(int64(m.HeapReleased))
  93. sysStatus.HeapObjects = m.HeapObjects
  94. sysStatus.StackInuse = base.FileSize(int64(m.StackInuse))
  95. sysStatus.StackSys = base.FileSize(int64(m.StackSys))
  96. sysStatus.MSpanInuse = base.FileSize(int64(m.MSpanInuse))
  97. sysStatus.MSpanSys = base.FileSize(int64(m.MSpanSys))
  98. sysStatus.MCacheInuse = base.FileSize(int64(m.MCacheInuse))
  99. sysStatus.MCacheSys = base.FileSize(int64(m.MCacheSys))
  100. sysStatus.BuckHashSys = base.FileSize(int64(m.BuckHashSys))
  101. sysStatus.GCSys = base.FileSize(int64(m.GCSys))
  102. sysStatus.OtherSys = base.FileSize(int64(m.OtherSys))
  103. sysStatus.NextGC = base.FileSize(int64(m.NextGC))
  104. sysStatus.LastGC = fmt.Sprintf("%.1fs", float64(time.Now().UnixNano()-int64(m.LastGC))/1000/1000/1000)
  105. sysStatus.PauseTotalNs = fmt.Sprintf("%.1fs", float64(m.PauseTotalNs)/1000/1000/1000)
  106. sysStatus.PauseNs = fmt.Sprintf("%.3fs", float64(m.PauseNs[(m.NumGC+255)%256])/1000/1000/1000)
  107. sysStatus.NumGC = m.NumGC
  108. }
  109. // Operation Operation types.
  110. type Operation int
  111. const (
  112. cleanInactivateUser Operation = iota + 1
  113. cleanRepoArchives
  114. cleanMissingRepos
  115. gitGCRepos
  116. syncSSHAuthorizedKey
  117. syncRepositoryUpdateHook
  118. reinitMissingRepository
  119. syncExternalUsers
  120. gitFsck
  121. deleteGeneratedRepositoryAvatars
  122. )
  123. // Dashboard show admin panel dashboard
  124. func Dashboard(ctx *context.Context) {
  125. ctx.Data["Title"] = ctx.Tr("admin.dashboard")
  126. ctx.Data["PageIsAdmin"] = true
  127. ctx.Data["PageIsAdminDashboard"] = true
  128. // Run operation.
  129. op, _ := com.StrTo(ctx.Query("op")).Int()
  130. if op > 0 {
  131. var err error
  132. var success string
  133. shutdownCtx := graceful.GetManager().ShutdownContext()
  134. switch Operation(op) {
  135. case cleanInactivateUser:
  136. success = ctx.Tr("admin.dashboard.delete_inactivate_accounts_success")
  137. err = models.DeleteInactivateUsers()
  138. case cleanRepoArchives:
  139. success = ctx.Tr("admin.dashboard.delete_repo_archives_success")
  140. err = models.DeleteRepositoryArchives()
  141. case cleanMissingRepos:
  142. success = ctx.Tr("admin.dashboard.delete_missing_repos_success")
  143. err = repo_module.DeleteMissingRepositories(ctx.User)
  144. case gitGCRepos:
  145. success = ctx.Tr("admin.dashboard.git_gc_repos_success")
  146. err = repo_module.GitGcRepos(shutdownCtx)
  147. case syncSSHAuthorizedKey:
  148. success = ctx.Tr("admin.dashboard.resync_all_sshkeys_success")
  149. err = models.RewriteAllPublicKeys()
  150. case syncRepositoryUpdateHook:
  151. success = ctx.Tr("admin.dashboard.resync_all_hooks_success")
  152. err = repo_module.SyncRepositoryHooks(shutdownCtx)
  153. case reinitMissingRepository:
  154. success = ctx.Tr("admin.dashboard.reinit_missing_repos_success")
  155. err = repo_module.ReinitMissingRepositories()
  156. case syncExternalUsers:
  157. success = ctx.Tr("admin.dashboard.sync_external_users_started")
  158. go graceful.GetManager().RunWithShutdownContext(models.SyncExternalUsers)
  159. case gitFsck:
  160. success = ctx.Tr("admin.dashboard.git_fsck_started")
  161. err = repo_module.GitFsck(shutdownCtx)
  162. case deleteGeneratedRepositoryAvatars:
  163. success = ctx.Tr("admin.dashboard.delete_generated_repository_avatars_success")
  164. err = models.RemoveRandomAvatars()
  165. }
  166. if err != nil {
  167. ctx.Flash.Error(err.Error())
  168. } else {
  169. ctx.Flash.Success(success)
  170. }
  171. ctx.Redirect(setting.AppSubURL + "/admin")
  172. return
  173. }
  174. ctx.Data["Stats"] = models.GetStatistic()
  175. // FIXME: update periodically
  176. updateSystemStatus()
  177. ctx.Data["SysStatus"] = sysStatus
  178. ctx.HTML(200, tplDashboard)
  179. }
  180. // SendTestMail send test mail to confirm mail service is OK
  181. func SendTestMail(ctx *context.Context) {
  182. email := ctx.Query("email")
  183. // Send a test email to the user's email address and redirect back to Config
  184. if err := mailer.SendTestMail(email); err != nil {
  185. ctx.Flash.Error(ctx.Tr("admin.config.test_mail_failed", email, err))
  186. } else {
  187. ctx.Flash.Info(ctx.Tr("admin.config.test_mail_sent", email))
  188. }
  189. ctx.Redirect(setting.AppSubURL + "/admin/config")
  190. }
  191. func shadowPasswordKV(cfgItem, splitter string) string {
  192. fields := strings.Split(cfgItem, splitter)
  193. for i := 0; i < len(fields); i++ {
  194. if strings.HasPrefix(fields[i], "password=") {
  195. fields[i] = "password=******"
  196. break
  197. }
  198. }
  199. return strings.Join(fields, splitter)
  200. }
  201. func shadowURL(provider, cfgItem string) string {
  202. u, err := url.Parse(cfgItem)
  203. if err != nil {
  204. log.Error("Shadowing Password for %v failed: %v", provider, err)
  205. return cfgItem
  206. }
  207. if u.User != nil {
  208. atIdx := strings.Index(cfgItem, "@")
  209. if atIdx > 0 {
  210. colonIdx := strings.LastIndex(cfgItem[:atIdx], ":")
  211. if colonIdx > 0 {
  212. return cfgItem[:colonIdx+1] + "******" + cfgItem[atIdx:]
  213. }
  214. }
  215. }
  216. return cfgItem
  217. }
  218. func shadowPassword(provider, cfgItem string) string {
  219. switch provider {
  220. case "redis":
  221. return shadowPasswordKV(cfgItem, ",")
  222. case "mysql":
  223. //root:@tcp(localhost:3306)/macaron?charset=utf8
  224. atIdx := strings.Index(cfgItem, "@")
  225. if atIdx > 0 {
  226. colonIdx := strings.Index(cfgItem[:atIdx], ":")
  227. if colonIdx > 0 {
  228. return cfgItem[:colonIdx+1] + "******" + cfgItem[atIdx:]
  229. }
  230. }
  231. return cfgItem
  232. case "postgres":
  233. // user=jiahuachen dbname=macaron port=5432 sslmode=disable
  234. if !strings.HasPrefix(cfgItem, "postgres://") {
  235. return shadowPasswordKV(cfgItem, " ")
  236. }
  237. fallthrough
  238. case "couchbase":
  239. return shadowURL(provider, cfgItem)
  240. // postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full
  241. // Notice: use shadowURL
  242. }
  243. return cfgItem
  244. }
  245. // Config show admin config page
  246. func Config(ctx *context.Context) {
  247. ctx.Data["Title"] = ctx.Tr("admin.config")
  248. ctx.Data["PageIsAdmin"] = true
  249. ctx.Data["PageIsAdminConfig"] = true
  250. ctx.Data["CustomConf"] = setting.CustomConf
  251. ctx.Data["AppUrl"] = setting.AppURL
  252. ctx.Data["Domain"] = setting.Domain
  253. ctx.Data["OfflineMode"] = setting.OfflineMode
  254. ctx.Data["DisableRouterLog"] = setting.DisableRouterLog
  255. ctx.Data["RunUser"] = setting.RunUser
  256. ctx.Data["RunMode"] = strings.Title(macaron.Env)
  257. ctx.Data["GitVersion"], _ = git.BinVersion()
  258. ctx.Data["RepoRootPath"] = setting.RepoRootPath
  259. ctx.Data["CustomRootPath"] = setting.CustomPath
  260. ctx.Data["StaticRootPath"] = setting.StaticRootPath
  261. ctx.Data["LogRootPath"] = setting.LogRootPath
  262. ctx.Data["ScriptType"] = setting.ScriptType
  263. ctx.Data["ReverseProxyAuthUser"] = setting.ReverseProxyAuthUser
  264. ctx.Data["ReverseProxyAuthEmail"] = setting.ReverseProxyAuthEmail
  265. ctx.Data["SSH"] = setting.SSH
  266. ctx.Data["LFS"] = setting.LFS
  267. ctx.Data["Service"] = setting.Service
  268. ctx.Data["DbCfg"] = setting.Database
  269. ctx.Data["Webhook"] = setting.Webhook
  270. ctx.Data["MailerEnabled"] = false
  271. if setting.MailService != nil {
  272. ctx.Data["MailerEnabled"] = true
  273. ctx.Data["Mailer"] = setting.MailService
  274. }
  275. ctx.Data["CacheAdapter"] = setting.CacheService.Adapter
  276. ctx.Data["CacheInterval"] = setting.CacheService.Interval
  277. ctx.Data["CacheConn"] = shadowPassword(setting.CacheService.Adapter, setting.CacheService.Conn)
  278. ctx.Data["CacheItemTTL"] = setting.CacheService.TTL
  279. sessionCfg := setting.SessionConfig
  280. if sessionCfg.Provider == "VirtualSession" {
  281. var realSession session.Options
  282. if err := json.Unmarshal([]byte(sessionCfg.ProviderConfig), &realSession); err != nil {
  283. log.Error("Unable to unmarshall session config for virtualed provider config: %s\nError: %v", sessionCfg.ProviderConfig, err)
  284. }
  285. sessionCfg = realSession
  286. }
  287. sessionCfg.ProviderConfig = shadowPassword(sessionCfg.Provider, sessionCfg.ProviderConfig)
  288. ctx.Data["SessionConfig"] = sessionCfg
  289. ctx.Data["DisableGravatar"] = setting.DisableGravatar
  290. ctx.Data["EnableFederatedAvatar"] = setting.EnableFederatedAvatar
  291. ctx.Data["Git"] = setting.Git
  292. type envVar struct {
  293. Name, Value string
  294. }
  295. envVars := map[string]*envVar{}
  296. if len(os.Getenv("GITEA_WORK_DIR")) > 0 {
  297. envVars["GITEA_WORK_DIR"] = &envVar{"GITEA_WORK_DIR", os.Getenv("GITEA_WORK_DIR")}
  298. }
  299. if len(os.Getenv("GITEA_CUSTOM")) > 0 {
  300. envVars["GITEA_CUSTOM"] = &envVar{"GITEA_CUSTOM", os.Getenv("GITEA_CUSTOM")}
  301. }
  302. ctx.Data["EnvVars"] = envVars
  303. ctx.Data["Loggers"] = setting.LogDescriptions
  304. ctx.Data["RedirectMacaronLog"] = setting.RedirectMacaronLog
  305. ctx.Data["EnableAccessLog"] = setting.EnableAccessLog
  306. ctx.Data["AccessLogTemplate"] = setting.AccessLogTemplate
  307. ctx.Data["DisableRouterLog"] = setting.DisableRouterLog
  308. ctx.Data["EnableXORMLog"] = setting.EnableXORMLog
  309. ctx.Data["LogSQL"] = setting.Database.LogSQL
  310. ctx.HTML(200, tplConfig)
  311. }
  312. // Monitor show admin monitor page
  313. func Monitor(ctx *context.Context) {
  314. ctx.Data["Title"] = ctx.Tr("admin.monitor")
  315. ctx.Data["PageIsAdmin"] = true
  316. ctx.Data["PageIsAdminMonitor"] = true
  317. ctx.Data["Processes"] = process.GetManager().Processes()
  318. ctx.Data["Entries"] = cron.ListTasks()
  319. ctx.Data["Queues"] = queue.GetManager().ManagedQueues()
  320. ctx.HTML(200, tplMonitor)
  321. }
  322. // MonitorCancel cancels a process
  323. func MonitorCancel(ctx *context.Context) {
  324. pid := ctx.ParamsInt64("pid")
  325. process.GetManager().Cancel(pid)
  326. ctx.JSON(200, map[string]interface{}{
  327. "redirect": ctx.Repo.RepoLink + "/admin/monitor",
  328. })
  329. }
  330. // Queue shows details for a specific queue
  331. func Queue(ctx *context.Context) {
  332. qid := ctx.ParamsInt64("qid")
  333. mq := queue.GetManager().GetManagedQueue(qid)
  334. if mq == nil {
  335. ctx.Status(404)
  336. return
  337. }
  338. ctx.Data["Title"] = ctx.Tr("admin.monitor.queue", mq.Name)
  339. ctx.Data["PageIsAdmin"] = true
  340. ctx.Data["PageIsAdminMonitor"] = true
  341. ctx.Data["Queue"] = mq
  342. ctx.HTML(200, tplQueue)
  343. }
  344. // WorkerCancel cancels a worker group
  345. func WorkerCancel(ctx *context.Context) {
  346. qid := ctx.ParamsInt64("qid")
  347. mq := queue.GetManager().GetManagedQueue(qid)
  348. if mq == nil {
  349. ctx.Status(404)
  350. return
  351. }
  352. pid := ctx.ParamsInt64("pid")
  353. mq.CancelWorkers(pid)
  354. ctx.Flash.Info(ctx.Tr("admin.monitor.queue.pool.cancelling"))
  355. ctx.JSON(200, map[string]interface{}{
  356. "redirect": setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid),
  357. })
  358. }
  359. // Flush flushes a queue
  360. func Flush(ctx *context.Context) {
  361. qid := ctx.ParamsInt64("qid")
  362. mq := queue.GetManager().GetManagedQueue(qid)
  363. if mq == nil {
  364. ctx.Status(404)
  365. return
  366. }
  367. timeout, err := time.ParseDuration(ctx.Query("timeout"))
  368. if err != nil {
  369. timeout = -1
  370. }
  371. ctx.Flash.Info(ctx.Tr("admin.monitor.queue.pool.flush.added", mq.Name))
  372. go func() {
  373. err := mq.Flush(timeout)
  374. if err != nil {
  375. log.Error("Flushing failure for %s: Error %v", mq.Name, err)
  376. }
  377. }()
  378. ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid))
  379. }
  380. // AddWorkers adds workers to a worker group
  381. func AddWorkers(ctx *context.Context) {
  382. qid := ctx.ParamsInt64("qid")
  383. mq := queue.GetManager().GetManagedQueue(qid)
  384. if mq == nil {
  385. ctx.Status(404)
  386. return
  387. }
  388. number := ctx.QueryInt("number")
  389. if number < 1 {
  390. ctx.Flash.Error(ctx.Tr("admin.monitor.queue.pool.addworkers.mustnumbergreaterzero"))
  391. ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid))
  392. return
  393. }
  394. timeout, err := time.ParseDuration(ctx.Query("timeout"))
  395. if err != nil {
  396. ctx.Flash.Error(ctx.Tr("admin.monitor.queue.pool.addworkers.musttimeoutduration"))
  397. ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid))
  398. return
  399. }
  400. if _, ok := mq.Managed.(queue.ManagedPool); !ok {
  401. ctx.Flash.Error(ctx.Tr("admin.monitor.queue.pool.none"))
  402. ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid))
  403. return
  404. }
  405. mq.AddWorkers(number, timeout)
  406. ctx.Flash.Success(ctx.Tr("admin.monitor.queue.pool.added"))
  407. ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid))
  408. }
  409. // SetQueueSettings sets the maximum number of workers and other settings for this queue
  410. func SetQueueSettings(ctx *context.Context) {
  411. qid := ctx.ParamsInt64("qid")
  412. mq := queue.GetManager().GetManagedQueue(qid)
  413. if mq == nil {
  414. ctx.Status(404)
  415. return
  416. }
  417. if _, ok := mq.Managed.(queue.ManagedPool); !ok {
  418. ctx.Flash.Error(ctx.Tr("admin.monitor.queue.pool.none"))
  419. ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid))
  420. return
  421. }
  422. maxNumberStr := ctx.Query("max-number")
  423. numberStr := ctx.Query("number")
  424. timeoutStr := ctx.Query("timeout")
  425. var err error
  426. var maxNumber, number int
  427. var timeout time.Duration
  428. if len(maxNumberStr) > 0 {
  429. maxNumber, err = strconv.Atoi(maxNumberStr)
  430. if err != nil {
  431. ctx.Flash.Error(ctx.Tr("admin.monitor.queue.settings.maxnumberworkers.error"))
  432. ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid))
  433. return
  434. }
  435. if maxNumber < -1 {
  436. maxNumber = -1
  437. }
  438. } else {
  439. maxNumber = mq.MaxNumberOfWorkers()
  440. }
  441. if len(numberStr) > 0 {
  442. number, err = strconv.Atoi(numberStr)
  443. if err != nil || number < 0 {
  444. ctx.Flash.Error(ctx.Tr("admin.monitor.queue.settings.numberworkers.error"))
  445. ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid))
  446. return
  447. }
  448. } else {
  449. number = mq.BoostWorkers()
  450. }
  451. if len(timeoutStr) > 0 {
  452. timeout, err = time.ParseDuration(timeoutStr)
  453. if err != nil {
  454. ctx.Flash.Error(ctx.Tr("admin.monitor.queue.settings.timeout.error"))
  455. ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid))
  456. return
  457. }
  458. } else {
  459. timeout = mq.BoostTimeout()
  460. }
  461. mq.SetPoolSettings(maxNumber, number, timeout)
  462. ctx.Flash.Success(ctx.Tr("admin.monitor.queue.settings.changed"))
  463. ctx.Redirect(setting.AppSubURL + fmt.Sprintf("/admin/monitor/queue/%d", qid))
  464. }