lp: task test better
This commit is contained in:
parent
ec43903ad6
commit
deae3ad05f
@ -6,6 +6,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
@ -74,17 +75,13 @@ var wdPostTaskCmd = &cli.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("cannot get miner id %w", err)
|
return xerrors.Errorf("cannot get miner id %w", err)
|
||||||
}
|
}
|
||||||
did, err := deps.db.BeginTransaction(ctx, func(tx *harmonydb.Tx) (commit bool, err error) {
|
var id int64
|
||||||
_, err = tx.Exec(`INSERT INTO harmony_task (name, posted_time, added_by) VALUES ('WdPost', CURRENT_TIMESTAMP, 123)`)
|
_, err = deps.db.BeginTransaction(ctx, func(tx *harmonydb.Tx) (commit bool, err error) {
|
||||||
|
err = tx.QueryRow(`INSERT INTO harmony_task (name, posted_time, added_by) VALUES ('WdPost', CURRENT_TIMESTAMP, 123) RETURNING id`).Scan(&id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("inserting harmony_task: ", err)
|
log.Error("inserting harmony_task: ", err)
|
||||||
return false, xerrors.Errorf("inserting harmony_task: %w", err)
|
return false, xerrors.Errorf("inserting harmony_task: %w", err)
|
||||||
}
|
}
|
||||||
var id int64
|
|
||||||
if err = tx.QueryRow(`SELECT id FROM harmony_task ORDER BY update_time DESC LIMIT 1`).Scan(&id); err != nil {
|
|
||||||
log.Error("getting inserted id: ", err)
|
|
||||||
return false, xerrors.Errorf("getting inserted id: %w", err)
|
|
||||||
}
|
|
||||||
_, err = tx.Exec(`INSERT INTO wdpost_partition_tasks
|
_, err = tx.Exec(`INSERT INTO wdpost_partition_tasks
|
||||||
(task_id, sp_id, proving_period_start, deadline_index, partition_index) VALUES ($1, $2, $3, $4, $5)`,
|
(task_id, sp_id, proving_period_start, deadline_index, partition_index) VALUES ($1, $2, $3, $4, $5)`,
|
||||||
id, maddr, ht, cctx.Uint64("deadline"), 0)
|
id, maddr, ht, cctx.Uint64("deadline"), 0)
|
||||||
@ -101,8 +98,17 @@ var wdPostTaskCmd = &cli.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("writing SQL transaction: %w", err)
|
return xerrors.Errorf("writing SQL transaction: %w", err)
|
||||||
}
|
}
|
||||||
log.Infof("Inserted task %v", did)
|
fmt.Printf("Inserted task %v. Waiting for success ", id)
|
||||||
log.Infof("Check your lotus-provider logs for more details.")
|
var result string
|
||||||
|
for {
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
deps.db.QueryRow(ctx, `SELECT result FROM harmony_test WHERE task_id=$1`, id).Scan(&result)
|
||||||
|
if result != "" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
fmt.Print(".")
|
||||||
|
}
|
||||||
|
log.Infof("Result:", result)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -2,5 +2,6 @@ CREATE TABLE harmony_test (
|
|||||||
task_id bigint
|
task_id bigint
|
||||||
constraint harmony_test_pk
|
constraint harmony_test_pk
|
||||||
primary key,
|
primary key,
|
||||||
options text
|
options text,
|
||||||
|
result text
|
||||||
);
|
);
|
@ -2,6 +2,7 @@ package lpmessage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
@ -149,15 +150,22 @@ func (s *Sender) Send(ctx context.Context, msg *types.Message, mss *api.MessageS
|
|||||||
}
|
}
|
||||||
|
|
||||||
if noSend {
|
if noSend {
|
||||||
log.Errorw("SKIPPED SENDING MESSAGE PER ENVIRONMENT VARIABLE - NOT PRODUCTION SAFE",
|
|
||||||
"from_key", fromA.String(),
|
data, err := json.MarshalIndent(map[string]any{
|
||||||
"nonce", msg.Nonce,
|
"from_key": fromA.String(),
|
||||||
"to_addr", msg.To.String(),
|
"nonce": msg.Nonce,
|
||||||
"signed_data", data,
|
"to_addr": msg.To.String(),
|
||||||
"signed_json", string(jsonBytes),
|
"signed_data": data,
|
||||||
"signed_cid", sigMsg.Cid(),
|
"signed_json": string(jsonBytes),
|
||||||
"send_reason", reason,
|
"signed_cid": sigMsg.Cid(),
|
||||||
)
|
"send_reason": reason,
|
||||||
|
}, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return false, xerrors.Errorf("marshaling message: %w", err)
|
||||||
|
}
|
||||||
|
id := ctx.Value(CtxTaskID)
|
||||||
|
tx.Exec(`UPDATE harmony_test SET result=$1 WHERE task_id=$2`, string(data), id)
|
||||||
|
log.Infof("SKIPPED sending test message to chain. Query harmony_test WHERE task_id= %v", id)
|
||||||
return true, nil // nothing committed
|
return true, nil // nothing committed
|
||||||
}
|
}
|
||||||
// write to db
|
// write to db
|
||||||
|
Loading…
Reference in New Issue
Block a user