Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • oss/libraries/go/services/job-queues
1 result
Select Git revision
Show changes
Commits on Source (1)
...@@ -6,11 +6,12 @@ ...@@ -6,11 +6,12 @@
package jobqueue package jobqueue
import ( import (
"testing"
"time"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gorm.io/driver/sqlite" "gorm.io/driver/sqlite"
"gorm.io/gorm" "gorm.io/gorm"
"testing"
"time"
) )
func TestWriteToDB1(t *testing.T) { func TestWriteToDB1(t *testing.T) {
......
...@@ -8,58 +8,64 @@ import ( ...@@ -8,58 +8,64 @@ import (
) )
var ( var (
ErrMissingDependency = fmt.Errorf("missing dependency") ErrMissingDependency = newUIError("missing dependency")
ErrCycleDetected = fmt.Errorf("cycle detected") ErrCycleDetected = newUIError("cycle detected")
ErrQueueEmpty = fmt.Errorf("queue is empty") ErrQueueEmpty = newUIError("queue is empty")
ErrJobAlreadyExists = fmt.Errorf("job already exists") ErrJobAlreadyExists = newUIError("job already exists")
ErrWorkerNotRunning = fmt.Errorf("worker is not running") ErrWorkerNotRunning = newUIError("worker is not running")
ErrMaxJobsReached = fmt.Errorf("maximum number of jobs reached") ErrMaxJobsReached = newUIError("maximum number of jobs reached")
ErrWorkerAlreadyRunning = fmt.Errorf("worker is already running") ErrWorkerAlreadyRunning = newUIError("worker is already running")
ErrWorkerAlreadyAdded = fmt.Errorf("worker is already added") ErrWorkerAlreadyAdded = newUIError("worker is already added")
ErrWorkerNotAdded = fmt.Errorf("worker is not added") ErrWorkerNotAdded = newUIError("worker is not added")
ErrNoWorkers = fmt.Errorf("no workers") ErrNoWorkers = newUIError("no workers")
ErrWorkerAlreadyStopped = fmt.Errorf("worker is already stopped") ErrWorkerAlreadyStopped = newUIError("worker is already stopped")
ErrManagerAlreadyStopped = fmt.Errorf("manager is already stopped") ErrManagerAlreadyStopped = newUIError("manager is already stopped")
ErrManagerAlreadyRunning = fmt.Errorf("manager is already running") ErrManagerAlreadyRunning = newUIError("manager is already running")
ErrManagerNotRunning = fmt.Errorf("manager is not running") ErrManagerNotRunning = newUIError("manager is not running")
ErrJobNotScheduled = fmt.Errorf("job is not scheduled") ErrJobNotScheduled = newUIError("job is not scheduled")
ErrCronNotInitialized = fmt.Errorf("cron is not initialized") ErrCronNotInitialized = newUIError("cron is not initialized")
ErrCPUPercentage = fmt.Errorf("cpu percentage must be between 0 and 100") ErrCPUPercentage = newUIError("cpu percentage must be between 0 and 100")
ErrIntervalIsZero = fmt.Errorf("interval must be greater than 0") ErrIntervalIsZero = newUIError("interval must be greater than 0")
ErrUnknownRunnableType = fmt.Errorf("unknown runnable type") ErrUnknownRunnableType = newUIError("unknown runnable type")
ErrUnknownSchedulerType = fmt.Errorf("unknown scheduler type") ErrUnknownSchedulerType = newUIError("unknown scheduler type")
ErrUnsupportedDatabaseType = fmt.Errorf("unsupported database type") ErrUnsupportedDatabaseType = newUIError("unsupported database type")
ErrUnsupportedFileOption = fmt.Errorf("unsupported file option") ErrUnsupportedFileOption = newUIError("unsupported file option")
ErrUnsupportedCredentialType = fmt.Errorf("unsupported credential type") ErrUnsupportedCredentialType = newUIError("unsupported credential type")
ErrUnsupportedTransferDirection = fmt.Errorf("unsupported transfer direction") ErrUnsupportedTransferDirection = newUIError("unsupported transfer direction")
ErrInvalidData = fmt.Errorf("invalid data") ErrInvalidData = newUIError("invalid data")
ErrUnknownFormat = fmt.Errorf("unknown format") ErrUnknownFormat = newUIError("unknown format")
ErrFailedToCreateTempFile = fmt.Errorf("failed to create temp file") ErrFailedToCreateTempFile = newUIError("failed to create temp file")
ErrFailedToWriteTempFile = fmt.Errorf("failed to write temp file") ErrFailedToWriteTempFile = newUIError("failed to write temp file")
ErrJobAlreadyScheduled = fmt.Errorf("job already scheduled") ErrJobAlreadyScheduled = newUIError("job already scheduled")
ErrNoDatabaseConnection = fmt.Errorf("no database connection") ErrNoDatabaseConnection = newUIError("no database connection")
ErrDBSaverNotRunning = fmt.Errorf("dbsaver is not running") ErrSchedulerNotSet = newUIError("scheduler is not set")
ErrDBSaverNotInitialized = fmt.Errorf("dbsaver is not initialized") ErrJobNotActive = newUIError("job is not active")
ErrSchedulerNotSet = fmt.Errorf("scheduler is not set") ErrJobAlreadyActive = newUIError("job is already active")
ErrJobNotActive = fmt.Errorf("job is not active") ErrChannelAlreadyClosed = newUIError("the channel is already closed")
ErrJobAlreadyActive = fmt.Errorf("job is already active") ErrUnknownScheduleType = newUIError("unknown schedule type")
ErrChannelAlreadyClosed = fmt.Errorf("the channel is already closed") ErrCannotLoadStatsFromDatabase = newUIError("errors while loading stats from database")
ErrUnknownScheduleType = fmt.Errorf("unknown schedule type") ErrInvalidTime = newUIError("invalid time")
ErrNoManager = fmt.Errorf("no manager") ErrSchedulerMisconfiguration = newUIError("scheduler misconfiguration")
ErrCannotLoadStatsFromDatabase = fmt.Errorf("errors while loading stats from database") ErrMaxRetriesReached = newUIError("maximum number of retries reached")
ErrInvalidTime = fmt.Errorf("invalid time") ErrTimeoutReached = newUIError("timeout reached")
ErrSchedulerMisconfiguration = fmt.Errorf("scheduler misconfiguration") ErrFailedToCreate = newUIError("failed to create")
ErrInvalidDuration = fmt.Errorf("invalid duration") ErrFailedToQueryExistingJob = newUIError("failed to query an existing job")
ErrJobSyncerAlreadyRunning = fmt.Errorf("JobSyncer is already running") ErrFailedToSaveJob = newUIError("failed to save a job")
ErrJobSyncerNotRunning = fmt.Errorf("JobSyncer is not running") ErrParameterIsNil = newUIError("parameter is nil")
ErrMaxRetriesReached = fmt.Errorf("maximum number of retries reached") ErrJobIDEmpty = newUIError("job ID is empty")
ErrTimeoutReached = fmt.Errorf("timeout reached") ErrManagerNotInitialized = newUIError("manager is not initialized")
ErrFailedToCreate = fmt.Errorf("failed to create") ErrScheduleTimeIsInThePast = newUIError("scheduled time is in the past")
ErrFailedToQueryExistingJob = fmt.Errorf("failed to query an existing job")
ErrFailedToSaveJob = fmt.Errorf("failed to save a job")
ErrScheduleTimeIsInThePast = fmt.Errorf("scheduled time is in the past")
ErrParameterIsNil = fmt.Errorf("parameter is nil")
ErrJobIDEmpty = fmt.Errorf("job ID is empty")
ErrManagerNotInitialized = fmt.Errorf("manager is not initialized")
ErrJobSyncerNotInitialized = fmt.Errorf("JobSyncer is not initialized")
) )
// UIError is an error that can be displayed to the user
type UIError struct {
msg string
}
func newUIError(msg string, args ...any) *UIError {
return &UIError{msg: fmt.Sprintf(msg, args...)}
}
func (e *UIError) Error() string {
return e.msg
}
...@@ -5,6 +5,7 @@ package jobqueue ...@@ -5,6 +5,7 @@ package jobqueue
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"github.com/robfig/cron/v3" "github.com/robfig/cron/v3"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
...@@ -247,11 +248,8 @@ func ReadFromGORM(db *gorm.DB) ([]JobPersistence, error) { ...@@ -247,11 +248,8 @@ func ReadFromGORM(db *gorm.DB) ([]JobPersistence, error) {
} }
if len(wrappedErr) > 0 { if len(wrappedErr) > 0 {
returnErr := ErrCannotLoadStatsFromDatabase wrappedErr = append(wrappedErr, ErrCannotLoadStatsFromDatabase)
for _, err := range wrappedErr { return errors.Join(wrappedErr...)
returnErr = fmt.Errorf("%w: %v", returnErr, err)
}
return returnErr
} }
return nil return nil
......