mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
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).
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package cassandra
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hanzoai/tasks/common/log"
|
|
"github.com/hanzoai/tasks/common/log/tag"
|
|
"github.com/hanzoai/tasks/common/persistence/nosql/nosqlplugin/cassandra/gocql"
|
|
)
|
|
|
|
const cassandraPersistenceName = "cassandra"
|
|
|
|
// CreateCassandraKeyspace creates the keyspace using this session for given replica count
|
|
func CreateCassandraKeyspace(s gocql.Session, keyspace string, replicas int, overwrite bool, logger log.Logger) (err error) {
|
|
// if overwrite flag is set, drop the keyspace and create a new one
|
|
if overwrite {
|
|
err = DropCassandraKeyspace(s, keyspace, logger)
|
|
if err != nil {
|
|
logger.Error("drop keyspace error", tag.Error(err))
|
|
return
|
|
}
|
|
}
|
|
err = s.Query(fmt.Sprintf(`CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {
|
|
'class' : 'SimpleStrategy', 'replication_factor' : %d}`, keyspace, replicas)).Exec()
|
|
if err != nil {
|
|
logger.Error("create keyspace error", tag.Error(err))
|
|
return
|
|
}
|
|
logger.Debug("created keyspace", tag.Value(keyspace))
|
|
|
|
return
|
|
}
|
|
|
|
// DropCassandraKeyspace drops the given keyspace, if it exists
|
|
func DropCassandraKeyspace(s gocql.Session, keyspace string, logger log.Logger) (err error) {
|
|
err = s.Query(fmt.Sprintf("DROP KEYSPACE IF EXISTS %s", keyspace)).Exec()
|
|
if err != nil {
|
|
logger.Error("drop keyspace error", tag.Error(err))
|
|
return
|
|
}
|
|
logger.Debug("dropped keyspace", tag.Value(keyspace))
|
|
return
|
|
}
|