Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
refactor(BUX-411): Tasker to TaskEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-4chain committed Dec 20, 2023
1 parent 04e02c9 commit 12a41f8
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bux_suite_mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ func (tm *taskManagerMockBase) CronJobsInit(cronJobsMap taskmanager.CronJobs) er
// Sets custom task manager only for testing
func withTaskManagerMockup() ClientOps {
return func(c *clientOptions) {
c.taskManager.Tasker = &taskManagerMockBase{}
c.taskManager.TaskEngine = &taskManagerMockBase{}
}
}
16 changes: 8 additions & 8 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ type (

// taskManagerOptions holds the configuration for taskmanager
taskManagerOptions struct {
taskmanager.Tasker // Client for TaskManager
cronJobs taskmanager.CronJobs // List of cron jobs
options []taskmanager.TaskManagerOptions // List of options
cronCustomPeriods map[string]time.Duration // will override the default period of cronJob
taskmanager.TaskEngine // Client for TaskManager
cronJobs taskmanager.CronJobs // List of cron jobs
options []taskmanager.TaskManagerOptions // List of options
cronCustomPeriods map[string]time.Duration // will override the default period of cronJob
}
)

Expand Down Expand Up @@ -303,7 +303,7 @@ func (c *Client) Close(ctx context.Context) error {
if err := tm.Close(ctx); err != nil {
return err
}
c.options.taskManager.Tasker = nil
c.options.taskManager.TaskEngine = nil
}
return nil
}
Expand Down Expand Up @@ -440,9 +440,9 @@ func (c *Client) SetNotificationsClient(client notifications.ClientInterface) {
}

// Taskmanager will return the Taskmanager if it exists
func (c *Client) Taskmanager() taskmanager.Tasker {
if c.options.taskManager != nil && c.options.taskManager.Tasker != nil {
return c.options.taskManager.Tasker
func (c *Client) Taskmanager() taskmanager.TaskEngine {
if c.options.taskManager != nil && c.options.taskManager.TaskEngine != nil {
return c.options.taskManager.TaskEngine
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions client_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ func (c *Client) loadPaymailClient() (err error) {
// loadTaskmanager will load the TaskManager and start the TaskManager client
func (c *Client) loadTaskmanager(ctx context.Context) (err error) {
// Load if a custom interface was NOT provided
if c.options.taskManager.Tasker == nil {
c.options.taskManager.Tasker, err = taskmanager.NewTaskManager(
if c.options.taskManager.TaskEngine == nil {
c.options.taskManager.TaskEngine, err = taskmanager.NewTaskManager(
ctx, c.options.taskManager.options...,
)
}
Expand Down
2 changes: 1 addition & 1 deletion client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func defaultClientOptions() *clientOptions {

// Blank TaskManager config
taskManager: &taskManagerOptions{
Tasker: nil,
TaskEngine: nil,
cronCustomPeriods: map[string]time.Duration{},
},

Expand Down
2 changes: 1 addition & 1 deletion interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type ClientService interface {
Logger() *zerolog.Logger
Notifications() notifications.ClientInterface
PaymailClient() paymail.ClientInterface
Taskmanager() taskmanager.Tasker
Taskmanager() taskmanager.TaskEngine
}

// DestinationService is the destination actions
Expand Down
4 changes: 2 additions & 2 deletions taskmanager/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
taskq "github.com/vmihailenco/taskq/v3"
)

// Tasker is the taskmanager client interface
type Tasker interface {
// TaskEngine is the taskmanager client interface
type TaskEngine interface {
RegisterTask(name string, handler interface{}) error
ResetCron()
RunTask(ctx context.Context, options *TaskRunOptions) error
Expand Down
4 changes: 2 additions & 2 deletions taskmanager/taskmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

type (

// TaskManager implements the Tasker interface
// TaskManager implements the TaskEngine interface
TaskManager struct {
options *options
}
Expand All @@ -38,7 +38,7 @@ type (
// NewTaskManager creates a new client for all TaskManager functionality
// If no options are given, it will use local memory for the queue.
// ctx may contain a NewRelic txn (or one will be created)
func NewTaskManager(ctx context.Context, opts ...TaskManagerOptions) (Tasker, error) {
func NewTaskManager(ctx context.Context, opts ...TaskManagerOptions) (TaskEngine, error) {
// Create a new tm with defaults
tm := &TaskManager{options: &options{
newRelicEnabled: false,
Expand Down

0 comments on commit 12a41f8

Please sign in to comment.