Skip to content

Commit

Permalink
jobservice: update readme (#18849)
Browse files Browse the repository at this point in the history
To reflect the newest job interface, and the missing parts of
DB job service logger.

Signed-off-by: bin liu <liubin0329@gmail.com>
  • Loading branch information
liubin authored Jun 27, 2023
1 parent 46f1fb0 commit 1d6c02f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
37 changes: 27 additions & 10 deletions src/jobservice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ To let the job service recognize the job, the implementation of job should follo
A valid job must implement the job interface. For the details of each method defined in the job interface, you can refer the comments attached with the method.

```go

// Interface defines the related injection and run entry methods.
type Interface interface {
// Declare how many times the job can be retried if failed.
Expand All @@ -76,7 +77,13 @@ type Interface interface {
// uint: the failure count allowed. If it is set to 0, then default value 4 is used.
MaxFails() uint

// Tell the worker pool if retry the failed job when the fails is
// Max currency of the job. Unlike the WorkerPool concurrency, it controls the limit on the number jobs of that type
// that can be active at one time by within a single redis instance.
//
// The default value is 0, which means "no limit on job concurrency".
MaxCurrency() uint

// Tell the worker worker if retry the failed job when the fails is
// still less that the number declared by the method 'MaxFails'.
//
// Returns:
Expand All @@ -87,18 +94,18 @@ type Interface interface {
//
// Return:
// error if parameters are not valid. NOTES: If no parameters needed, directly return nil.
Validate(params map[string]interface{}) error
Validate(params Parameters) error

// Run the business logic here.
// The related arguments will be injected by the workerpool.
//
// ctx env.JobContext : Job execution context.
// ctx Context : Job execution context.
// params map[string]interface{} : parameters with key-pair style for the job execution.
//
// Returns:
// error if failed to run. NOTES: If job is stopped or cancelled, a specified error should be returned
//
Run(ctx env.JobContext, params map[string]interface{}) error
Run(ctx Context, params Parameters) error
}
```

Expand Down Expand Up @@ -180,14 +187,19 @@ func (dj *DemoJob) MaxFails() uint {
return 3
}

// MaxCurrency is implementation of same method in Interface.
func (dj *DemoJob) MaxCurrency() uint {
return 1
}

// ShouldRetry ...
func (dj *DemoJob) ShouldRetry() bool {
return true
}

// Validate is implementation of same method in Interface.
func (dj *DemoJob) Validate(params map[string]interface{}) error {
if params == nil || len(params) == 0 {
func (dj *DemoJob) Validate(params job.Parameters) error {
if len(params) == 0 {
return errors.New("parameters required for replication job")
}
name, ok := params["image"]
Expand All @@ -196,14 +208,14 @@ func (dj *DemoJob) Validate(params map[string]interface{}) error {
}

if !strings.HasPrefix(name.(string), "demo") {
return fmt.Errorf("expected '%s' but got '%s'", "demo steven", name)
return fmt.Errorf("expected '%s' but got '%s'", "demo *", name)
}

return nil
}

// Run the replication logic here.
func (dj *DemoJob) Run(ctx env.JobContext, params map[string]interface{}) error {
func (dj *DemoJob) Run(ctx job.Context, params job.Parameters) error {
logger := ctx.GetLogger()

defer func() {
Expand Down Expand Up @@ -292,7 +304,7 @@ Any jobs can launch new jobs through the launch function in the job context. All

```go

func (j *Job) Run(ctx env.JobContext, params map[string]interface{}) error{
func (j *Job) Run(ctx job.Context, params job.Parameters) error{
// ...
subJob, err := ctx.LaunchJob(models.JobRequest{})
// ...
Expand Down Expand Up @@ -333,6 +345,7 @@ var knownLoggers = map[string]*Declaration{
So far, only the following two backends are supported:

* **STD_OUTPUT**: Output the log to the std stream (stdout/stderr)
* **DB**: Output the log to the database with the table name `job_log`
* **FILE**: Output the log to the log files
* sweeper supports
* getter supports
Expand All @@ -354,7 +367,7 @@ An example:
```yaml
#Loggers
loggers:
- name: "STD_OUTPUT" # logger backend name, only support "FILE" and "STD_OUTPUT"
- name: "STD_OUTPUT" # logger backend name, only support "DB", "FILE" and "STD_OUTPUT"
level: "DEBUG" # INFO/DEBUG/WARNING/ERROR/FATAL
- name: "FILE"
level: "DEBUG"
Expand All @@ -364,6 +377,10 @@ loggers:
duration: 1 #days
settings: # Customized settings of sweeper
work_dir: "/tmp/job_logs"
- name: "DB"
level: "DEBUG"
sweeper:
duration: 1 #days
```
## Configuration
Expand Down
2 changes: 1 addition & 1 deletion src/jobservice/mgt/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/goharbor/harbor/src/lib/errors"
)

// Manager defies the related operations to handle the management of job stats.
// Manager defines the related operations to handle the management of job stats.
type Manager interface {
// Get the stats data of all kinds of jobs.
// Data returned by pagination.
Expand Down

0 comments on commit 1d6c02f

Please sign in to comment.