Skip to content

Commit 59f626c

Browse files
committed
feat: add rollback and virtual list
1 parent 7a2fb83 commit 59f626c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3148
-2538
lines changed

apis/job_create.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,5 @@ func (api *API) JobCreate(ctx context.Context, req *entity.JobCreateRequest) (*e
1616
return nil, err
1717
}
1818

19-
if err := api.exe.Start(ctx, job); err != nil {
20-
return nil, err
21-
}
22-
2319
return &entity.JobCreateReply{Job: convertJobs(job)[0]}, nil
2420
}

apis/job_edit_state.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package apis
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/samuelncui/yatm/entity"
8+
)
9+
10+
func (api *API) JobEditState(ctx context.Context, req *entity.JobEditStateRequest) (*entity.JobEditStateReply, error) {
11+
job, err := api.exe.GetJob(ctx, req.Id)
12+
if err != nil {
13+
return nil, err
14+
}
15+
if job == nil {
16+
return nil, fmt.Errorf("job not found, id= %d", req.Id)
17+
}
18+
19+
if job.Status == entity.JobStatus_PROCESSING {
20+
return nil, fmt.Errorf("job status 'PROCESSING' is unexpected")
21+
}
22+
if req.Status != nil {
23+
if *req.Status == entity.JobStatus_PROCESSING {
24+
return nil, fmt.Errorf("job target status 'PROCESSING' is unexpected")
25+
}
26+
job.Status = *req.Status
27+
}
28+
29+
job.State = req.State
30+
if _, err := api.exe.SaveJob(ctx, job); err != nil {
31+
return nil, fmt.Errorf("save job fail, %w", err)
32+
}
33+
34+
executor, err := api.exe.GetJobExecutor(ctx, job.ID)
35+
if err != nil {
36+
return nil, fmt.Errorf("get job executor fail, %w", err)
37+
}
38+
39+
if err := executor.Close(ctx); err != nil {
40+
return nil, fmt.Errorf("close job executor fail, %w", err)
41+
}
42+
43+
return &entity.JobEditStateReply{}, nil
44+
}

apis/job_next.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,10 @@ import (
66
"github.com/samuelncui/yatm/entity"
77
)
88

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

15-
if err := api.exe.Submit(ctx, job, req.Param); err != nil {
16-
return nil, err
17-
}
18-
19-
return &entity.JobNextReply{Job: convertJobs(job)[0]}, nil
14+
return &entity.JobDispatchReply{}, nil
2015
}

entity/job.pb.go

Lines changed: 84 additions & 83 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

entity/job.proto

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ message JobState {
4141
}
4242
}
4343

44-
message JobNextParam {
44+
message JobDispatchParam {
4545
oneof param {
46-
job_archive.JobArchiveNextParam archive = 1;
47-
job_restore.JobRestoreNextParam restore = 2;
46+
job_archive.JobArchiveDispatchParam archive = 1;
47+
job_restore.JobRestoreDispatchParam restore = 2;
4848
}
4949
}
5050

entity/job_archive.pb.go

Lines changed: 88 additions & 88 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

entity/job_archive.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ message JobArchiveParam {
1616
repeated source.Source sources = 1;
1717
}
1818

19-
message JobArchiveNextParam {
19+
message JobArchiveDispatchParam {
2020
oneof param {
2121
JobArchiveWaitForTapeParam wait_for_tape = 1;
2222
JobArchiveCopyingParam copying = 2;

entity/job_restore.pb.go

Lines changed: 111 additions & 111 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

entity/job_restore.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ message JobRestoreParam {
1616
repeated int64 file_ids = 1;
1717
}
1818

19-
message JobRestoreNextParam {
19+
message JobRestoreDispatchParam {
2020
oneof param {
2121
JobRestoreWaitForTapeParam wait_for_tape = 1;
2222
JobRestoreCopyingParam copying = 2;

0 commit comments

Comments
 (0)