Documentation
¶
Index ¶
- Constants
- Variables
- func CleanupTestFile(t *task) error
- func CreateTestCSVFile(t *testing.T, filename string, content string) string
- func CreateTestConfig() *config.AppConfig
- func CreateTestConfigWithTasks(tasks []struct{ ... }) *config.AppConfig
- func CreateTestTask(id TaskID, commandID TaskCommandID, instanceID TaskInstanceID) *task
- func CreateTestTempDir(t *testing.T) string
- func LoadTestData(t *testing.T, filename string) []byte
- func LoadTestDataAsString(t *testing.T, filename string) string
- type CommandExecutor
- type CommandProcess
- type DefaultCommandExecutor
- type Fetcher
- type HTTPFetcher
- type MockHTTPFetcher
- func (m *MockHTTPFetcher) Do(req *http.Request) (*http.Response, error)
- func (m *MockHTTPFetcher) Get(url string) (*http.Response, error)
- func (m *MockHTTPFetcher) GetRequestedURLs() []string
- func (m *MockHTTPFetcher) Reset()
- func (m *MockHTTPFetcher) SetError(url string, err error)
- func (m *MockHTTPFetcher) SetResponse(url string, response []byte)
- type MockTaskNotificationSender
- func (m *MockTaskNotificationSender) GetNotifyToDefaultCallCount() int
- func (m *MockTaskNotificationSender) GetNotifyWithTaskContextCallCount() int
- func (m *MockTaskNotificationSender) GetSupportHTMLMessageCallCount() int
- func (m *MockTaskNotificationSender) NotifyToDefault(message string) bool
- func (m *MockTaskNotificationSender) NotifyWithTaskContext(notifierID string, message string, taskCtx TaskContext) bool
- func (m *MockTaskNotificationSender) Reset()
- func (m *MockTaskNotificationSender) SupportHTMLMessage(notifierID string) bool
- type NotifyWithTaskContextCall
- type RetryFetcher
- type TaskCanceler
- type TaskCommandID
- type TaskContext
- type TaskExecutor
- type TaskID
- type TaskInstanceID
- type TaskNotificationSender
- type TaskRunBy
- type TaskRunner
- type TaskService
- func (s *TaskService) Run(serviceStopCtx context.Context, serviceStopWaiter *sync.WaitGroup) error
- func (s *TaskService) SetTaskNotificationSender(taskNotificiationSender TaskNotificationSender)
- func (s *TaskService) TaskCancel(taskInstanceID TaskInstanceID) (succeeded bool)
- func (s *TaskService) TaskRun(taskID TaskID, taskCommandID TaskCommandID, notifierID string, ...) (succeeded bool)
- func (s *TaskService) TaskRunWithContext(taskID TaskID, taskCommandID TaskCommandID, taskCtx TaskContext, ...) (succeeded bool)
Constants ¶
const ( TaskCtxKeyTitle taskContextKey = "Title" TaskCtxKeyErrorOccurred taskContextKey = "ErrorOccurred" TaskCtxKeyTaskID taskContextKey = "Task.TaskID" TaskCtxKeyTaskCommandID taskContextKey = "Task.TaskCommandID" TaskCtxKeyTaskInstanceID taskContextKey = "Task.TaskInstanceID" TaskCtxKeyElapsedTimeAfterRun taskContextKey = "Task.ElapsedTimeAfterRun" )
const ( // TaskID TidJdc TaskID = "JDC" // 전남디지털역량교육(http://전남디지털역량.com/) // TaskCommandID TcidJdcWatchNewOnlineEducation TaskCommandID = "WatchNewOnlineEducation" // 신규 비대면 온라인 특별/정규교육 확인 )
const ( // TaskID TidJyiu TaskID = "JYIU" // 전남여수산학융합원(https://www.jyiu.or.kr/) // TaskCommandID TcidJyiuWatchNewNotice TaskCommandID = "WatchNewNotice" // 전남여수산학융합원 공지사항 새글 확인 TcidJyiuWatchNewEducation TaskCommandID = "WatchNewEducation" // 전남여수산학융합원 신규 교육프로그램 확인 )
const ( TidKurly TaskID = "KURLY" // 마켓컬리 TcidKurlyWatchProductPrice TaskCommandID = "WatchProductPrice" // 마켓컬리 가격 확인 )
const ( WatchProductColumnNo watchProductColumn = iota // 상품 코드 컬럼 WatchProductColumnName // 상품 이름 컬럼 WatchProductColumnWatchStatus // 감시 대상인지에 대한 활성/비활성 컬럼 )
감시할 상품 목록의 헤더 컬럼
const ( WatchStatusEnabled = "1" WatchStatusDisabled = "0" )
감시 대상인지에 대한 활성/비활성 컬럼의 값
const ( // TaskID TidLotto TaskID = "LOTTO" // TaskCommandID TcidLottoPrediction TaskCommandID = "Prediction" // 로또 번호 예측 )
const ( TidNaver TaskID = "NAVER" // 네이버 TcidNaverWatchNewPerformances TaskCommandID = "WatchNewPerformances" // 네이버 신규 공연정보 확인 )
Variables ¶
Functions ¶
func CleanupTestFile ¶ added in v1.0.0
func CleanupTestFile(t *task) error
CleanupTestFile 테스트 파일을 정리합니다.
func CreateTestCSVFile ¶ added in v1.0.0
CreateTestCSVFile 테스트용 CSV 파일을 생성합니다.
func CreateTestConfig ¶ added in v1.0.0
CreateTestConfig 테스트용 AppConfig를 생성합니다.
func CreateTestConfigWithTasks ¶ added in v1.0.0
func CreateTestConfigWithTasks(tasks []struct {
ID string
Title string
Commands []struct {
ID string
Title string
Runnable bool
TimeSpec string
DefaultNotifierID string
}
}) *config.AppConfig
CreateTestConfigWithTasks Task가 포함된 테스트용 AppConfig를 생성합니다.
func CreateTestTask ¶ added in v1.0.0
func CreateTestTask(id TaskID, commandID TaskCommandID, instanceID TaskInstanceID) *task
CreateTestTask 테스트용 Task 인스턴스를 생성합니다.
func CreateTestTempDir ¶ added in v1.0.0
CreateTestTempDir 테스트용 임시 디렉토리를 생성합니다. 테스트 종료 시 자동으로 정리됩니다.
func LoadTestData ¶ added in v1.0.0
LoadTestData testdata 디렉토리에서 파일을 로드합니다.
Types ¶
type CommandExecutor ¶ added in v1.0.0
type CommandExecutor interface {
StartCommand(name string, args ...string) (CommandProcess, error)
}
CommandExecutor 외부 명령 실행을 추상화하는 인터페이스
type CommandProcess ¶ added in v1.0.0
CommandProcess 실행 중인 프로세스를 추상화하는 인터페이스
type DefaultCommandExecutor ¶ added in v1.0.0
type DefaultCommandExecutor struct{}
DefaultCommandExecutor 기본 명령 실행기 (os/exec 사용)
func (*DefaultCommandExecutor) StartCommand ¶ added in v1.0.0
func (e *DefaultCommandExecutor) StartCommand(name string, args ...string) (CommandProcess, error)
type Fetcher ¶ added in v1.0.0
type Fetcher interface {
Get(url string) (*http.Response, error)
Do(req *http.Request) (*http.Response, error)
}
Fetcher interface for network requests
type HTTPFetcher ¶ added in v1.0.0
type HTTPFetcher struct{}
HTTPFetcher implementation using http.DefaultClient
type MockHTTPFetcher ¶ added in v1.0.0
type MockHTTPFetcher struct {
// URL별 응답 설정
Responses map[string][]byte // URL -> 응답 바이트
Errors map[string]error // URL -> 에러
// 호출 기록
RequestedURLs []string
// contains filtered or unexported fields
}
MockHTTPFetcher HTTP 요청을 Mock하는 구조체입니다.
func NewMockHTTPFetcher ¶ added in v1.0.0
func NewMockHTTPFetcher() *MockHTTPFetcher
NewMockHTTPFetcher 새로운 MockHTTPFetcher를 생성합니다.
func (*MockHTTPFetcher) Get ¶ added in v1.0.0
func (m *MockHTTPFetcher) Get(url string) (*http.Response, error)
Get Mock HTTP Get 요청을 수행합니다.
func (*MockHTTPFetcher) GetRequestedURLs ¶ added in v1.0.0
func (m *MockHTTPFetcher) GetRequestedURLs() []string
GetRequestedURLs 요청된 URL 목록을 반환합니다.
func (*MockHTTPFetcher) Reset ¶ added in v1.0.0
func (m *MockHTTPFetcher) Reset()
Reset 모든 설정과 기록을 초기화합니다.
func (*MockHTTPFetcher) SetError ¶ added in v1.0.0
func (m *MockHTTPFetcher) SetError(url string, err error)
SetError 특정 URL에 대한 에러를 설정합니다.
func (*MockHTTPFetcher) SetResponse ¶ added in v1.0.0
func (m *MockHTTPFetcher) SetResponse(url string, response []byte)
SetResponse 특정 URL에 대한 응답을 설정합니다.
type MockTaskNotificationSender ¶ added in v1.0.0
type MockTaskNotificationSender struct {
// 호출 기록
NotifyToDefaultCalls []string
NotifyWithTaskContextCalls []NotifyWithTaskContextCall
SupportHTMLMessageCalls []string
SupportHTMLMessageReturnValue bool
// contains filtered or unexported fields
}
MockTaskNotificationSender 테스트용 TaskNotificationSender 구현체입니다.
func NewMockTaskNotificationSender ¶ added in v1.0.0
func NewMockTaskNotificationSender() *MockTaskNotificationSender
NewMockTaskNotificationSender 새로운 Mock 객체를 생성합니다.
func (*MockTaskNotificationSender) GetNotifyToDefaultCallCount ¶ added in v1.0.0
func (m *MockTaskNotificationSender) GetNotifyToDefaultCallCount() int
GetNotifyToDefaultCallCount NotifyToDefault 호출 횟수를 반환합니다.
func (*MockTaskNotificationSender) GetNotifyWithTaskContextCallCount ¶ added in v1.0.0
func (m *MockTaskNotificationSender) GetNotifyWithTaskContextCallCount() int
GetNotifyWithTaskContextCallCount NotifyWithTaskContext 호출 횟수를 반환합니다.
func (*MockTaskNotificationSender) GetSupportHTMLMessageCallCount ¶ added in v1.0.0
func (m *MockTaskNotificationSender) GetSupportHTMLMessageCallCount() int
GetSupportHTMLMessageCallCount SupportHTMLMessage 호출 횟수를 반환합니다.
func (*MockTaskNotificationSender) NotifyToDefault ¶ added in v1.0.0
func (m *MockTaskNotificationSender) NotifyToDefault(message string) bool
NotifyToDefault 기본 알림을 전송합니다 (Mock).
func (*MockTaskNotificationSender) NotifyWithTaskContext ¶ added in v1.0.0
func (m *MockTaskNotificationSender) NotifyWithTaskContext(notifierID string, message string, taskCtx TaskContext) bool
NotifyWithTaskContext Task 컨텍스트와 함께 알림을 전송합니다 (Mock).
func (*MockTaskNotificationSender) Reset ¶ added in v1.0.0
func (m *MockTaskNotificationSender) Reset()
Reset 모든 호출 기록을 초기화합니다.
func (*MockTaskNotificationSender) SupportHTMLMessage ¶ added in v1.0.0
func (m *MockTaskNotificationSender) SupportHTMLMessage(notifierID string) bool
SupportHTMLMessage HTML 메시지 지원 여부를 반환합니다 (Mock).
type NotifyWithTaskContextCall ¶ added in v1.0.0
type NotifyWithTaskContextCall struct {
NotifierID string
Message string
TaskCtx TaskContext
}
NotifyWithTaskContextCall NotifyWithTaskContext 호출 정보를 저장합니다.
type RetryFetcher ¶ added in v1.0.0
type RetryFetcher struct {
// contains filtered or unexported fields
}
RetryFetcher는 Fetcher 인터페이스를 구현하며, 실패 시 재시도를 수행합니다.
func NewRetryFetcher ¶ added in v1.0.0
func NewRetryFetcher(delegate Fetcher, maxRetries int, retryDelay time.Duration) *RetryFetcher
NewRetryFetcher는 새로운 RetryFetcher 인스턴스를 생성합니다.
type TaskCanceler ¶ added in v1.0.0
type TaskCanceler interface {
TaskCancel(taskInstanceID TaskInstanceID) (succeeded bool)
}
TaskCanceler
type TaskCommandID ¶
type TaskCommandID string
type TaskContext ¶
type TaskContext interface {
With(key, val interface{}) TaskContext
WithTask(taskID TaskID, taskCommandID TaskCommandID) TaskContext
WithInstanceID(taskInstanceID TaskInstanceID, elapsedTimeAfterRun int64) TaskContext
WithError() TaskContext
Value(key interface{}) interface{}
}
TaskContext
func NewContext ¶
func NewContext() TaskContext
type TaskExecutor ¶ added in v1.0.0
type TaskExecutor interface {
TaskRun(taskID TaskID, taskCommandID TaskCommandID, notifierID string, notifyResultOfTaskRunRequest bool, taskRunBy TaskRunBy) (succeeded bool)
TaskRunWithContext(taskID TaskID, taskCommandID TaskCommandID, taskCtx TaskContext, notifierID string, notifyResultOfTaskRunRequest bool, taskRunBy TaskRunBy) (succeeded bool)
}
TaskExecutor
type TaskID ¶
type TaskID string
const ( TidNaverShopping TaskID = "NS" // 네이버쇼핑(https://shopping.naver.com/) TcidNaverShoppingWatchPriceAny = TaskCommandID(naverShoppingWatchPriceTaskCommandIDPrefix + taskCommandIDAnyString) // 네이버쇼핑 가격 확인 )
type TaskInstanceID ¶
type TaskInstanceID string
type TaskNotificationSender ¶
type TaskNotificationSender interface {
NotifyToDefault(message string) bool
NotifyWithTaskContext(notifierID string, message string, taskCtx TaskContext) bool
SupportHTMLMessage(notifierID string) bool
}
TaskNotificationSender
type TaskService ¶
type TaskService struct {
// contains filtered or unexported fields
}
TaskService
func NewService ¶
func NewService(appConfig *config.AppConfig) *TaskService
func (*TaskService) SetTaskNotificationSender ¶
func (s *TaskService) SetTaskNotificationSender(taskNotificiationSender TaskNotificationSender)
func (*TaskService) TaskCancel ¶
func (s *TaskService) TaskCancel(taskInstanceID TaskInstanceID) (succeeded bool)
func (*TaskService) TaskRun ¶
func (s *TaskService) TaskRun(taskID TaskID, taskCommandID TaskCommandID, notifierID string, notifyResultOfTaskRunRequest bool, taskRunBy TaskRunBy) (succeeded bool)
func (*TaskService) TaskRunWithContext ¶
func (s *TaskService) TaskRunWithContext(taskID TaskID, taskCommandID TaskCommandID, taskCtx TaskContext, notifierID string, notifyResultOfTaskRunRequest bool, taskRunBy TaskRunBy) (succeeded bool)