task locking
parent
6cb469fdb3
commit
3e952c2921
|
@ -262,6 +262,9 @@ func GetAllGroupTasksSteps() []structs.GroupTaskSteps {
|
|||
|
||||
database.DB.Find(&groupTaskStepsLogs)
|
||||
|
||||
// TODO: locked state
|
||||
// groupTaskStepsLogs[0].LockedByUserId = cache...
|
||||
|
||||
return groupTaskStepsLogs
|
||||
}
|
||||
|
||||
|
@ -282,10 +285,10 @@ func GetCategoryGroupTaskByCategoryAndGroupId(category string, groupId string) s
|
|||
func StartUnlockLockedGroupTaskStepsTicker() {
|
||||
ticker := time.NewTicker(1 * time.Second)
|
||||
|
||||
for _ = range ticker.C {
|
||||
for range ticker.C {
|
||||
for index, taskStep := range cache.GetLockedGroupTaskSteps() {
|
||||
if time.Since(taskStep.LockedAt).Seconds() > 3 {
|
||||
log.Debug().Msgf("Unlocked task step", index)
|
||||
log.Debug().Msgf("Unlocked task step %v", index)
|
||||
cache.RemoveLockedGroupTaskStep(index)
|
||||
|
||||
socketclients.BroadcastMessageExceptUserSessionId(taskStep.LockedByUserSession,
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package cache
|
||||
|
||||
import (
|
||||
"janex/admin-dashboard-backend/modules/structs"
|
||||
"sync"
|
||||
)
|
||||
|
||||
/*
|
||||
This stores the inputs that a user makes when typing into the input fields at a Group Task step.
|
||||
This storage is necessary so that other users when opening this GroupTask or reloading the browser receive the data entered by the one user.
|
||||
*/
|
||||
var groupTaskStepsInputs []structs.GroupTaskStepsInput
|
||||
var gtsi sync.RWMutex
|
|
@ -2,8 +2,11 @@ package cache
|
|||
|
||||
import (
|
||||
"janex/admin-dashboard-backend/modules/structs"
|
||||
"janex/admin-dashboard-backend/modules/utils"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var lockedGroupTaskSteps []*structs.LockedGroupTaskSteps
|
||||
|
@ -42,3 +45,20 @@ func GetLockedGroupTaskSteps() []*structs.LockedGroupTaskSteps {
|
|||
|
||||
return lockedGroupTaskSteps
|
||||
}
|
||||
|
||||
func ExtendLockedGroupTaskStepLockedAtTime(lockedGroupTaskStep structs.LockedGroupTaskSteps) {
|
||||
lgtMu.Lock()
|
||||
|
||||
log.Debug().Msg("start extending")
|
||||
|
||||
for i, step := range lockedGroupTaskSteps {
|
||||
if step.GroupTaskId == lockedGroupTaskStep.GroupTaskId {
|
||||
step.LockedAt = time.Now().Add(utils.GroupTaskLockedTime * time.Second)
|
||||
lockedGroupTaskSteps[i] = step
|
||||
log.Debug().Msg("time extended")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
lgtMu.Unlock()
|
||||
}
|
||||
|
|
|
@ -81,7 +81,6 @@ type TaskParameter struct {
|
|||
}
|
||||
|
||||
// used for ui when a user is writing into input field to lock the task step for other users
|
||||
|
||||
type LockedGroupTaskSteps struct {
|
||||
LockedByUserId string
|
||||
LockedByUserSession string // user session is needed to prevent sending the unlocking message to the user who are writing
|
||||
|
@ -89,3 +88,11 @@ type LockedGroupTaskSteps struct {
|
|||
Step uint8
|
||||
LockedAt time.Time
|
||||
}
|
||||
|
||||
// used for ui when a user types into input fields to sync to other users and show them this when opening the group task view
|
||||
type GroupTaskStepsInput struct {
|
||||
GroupTaskId string
|
||||
Step string
|
||||
ParameterName string
|
||||
Value string
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ func AddScanner(c *fiber.Ctx) error {
|
|||
}
|
||||
|
||||
if err := utils.ValidateStruct(body); err != nil {
|
||||
log.Error().Msgf("Failed to validate body, err: %s", err)
|
||||
log.Error().Msgf("Failed to validate body, err: %v", err)
|
||||
return c.SendStatus(fiber.StatusBadRequest)
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ func RunHub() {
|
|||
continue
|
||||
}
|
||||
|
||||
log.Info().Msgf("Received message: %s", receivedMessage, receivedMessage.Cmd)
|
||||
log.Info().Msgf("Received message: %v %v", receivedMessage, receivedMessage.Cmd)
|
||||
|
||||
switch receivedMessage.Cmd {
|
||||
case utils.ReceivedCmdStartGroupTasks:
|
||||
|
@ -178,10 +178,14 @@ func RunHub() {
|
|||
Cmd: utils.SentCmdUpdateGroupTaskStepUserInputValue,
|
||||
Body: receivedMessage.Body,
|
||||
})
|
||||
|
||||
cache.ExtendLockedGroupTaskStepLockedAtTime(structs.LockedGroupTaskSteps{
|
||||
GroupTaskId: receivedMessage.Body["groupTaskId"].(string),
|
||||
})
|
||||
break
|
||||
|
||||
default:
|
||||
log.Error().Msgf("Received unknown message: %s", receivedMessage)
|
||||
log.Error().Msgf("Received unknown message: %v", receivedMessage)
|
||||
break
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ func WebSocketServer(app *fiber.App) {
|
|||
if messageType == websocket.TextMessage {
|
||||
broadcast <- structs.SocketMessage{Conn: c, Msg: msg}
|
||||
} else {
|
||||
log.Error().Msgf("websocket message received of type %s", messageType)
|
||||
log.Error().Msgf("websocket message received of type %v", messageType)
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
|
Loading…
Reference in New Issue