Files
tasks/common/persistence/sql/sqlplugin/postgresql/task_v1.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
Full module path rebrand from Temporal to Hanzo Tasks:
- go.mod module: github.com/hanzoai/tasks
- All internal Go imports updated (1906 files)
- cmd/server renamed to cmd/tasksd
- Binary name: tasksd (was temporal-server)
- Docker images: hanzoai/tasks (was temporalio/server)
- README rewritten with Hanzo Tasks branding
- LLM.md created with integration notes
- Makefile, goreleaser, CI workflows updated
- go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos)

Fork of Temporal.io (MIT license).
2026-03-19 10:36:40 -07:00

92 lines
2.3 KiB
Go

package postgresql
import (
"context"
"database/sql"
"go.temporal.io/api/serviceerror"
"github.com/hanzoai/tasks/common/persistence/sql/sqlplugin"
)
const (
getTaskMinMaxQry = `SELECT task_id, data, data_encoding ` +
`FROM tasks ` +
`WHERE range_hash = $1 AND task_queue_id=$2 AND task_id >= $3 AND task_id < $4 ` +
`ORDER BY task_id LIMIT $5`
getTaskMinQry = `SELECT task_id, data, data_encoding ` +
`FROM tasks ` +
`WHERE range_hash = $1 AND task_queue_id = $2 AND task_id >= $3 ORDER BY task_id LIMIT $4`
createTaskQry = `INSERT INTO ` +
`tasks(range_hash, task_queue_id, task_id, data, data_encoding) ` +
`VALUES(:range_hash, :task_queue_id, :task_id, :data, :data_encoding)`
rangeDeleteTaskQry = `DELETE FROM tasks ` +
`WHERE range_hash = $1 AND task_queue_id = $2 AND task_id IN (SELECT task_id FROM
tasks WHERE range_hash = $1 AND task_queue_id = $2 AND task_id < $3 ` +
`ORDER BY task_queue_id,task_id LIMIT $4 )`
)
// InsertIntoTasks inserts one or more rows into tasks table
func (pdb *db) InsertIntoTasks(
ctx context.Context,
rows []sqlplugin.TasksRow,
) (sql.Result, error) {
return pdb.NamedExecContext(ctx,
createTaskQry,
rows,
)
}
// SelectFromTasks reads one or more rows from tasks table
func (pdb *db) SelectFromTasks(
ctx context.Context,
filter sqlplugin.TasksFilter,
) ([]sqlplugin.TasksRow, error) {
var err error
var rows []sqlplugin.TasksRow
switch {
case filter.ExclusiveMaxTaskID != nil:
err = pdb.SelectContext(ctx,
&rows,
getTaskMinMaxQry,
filter.RangeHash,
filter.TaskQueueID,
*filter.InclusiveMinTaskID,
*filter.ExclusiveMaxTaskID,
*filter.PageSize,
)
default:
err = pdb.SelectContext(ctx,
&rows,
getTaskMinQry,
filter.RangeHash,
filter.TaskQueueID,
*filter.InclusiveMinTaskID,
*filter.PageSize,
)
}
return rows, err
}
// DeleteFromTasks deletes multiple rows from tasks table
func (pdb *db) DeleteFromTasks(
ctx context.Context,
filter sqlplugin.TasksFilter,
) (sql.Result, error) {
if filter.ExclusiveMaxTaskID == nil {
return nil, serviceerror.NewInternal("missing ExclusiveMaxTaskID parameter")
}
if filter.Limit == nil || *filter.Limit == 0 {
return nil, serviceerror.NewInternal("missing limit parameter")
}
return pdb.ExecContext(ctx,
rangeDeleteTaskQry,
filter.RangeHash,
filter.TaskQueueID,
*filter.ExclusiveMaxTaskID,
*filter.Limit,
)
}