tâches planifiées : prompts cron persistés, outil scheduler, conversations liées aux tâches, rattrapage des exécutions manquées au redémarrage (go-cron MissedRunOnce)
This commit is contained in:
1 parent
bedb6c98e7
commit
058370830f
71 files changed
+1627
-100
No files matched your search
@@ -0,0 +1,85 @@
|
||||
package turso
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
|
||||
"trankilou.fr/lassistanoque/backend/internal/adapter/database/orm"
|
||||
"trankilou.fr/lassistanoque/backend/internal/domain"
|
||||
)
|
||||
|
||||
type TursoTaskRepository struct {
|
||||
db *sql.DB
|
||||
taskTable orm.Table[domain.Task]
|
||||
}
|
||||
|
||||
func NewTursoTaskRepository(db *sql.DB) *TursoTaskRepository {
|
||||
dialect := orm.NewSqliteDialect()
|
||||
taskTable, err := orm.NewTable[domain.Task](db, dialect, "tasks")
|
||||
if err != nil {
|
||||
log.Fatalf("error creating task table")
|
||||
}
|
||||
|
||||
return &TursoTaskRepository{
|
||||
db: db,
|
||||
taskTable: taskTable,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *TursoTaskRepository) ListTasks(userID string, teamID string) ([]*domain.Task, error) {
|
||||
return r.taskTable.Select(
|
||||
orm.WithWhere(
|
||||
"team_id=$1 and team_id in (select team_id from user_teams where user_id=$2)",
|
||||
teamID,
|
||||
userID,
|
||||
),
|
||||
orm.WithOrder("_date_created desc"),
|
||||
)
|
||||
}
|
||||
|
||||
func (r *TursoTaskRepository) ListActiveTasks() ([]*domain.Task, error) {
|
||||
return r.taskTable.Select(
|
||||
orm.WithWhere("status=$1", domain.TaskStatusActive),
|
||||
)
|
||||
}
|
||||
|
||||
func (r *TursoTaskRepository) GetTaskByID(userID string, teamID string, id string) (*domain.Task, error) {
|
||||
return r.taskTable.SelectOne(
|
||||
"id=$1 and team_id=$2 and team_id in (select team_id from user_teams where user_id=$3)",
|
||||
id,
|
||||
teamID,
|
||||
userID,
|
||||
)
|
||||
}
|
||||
|
||||
func (r *TursoTaskRepository) CreateTask(task *domain.Task) (*domain.Task, error) {
|
||||
return r.taskTable.Insert(task)
|
||||
}
|
||||
|
||||
func (r *TursoTaskRepository) UpdateTask(task *domain.Task) (*domain.Task, error) {
|
||||
return r.taskTable.Update(task)
|
||||
}
|
||||
|
||||
func (r *TursoTaskRepository) DeleteTask(userID string, teamID string, id string) error {
|
||||
return r.taskTable.DeleteWhere(
|
||||
"id=$1 and team_id=$2 and team_id in (select team_id from user_teams where user_id=$3)",
|
||||
id,
|
||||
teamID,
|
||||
userID,
|
||||
)
|
||||
}
|
||||
|
||||
// FirstUserOfTeam retourne le premier utilisateur d'une équipe. Les tâches
|
||||
// planifiées ne portent pas d'utilisateur : c'est lui qui porte la conversation
|
||||
// générée lors de l'exécution.
|
||||
func (r *TursoTaskRepository) FirstUserOfTeam(teamID string) (string, error) {
|
||||
var userID string
|
||||
err := r.db.QueryRow(
|
||||
"select user_id from user_teams where team_id=$1 order by _date_created asc limit 1",
|
||||
teamID,
|
||||
).Scan(&userID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return userID, nil
|
||||
}
|
||||
Reference in new issue
Block a user