Skip to content

Commit 476774c

Browse files
committed
Move PubSub RecordWriter to Library and Make Public
1 parent 7e0c81b commit 476774c

2 files changed

Lines changed: 31 additions & 25 deletions

File tree

cmd/batchforce/cmd/publish.go

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package cmd
22

33
import (
4-
"context"
54
"fmt"
65
"os"
76

87
force "github.com/ForceCLI/force/lib"
9-
"github.com/ForceCLI/force/lib/pubsub"
108
. "github.com/octoberswimmer/batchforce"
119

12-
log "github.com/sirupsen/logrus"
1310
"github.com/spf13/cobra"
1411
)
1512

@@ -21,7 +18,7 @@ $ batchforce publish --query "SELECT Id, Name FROM Account WHERE NOT Name LIKE '
2118
$ batchforce publish --file accounts.csv /event/Account_Change__e '{Id: record.Id, Name: record.Name + " Copy"}'
2219
`,
2320
DisableFlagsInUseLine: false,
24-
Args: cobra.ExactValidArgs(2),
21+
Args: cobra.MatchAll(cobra.ExactArgs(2), cobra.OnlyValidArgs),
2522
RunE: func(cmd *cobra.Command, args []string) error {
2623
execution, err := getExecution(cmd, args)
2724
if err != nil {
@@ -33,7 +30,7 @@ $ batchforce publish --file accounts.csv /event/Account_Change__e '{Id: record.I
3330
if !ok {
3431
return fmt.Errorf("cannot use session as *force.Force for publish")
3532
}
36-
execution.RecordWriter = publishTo(fs, channel)
33+
execution.RecordWriter = PublishTo(fs, channel)
3734
errors := execution.RunContext(cmd.Context())
3835
if errors.NumberBatchesFailed() > 0 {
3936
fmt.Println(errors.NumberBatchesFailed(), "batch failures")
@@ -46,23 +43,3 @@ $ batchforce publish --file accounts.csv /event/Account_Change__e '{Id: record.I
4643
return nil
4744
},
4845
}
49-
50-
type uncheckableResult struct {
51-
}
52-
53-
func (u uncheckableResult) NumberBatchesFailed() int {
54-
return 0
55-
}
56-
57-
func (u uncheckableResult) NumberRecordsFailed() int {
58-
return 0
59-
}
60-
61-
func publishTo(session *force.Force, channel string) RecordWriter {
62-
return func(ctx context.Context, records <-chan force.ForceRecord) (Result, error) {
63-
force.Log = log.StandardLogger()
64-
res := uncheckableResult{}
65-
err := pubsub.PublishMessagesWithContext(ctx, session, channel, records)
66-
return res, err
67-
}
68-
}

pubsub.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package batch
2+
3+
import (
4+
"context"
5+
6+
force "github.com/ForceCLI/force/lib"
7+
"github.com/ForceCLI/force/lib/pubsub"
8+
log "github.com/sirupsen/logrus"
9+
)
10+
11+
type uncheckableResult struct {
12+
}
13+
14+
func (u uncheckableResult) NumberBatchesFailed() int {
15+
return 0
16+
}
17+
18+
func (u uncheckableResult) NumberRecordsFailed() int {
19+
return 0
20+
}
21+
22+
func PublishTo(session *force.Force, channel string) RecordWriter {
23+
return func(ctx context.Context, records <-chan force.ForceRecord) (Result, error) {
24+
force.Log = log.StandardLogger()
25+
res := uncheckableResult{}
26+
err := pubsub.PublishMessagesWithContext(ctx, session, channel, records)
27+
return res, err
28+
}
29+
}

0 commit comments

Comments
 (0)