mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 04:42:33 +02:00

* fix: improved sync.Pool handling
* refactor: ping if-flow and remove timeout
* refactor: enhance favicon fetching with context support and improve cache management
- Added context support to favicon fetching functions to handle timeouts and cancellations.
- Improved cache entry structure to include content type and utilize atomic values for last access time.
- Implemented maximum cache size and entry limits to optimize memory usage.
- Updated error handling for HTTP requests and refined the logic for managing redirects.
* fix: log formatting
* feat(pool): add checkExists method to debug build to detect unexpected behavior
* chore: cont. 0866feb
* refactor: unify route handling by consolidating route query methods with Pool
- Replaced direct calls to routequery with a new routes package for better organization and maintainability.
- Updated various components to utilize the new routes methods for fetching health information, homepage configurations, and route aliases.
- Enhanced the overall structure of the routing logic to improve clarity and reduce redundancy.
* chore: uncomment icon list cache code
* refactor: update task management code
- Rename needFinish to waitFinish
- Fixed some tasks not being waited they should be
- Adjusted mutex usage in the directory watcher to utilize read-write locks for improved concurrency management.
* refactor: enhance idlewatcher logging and exit handling
* fix(server): ensure HTTP handler is set only if initialized
* refactor(accesslog): replace JSON log entry struct with zerolog for improved logging efficiency, updated test
* refactor: remove test run code
---------
Co-authored-by: yusing <yusing@6uo.me>
65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
package task
|
|
|
|
import (
|
|
"iter"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// debug only.
|
|
func (t *Task) listChildren() []string {
|
|
var children []string
|
|
allTasks.Range(func(child *Task) bool {
|
|
if child.parent == t {
|
|
children = append(children, strings.TrimPrefix(child.name, t.name+"."))
|
|
}
|
|
return true
|
|
})
|
|
return children
|
|
}
|
|
|
|
// debug only.
|
|
func (t *Task) listCallbacks() []string {
|
|
var callbacks []string
|
|
t.mu.Lock()
|
|
defer t.mu.Unlock()
|
|
for c := range t.callbacks {
|
|
callbacks = append(callbacks, c.about)
|
|
}
|
|
return callbacks
|
|
}
|
|
|
|
func AllTasks() iter.Seq2[string, *Task] {
|
|
return func(yield func(k string, v *Task) bool) {
|
|
for t := range allTasks.Range {
|
|
if !yield(t.name, t) {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func (t *Task) Key() string {
|
|
return t.name
|
|
}
|
|
|
|
func (t *Task) callbackList() []map[string]any {
|
|
list := make([]map[string]any, 0, len(t.callbacks))
|
|
for cb := range t.callbacks {
|
|
list = append(list, map[string]any{
|
|
"about": cb.about,
|
|
"wait_children": strconv.FormatBool(cb.waitChildren),
|
|
})
|
|
}
|
|
return list
|
|
}
|
|
|
|
func (t *Task) MarshalMap() map[string]any {
|
|
return map[string]any{
|
|
"name": t.name,
|
|
"need_finish": strconv.FormatBool(t.waitFinish),
|
|
"childrens": t.children,
|
|
"callbacks": t.callbackList(),
|
|
"finish_called": t.finishedCalled,
|
|
}
|
|
}
|