Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TaskService ¶
type TaskService struct {
// contains filtered or unexported fields
}
TaskService is responsible for managing tasks within the application. It contains the necessary dependencies such as a logger, repositories for task and status management, a client for interacting with the Hermes service, metrics for monitoring, and a last known hash for state tracking.
func NewTaskService ¶
func NewTaskService(log *slog.Logger, repo repository.TaskRepoIface, statusRepo repository.StatusRepoIface, metrics *metrics.Metrics, hermesClient pb.ScraperServiceClient, ) *TaskService
NewTaskService creates a new instance of TaskService with the provided dependencies. It takes a logger, task repository, status repository, metrics, and a Hermes client as parameters.
Parameters:
- log: A logger for logging task-related information.
- repo: An interface for task repository operations.
- statusRepo: An interface for status repository operations.
- metrics: A metrics object for tracking performance and usage.
- hermesClient: A client for interacting with the Hermes service.
Returns:
- A pointer to the newly created TaskService instance.
func (*TaskService) GetLastDate ¶
GetLastDate retrieves the last processed date from the status repository. If no date is found, it returns a default date of January 1, 2024. In case of other errors, it returns an error indicating the failure reason.
func (*TaskService) Start ¶
Start begins the task service, updating task types and entering a maintenance mode where it periodically processes tasks at the specified interval. It first updates the task types and then enters a catch-up mode to ensure all tasks are current. In maintenance mode, it uses a ticker to trigger periodic checks and processes tasks until the context is done, at which point it gracefully shuts down the service.
Parameters:
- ctx: The context for managing cancellation and deadlines.
- interval: The duration between periodic task processing.
Returns:
- error: An error if the service fails to start or during processing, otherwise nil.