Skip to content

Commit

Permalink
MaxRetryCountをConfigで設定できるようにした refs #48
Browse files Browse the repository at this point in the history
  • Loading branch information
sinmetal committed Oct 5, 2019
1 parent 243e82b commit 35897a5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion datastore_export_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type DatastoreExportRequest struct {
OutputGCSFilePath string `json:"outputGCSFilePath"`
BQLoadProjectID string `json:"bqLoadProjectId"`
BQLoadDatasetID string `json:"bqLoadDatasetId"`
MaxRetryCount int `json:"maxRetryCount"`
}

type DatastoreExportResponse struct {
Expand Down Expand Up @@ -124,7 +125,7 @@ func HandleDatastoreExportAPI(w http.ResponseWriter, r *http.Request) {
}

func (api *DatastoreExportAPI) StartDS2BQJob(ctx context.Context, ds2bqJobID string, body string, form *DatastoreExportRequest, namespaceIDs []string, kinds []string, ef *datastore.EntityFilter) (string, error) {
_, err := api.DSExportJobStore.Create(ctx, ds2bqJobID, body, form.ProjectID, namespaceIDs, kinds)
_, err := api.DSExportJobStore.Create(ctx, ds2bqJobID, body, form.ProjectID, namespaceIDs, kinds, form.MaxRetryCount)
if err != nil {
return "", fmt.Errorf("failed DSExportJobStore.Create() ds2bqJobID=%v.err=%+v", ds2bqJobID, err)
}
Expand Down
2 changes: 1 addition & 1 deletion datastore_export_job_check_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (api *DatastoreExportJobCheckAPI) Check(ctx context.Context, form *Datastor
return failure.New(StatusInternalServerError, failure.Messagef("failed DSExportJobStore.Get. DS2BQJobID=%v,err=%v\n", form.DS2BQJobID, err))
}
job.RetryCount++
if job.RetryCount > 3 { // TODO MaxRetryCountを設定できるようにする
if job.RetryCount > job.MaxRetryCount {
return nil
}

Expand Down
4 changes: 3 additions & 1 deletion dsexport_job_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type DSExportJob struct {
ExportKinds []string `datastore:",noindex"`
StatusCheckCount int
Status DSExportJobStatus
MaxRetryCount int
RetryCount int
ChangeStatusAt time.Time
DSExportResponseMessages []string `datastore:",noindex"` // DatastoreExportJobID-_-ResponseMessagesが格納される
Expand Down Expand Up @@ -89,7 +90,7 @@ func (store *DSExportJobStore) NewKey(ctx context.Context, ds2bqJobID string) da
return store.ds.NameKey("DSExportJob", ds2bqJobID, nil)
}

func (store *DSExportJobStore) Create(ctx context.Context, ds2bqJobID string, body string, exportProjectID string, namespaceIDs []string, kinds []string) (*DSExportJob, error) {
func (store *DSExportJobStore) Create(ctx context.Context, ds2bqJobID string, body string, exportProjectID string, namespaceIDs []string, kinds []string, maxRetryCount int) (*DSExportJob, error) {
e := DSExportJob{
ID: ds2bqJobID,
DSExportJobIDs: []string{},
Expand All @@ -100,6 +101,7 @@ func (store *DSExportJobStore) Create(ctx context.Context, ds2bqJobID string, bo
ExportKinds: kinds,
ChangeStatusAt: time.Now(),
DSExportResponseMessages: []string{},
MaxRetryCount: maxRetryCount,
}
_, err := store.ds.Put(ctx, store.NewKey(ctx, ds2bqJobID), &e)
if err != nil {
Expand Down

0 comments on commit 35897a5

Please sign in to comment.