Skip to content

Commit

Permalink
feat: add rollback and virtual list
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelncui committed Oct 12, 2023
1 parent 7a2fb83 commit 59f626c
Show file tree
Hide file tree
Showing 44 changed files with 3,148 additions and 2,538 deletions.
4 changes: 0 additions & 4 deletions apis/job_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,5 @@ func (api *API) JobCreate(ctx context.Context, req *entity.JobCreateRequest) (*e
return nil, err
}

if err := api.exe.Start(ctx, job); err != nil {
return nil, err
}

return &entity.JobCreateReply{Job: convertJobs(job)[0]}, nil
}
44 changes: 44 additions & 0 deletions apis/job_edit_state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package apis

import (
"context"
"fmt"

"github.com/samuelncui/yatm/entity"
)

func (api *API) JobEditState(ctx context.Context, req *entity.JobEditStateRequest) (*entity.JobEditStateReply, error) {
job, err := api.exe.GetJob(ctx, req.Id)
if err != nil {
return nil, err
}
if job == nil {
return nil, fmt.Errorf("job not found, id= %d", req.Id)
}

if job.Status == entity.JobStatus_PROCESSING {
return nil, fmt.Errorf("job status 'PROCESSING' is unexpected")
}
if req.Status != nil {
if *req.Status == entity.JobStatus_PROCESSING {
return nil, fmt.Errorf("job target status 'PROCESSING' is unexpected")
}
job.Status = *req.Status
}

job.State = req.State
if _, err := api.exe.SaveJob(ctx, job); err != nil {
return nil, fmt.Errorf("save job fail, %w", err)
}

executor, err := api.exe.GetJobExecutor(ctx, job.ID)
if err != nil {
return nil, fmt.Errorf("get job executor fail, %w", err)
}

if err := executor.Close(ctx); err != nil {
return nil, fmt.Errorf("close job executor fail, %w", err)
}

return &entity.JobEditStateReply{}, nil
}
11 changes: 3 additions & 8 deletions apis/job_next.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ import (
"github.com/samuelncui/yatm/entity"
)

func (api *API) JobNext(ctx context.Context, req *entity.JobNextRequest) (*entity.JobNextReply, error) {
job, err := api.exe.GetJob(ctx, req.Id)
if err != nil {
func (api *API) JobDispatch(ctx context.Context, req *entity.JobDispatchRequest) (*entity.JobDispatchReply, error) {
if err := api.exe.Dispatch(ctx, req.Id, req.Param); err != nil {
return nil, err
}

if err := api.exe.Submit(ctx, job, req.Param); err != nil {
return nil, err
}

return &entity.JobNextReply{Job: convertJobs(job)[0]}, nil
return &entity.JobDispatchReply{}, nil
}
167 changes: 84 additions & 83 deletions entity/job.pb.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions entity/job.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ message JobState {
}
}

message JobNextParam {
message JobDispatchParam {
oneof param {
job_archive.JobArchiveNextParam archive = 1;
job_restore.JobRestoreNextParam restore = 2;
job_archive.JobArchiveDispatchParam archive = 1;
job_restore.JobRestoreDispatchParam restore = 2;
}
}

Expand Down
176 changes: 88 additions & 88 deletions entity/job_archive.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion entity/job_archive.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ message JobArchiveParam {
repeated source.Source sources = 1;
}

message JobArchiveNextParam {
message JobArchiveDispatchParam {
oneof param {
JobArchiveWaitForTapeParam wait_for_tape = 1;
JobArchiveCopyingParam copying = 2;
Expand Down
222 changes: 111 additions & 111 deletions entity/job_restore.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion entity/job_restore.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ message JobRestoreParam {
repeated int64 file_ids = 1;
}

message JobRestoreNextParam {
message JobRestoreDispatchParam {
oneof param {
JobRestoreWaitForTapeParam wait_for_tape = 1;
JobRestoreCopyingParam copying = 2;
Expand Down
Loading

0 comments on commit 59f626c

Please sign in to comment.