Restructure the monorepo into clear top-level directories: - backend/: Go module root (cmd, internal, pkg, configs, migrations, docs/swagger, scripts, tests, go.mod, Makefile, .air.toml) - deploy/: Docker (Dockerfile, docker-compose*), quickstart, fluentd - docs/: project documentation + reports/ (moved from repo root) - AGENTS.md: new AI coding-agent guide at repo root Update all references to the new layout: - Dockerfile: COPY backend/go.mod, COPY backend/ (context = repo root) - docker-compose files: context ../.., dockerfile deploy/docker/Dockerfile, env_file ../../.env, volume mounts ../../backend:/app - deploy/quickstart/compose.yaml: dockerfile deploy/docker/Dockerfile - CI: working-directory: backend for go commands, file deploy/docker/Dockerfile, coverage path backend/coverage.out, health_check backend/scripts/ - backend/Makefile: docker target uses -f ../deploy/docker/Dockerfile ../ - README: architecture tree, quickstart, config paths updated Move root stray scripts (rename_models.*, run_m11_tests.sh, verify_build.sh, gorm_bool_main.go) to backend/scripts/legacy/. All moves via git mv to preserve history. Build, vet, SQLite tests, and docker compose config verified.
62 lines
1.9 KiB
Go
62 lines
1.9 KiB
Go
package automation
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"sync"
|
|
|
|
"github.com/gochat/gochat/internal/model"
|
|
"github.com/gochat/gochat/internal/worker"
|
|
)
|
|
|
|
type macroExecutionJob struct {
|
|
AccountID uint `json:"account_id"`
|
|
MacroID uint `json:"macro_id"`
|
|
ConversationIDs []uint `json:"conversation_ids"`
|
|
UserID uint `json:"user_id"`
|
|
}
|
|
|
|
var macroExecutionRegistrations sync.Map
|
|
|
|
// RegisterMacroExecutionJobs wires Chatwoot's MacrosExecutionJob equivalent.
|
|
// The job resolves account-scoped conversation display IDs at perform time.
|
|
func RegisterMacroExecutionJobs(wp *worker.WorkerPool, db DBProvider) {
|
|
registerMacroExecutionJobs(wp, db, nil)
|
|
}
|
|
|
|
func RegisterMacroExecutionSearchIndexer(wp *worker.WorkerPool, db DBProvider, indexer ActionSearchIndexer) {
|
|
registerMacroExecutionJobs(wp, db, indexer)
|
|
}
|
|
|
|
func registerMacroExecutionJobs(wp *worker.WorkerPool, db DBProvider, indexer ActionSearchIndexer) {
|
|
if wp == nil || db == nil {
|
|
return
|
|
}
|
|
runner := ¯oExecutionJobRunner{db: db, worker: wp, searchIndexer: indexer}
|
|
actual, loaded := macroExecutionRegistrations.LoadOrStore(wp, runner)
|
|
if loaded {
|
|
if indexer != nil {
|
|
actual.(*macroExecutionJobRunner).searchIndexer = indexer
|
|
}
|
|
return
|
|
}
|
|
wp.Register(TaskTypeMacroExecution, runner.perform)
|
|
}
|
|
|
|
type macroExecutionJobRunner struct {
|
|
db DBProvider
|
|
worker *worker.WorkerPool
|
|
searchIndexer ActionSearchIndexer
|
|
}
|
|
|
|
func (r *macroExecutionJobRunner) perform(ctx context.Context, job *model.BackgroundJob) error {
|
|
var payload macroExecutionJob
|
|
if err := json.Unmarshal(job.Payload, &payload); err != nil {
|
|
return fmt.Errorf("unmarshal macro execution job: %w", err)
|
|
}
|
|
svc := NewMacroServiceWithWorker(r.db, r.worker)
|
|
svc.SetSearchIndexer(r.searchIndexer)
|
|
return svc.executeForDisplayIDsNow(ctx, payload.AccountID, payload.MacroID, payload.ConversationIDs, payload.UserID)
|
|
}
|