c60118e7c4
Add Http Conn Count tracking. Move more panel phrases into the panel namespace. Use a string builder in hookgen. Use Countf() in a couple of places to eliminate boilerplate. Reduce prepared stmt boilerplate in forum store with a lambda. Reduce prepared stmt boilerplate in topic.go with a lambda. Reduce prepared stmt boilerplate in group.go with a lambda. Add TestSetCreatedAt method to *Topic. Add DateOlderThanQ method to *accDeleteBuilder and *accUpdateBuilder. Add Stmt method to *accUpdateBuilder and *AccSelectBuilder. Add AccBuilder interface. Shorten variable names. Shorten extractPerm name to ep. Add avatar_visibility setting stub. Implementation coming in a later commit. Don't set an IP for installer generated posts. Add counters_perf_tick_row hook. Add avatar_visibility phrase. Add avatar_visibility_label phrase. Rename forums_no_description to forums_no_desc. Rename panel.forums_create_description_label to panel.forums_create_desc_label. Rename panel.forums_create_description to panel.forums_create_desc. Rename panel_forum_description to panel.forum_desc. Rename panel_forum_description_placeholder to panel.forum_desc_placeholder. Add panel_debug_http_conns_label phrase. Add panel.forum_actions_head phrase. Add panel.forum_actions_create_head phrase. Add panel.forum_action_run_on_topic_creation phrase. Add panel.forum_action_run_days_after_topic_creation phrase. Add panel.forum_action_run_days_after_topic_last_reply phrase. Add panel.forum_action_action phrase. Add panel.forum_action_action_delete phrase. Add panel.forum_action_action_lock phrase. Add panel.forum_action_action_unlock phrase. Add panel.forum_action_action_move phrase. Add panel.forum_action_extra phrase. Add panel.forum_action_create_button phrase. You will need to run the patcher / updater for this commit.
153 lines
3.6 KiB
Go
153 lines
3.6 KiB
Go
/*
|
|
*
|
|
* Gosora Task System
|
|
* Copyright Azareal 2017 - 2020
|
|
*
|
|
*/
|
|
package common
|
|
|
|
import (
|
|
"database/sql"
|
|
"log"
|
|
"time"
|
|
|
|
qgen "github.com/Azareal/Gosora/query_gen"
|
|
)
|
|
|
|
type TaskStmts struct {
|
|
getExpiredScheduledGroups *sql.Stmt
|
|
getSync *sql.Stmt
|
|
}
|
|
|
|
var ScheduledHalfSecondTasks []func() error
|
|
var ScheduledSecondTasks []func() error
|
|
var ScheduledFifteenMinuteTasks []func() error
|
|
var ScheduledHourTasks []func() error
|
|
var ShutdownTasks []func() error
|
|
var taskStmts TaskStmts
|
|
var lastSync time.Time
|
|
|
|
// TODO: Add a TaskInits.Add
|
|
func init() {
|
|
lastSync = time.Now()
|
|
DbInits.Add(func(acc *qgen.Accumulator) error {
|
|
taskStmts = TaskStmts{
|
|
getExpiredScheduledGroups: acc.Select("users_groups_scheduler").Columns("uid").Where("UTC_TIMESTAMP() > revert_at AND temporary = 1").Prepare(),
|
|
getSync: acc.Select("sync").Columns("last_update").Prepare(),
|
|
}
|
|
return acc.FirstError()
|
|
})
|
|
}
|
|
|
|
// AddScheduledHalfSecondTask is not concurrency safe
|
|
func AddScheduledHalfSecondTask(task func() error) {
|
|
ScheduledHalfSecondTasks = append(ScheduledHalfSecondTasks, task)
|
|
}
|
|
|
|
// AddScheduledSecondTask is not concurrency safe
|
|
func AddScheduledSecondTask(task func() error) {
|
|
ScheduledSecondTasks = append(ScheduledSecondTasks, task)
|
|
}
|
|
|
|
// AddScheduledFifteenMinuteTask is not concurrency safe
|
|
func AddScheduledFifteenMinuteTask(task func() error) {
|
|
ScheduledFifteenMinuteTasks = append(ScheduledFifteenMinuteTasks, task)
|
|
}
|
|
|
|
// AddScheduledHourTask is not concurrency safe
|
|
func AddScheduledHourTask(task func() error) {
|
|
ScheduledHourTasks = append(ScheduledHourTasks, task)
|
|
}
|
|
|
|
// AddShutdownTask is not concurrency safe
|
|
func AddShutdownTask(task func() error) {
|
|
ShutdownTasks = append(ShutdownTasks, task)
|
|
}
|
|
|
|
// ScheduledHalfSecondTaskCount is not concurrency safe
|
|
func ScheduledHalfSecondTaskCount() int {
|
|
return len(ScheduledHalfSecondTasks)
|
|
}
|
|
|
|
// ScheduledSecondTaskCount is not concurrency safe
|
|
func ScheduledSecondTaskCount() int {
|
|
return len(ScheduledSecondTasks)
|
|
}
|
|
|
|
// ScheduledFifteenMinuteTaskCount is not concurrency safe
|
|
func ScheduledFifteenMinuteTaskCount() int {
|
|
return len(ScheduledFifteenMinuteTasks)
|
|
}
|
|
|
|
// ScheduledHourTaskCount is not concurrency safe
|
|
func ScheduledHourTaskCount() int {
|
|
return len(ScheduledHourTasks)
|
|
}
|
|
|
|
// ShutdownTaskCount is not concurrency safe
|
|
func ShutdownTaskCount() int {
|
|
return len(ShutdownTasks)
|
|
}
|
|
|
|
// TODO: Use AddScheduledSecondTask
|
|
func HandleExpiredScheduledGroups() error {
|
|
rows, e := taskStmts.getExpiredScheduledGroups.Query()
|
|
if e != nil {
|
|
return e
|
|
}
|
|
defer rows.Close()
|
|
|
|
var uid int
|
|
for rows.Next() {
|
|
if e := rows.Scan(&uid); e != nil {
|
|
return e
|
|
}
|
|
// Sneaky way of initialising a *User, please use the methods on the UserStore instead
|
|
user := BlankUser()
|
|
user.ID = uid
|
|
e = user.RevertGroupUpdate()
|
|
if e != nil {
|
|
return e
|
|
}
|
|
}
|
|
return rows.Err()
|
|
}
|
|
|
|
// TODO: Use AddScheduledSecondTask
|
|
// TODO: Be a little more granular with the synchronisation
|
|
// TODO: Synchronise more things
|
|
// TODO: Does this even work?
|
|
func HandleServerSync() error {
|
|
// We don't want to run any unnecessary queries when there is nothing to synchronise
|
|
if Config.ServerCount == 1 {
|
|
return nil
|
|
}
|
|
|
|
var lastUpdate time.Time
|
|
e := taskStmts.getSync.QueryRow().Scan(&lastUpdate)
|
|
if e != nil {
|
|
return e
|
|
}
|
|
|
|
if lastUpdate.After(lastSync) {
|
|
e = Forums.LoadForums()
|
|
if e != nil {
|
|
log.Print("Unable to reload the forums")
|
|
return e
|
|
}
|
|
// TODO: Resync the groups
|
|
// TODO: Resync the permissions
|
|
e = LoadSettings()
|
|
if e != nil {
|
|
log.Print("Unable to reload the settings")
|
|
return e
|
|
}
|
|
e = WordFilters.ReloadAll()
|
|
if e != nil {
|
|
log.Print("Unable to reload the word filters")
|
|
return e
|
|
}
|
|
}
|
|
return nil
|
|
}
|