Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
motatoes committed Jan 25, 2024
1 parent 93da167 commit cf5fa92
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 28 deletions.
4 changes: 2 additions & 2 deletions backend/controllers/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,10 +675,10 @@ func TriggerDiggerJobs(client *github.Client, repoOwner string, repoName string,
log.Printf("number of diggerJobs:%v\n", len(diggerJobs))

for _, job := range diggerJobs {
if job.SerializedJob == nil {
if job.SerializedJobSpec == nil {
return fmt.Errorf("GitHub job can't be nil")
}
jobString := string(job.SerializedJob)
jobString := string(job.SerializedJobSpec)
log.Printf("jobString: %v \n", jobString)

// TODO: make workflow file name configurable
Expand Down
2 changes: 1 addition & 1 deletion backend/controllers/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func SetJobStatusForProject(c *gin.Context) {

// store digger job summary
if request.JobSummary != nil {
models.DB.UpdateDiggerJobSummary(job.DiggerJobId, request.JobSummary.ResourcesCreated, request.JobSummary.ResourcesUpdated, request.JobSummary.ResourcesDeleted)
models.DB.UpdateDiggerJobSummary(job.DiggerJobID, request.JobSummary.ResourcesCreated, request.JobSummary.ResourcesUpdated, request.JobSummary.ResourcesDeleted)
}

case "failed":
Expand Down
6 changes: 3 additions & 3 deletions backend/models/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type DiggerJob struct {
BatchID *string `gorm:"index:idx_digger_job_id"`
DiggerJobSummary DiggerJobSummary
DiggerJobSummaryID uint
SerializedJob []byte
SerializedJobSpec []byte
StatusUpdatedAt time.Time
}

Expand Down Expand Up @@ -69,14 +69,14 @@ type GithubDiggerJobLink struct {

func (j *DiggerJob) MapToJsonStruct() interface{} {
var job orchestrator.JobJson
err := json.Unmarshal(j.SerializedJob, &job)
err := json.Unmarshal(j.SerializedJobSpec, &job)
if err != nil {
log.Printf("Failed to convert unmarshall Serialized job")
}
return orchestrator_scheduler.SerializedJob{
DiggerJobId: j.DiggerJobID,
Status: j.Status,
JobString: j.SerializedJob,
JobString: j.SerializedJobSpec,
ProjectName: job.ProjectName,
ResourcesCreated: j.DiggerJobSummary.ResourcesCreated,
ResourcesUpdated: j.DiggerJobSummary.ResourcesUpdated,
Expand Down
2 changes: 1 addition & 1 deletion backend/models/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ func (db *Database) CreateDiggerJob(batchId uuid.UUID, serializedJob []byte) (*D
}

job := &DiggerJob{DiggerJobID: jobId, Status: scheduler.DiggerJobCreated,
BatchID: &batchIdStr, SerializedJob: serializedJob, DiggerJobSummary: *summary}
BatchID: &batchIdStr, SerializedJobSpec: serializedJob, DiggerJobSummary: *summary}
result = db.GormDB.Save(job)
if result.Error != nil {
return nil, result.Error
Expand Down
19 changes: 7 additions & 12 deletions backend/models/storage_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package models

import (
"github.com/davecgh/go-spew/spew"
"github.com/diggerhq/digger/libs/orchestrator/scheduler"
"github.com/stretchr/testify/assert"
"gorm.io/driver/sqlite"
Expand Down Expand Up @@ -152,22 +153,16 @@ func TestGetDiggerJobsForBatchPreloadsSummary(t *testing.T) {
job, err := DB.CreateDiggerJob(batch.ID, []byte{97})
assert.NoError(t, err)

job, err = DB.UpdateDiggerJobSummary(job.DiggerJobId, 1, 2, 3)
job, err = DB.UpdateDiggerJobSummary(job.DiggerJobID, 1, 2, 3)
assert.NoError(t, err)

//fetchedBatch, err := DB.GetDiggerBatch(&batch.ID)
//assert.NoError(t, err)
//jsons, err := fetchedBatch.MapToJsonStruct()
//assert.NoError(t, err)

//jobs := job.MapToJsonStruct()
//
//println(job.DiggerJobSummary.ResourcesCreated, job.DiggerJobSummary.ResourcesUpdated, job.DiggerJobSummary.ResourcesDeleted)
//spew.Dump(jsons)
//spew.Dump(jobs)

jobssss, err := DB.GetDiggerJobsForBatch(batch.ID)
println(job.DiggerJobSummary.ResourcesCreated, job.DiggerJobSummary.ResourcesUpdated, job.DiggerJobSummary.ResourcesDeleted)
println(jobssss[0].DiggerJobSummary.ResourcesCreated, jobssss[0].DiggerJobSummary.ResourcesUpdated, jobssss[0].DiggerJobSummary.ResourcesDeleted)

fetchedBatch, err := DB.GetDiggerBatch(&batch.ID)
assert.NoError(t, err)
jsons, err := fetchedBatch.MapToJsonStruct()
assert.NoError(t, err)
spew.Dump(jsons)
}
10 changes: 5 additions & 5 deletions backend/services/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
)

func DiggerJobCompleted(client *github.Client, batchId *uuid.UUID, parentJob *models.DiggerJob, repoOwner string, repoName string, workflowFileName string) error {
log.Printf("DiggerJobCompleted parentJobId: %v", parentJob.DiggerJobId)
log.Printf("DiggerJobCompleted parentJobId: %v", parentJob.DiggerJobID)

jobLinksForParent, err := models.DB.GetDiggerJobParentLinksByParentId(&parentJob.DiggerJobId)
jobLinksForParent, err := models.DB.GetDiggerJobParentLinksByParentId(&parentJob.DiggerJobID)
if err != nil {
return err
}
Expand Down Expand Up @@ -50,18 +50,18 @@ func DiggerJobCompleted(client *github.Client, batchId *uuid.UUID, parentJob *mo
}

func TriggerJob(client *github.Client, repoOwner string, repoName string, batchId *uuid.UUID, job *models.DiggerJob, workflowFileName string) {
log.Printf("TriggerJob jobId: %v", job.DiggerJobId)
log.Printf("TriggerJob jobId: %v", job.DiggerJobID)

batch, err := models.DB.GetDiggerBatch(batchId)
if err != nil {
log.Printf("TriggerJob err: %v\n", err)
return
}

if job.SerializedJob == nil {
if job.SerializedJobSpec == nil {
log.Printf("GitHub job can't be nil")
}
jobString := string(job.SerializedJob)
jobString := string(job.SerializedJobSpec)
log.Printf("jobString: %v \n", jobString)

err = utils.TriggerGithubWorkflow(client, repoOwner, repoName, *job, jobString, *batch.CommentId)
Expand Down
2 changes: 1 addition & 1 deletion backend/utils/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TriggerGithubWorkflow(client *github.Client, repoOwner string, repoName str
log.Printf("TriggerGithubWorkflow: repoOwner: %v, repoName: %v, commentId: %v", repoOwner, repoName, commentId)
_, err := client.Actions.CreateWorkflowDispatchEventByFileName(context.Background(), repoOwner, repoName, "digger_workflow.yml", github.CreateWorkflowDispatchEventRequest{
Ref: job.Batch.BranchName,
Inputs: map[string]interface{}{"job": jobString, "id": job.DiggerJobId, "comment_id": strconv.FormatInt(commentId, 10)},
Inputs: map[string]interface{}{"job": jobString, "id": job.DiggerJobID, "comment_id": strconv.FormatInt(commentId, 10)},
})
return err
}
6 changes: 3 additions & 3 deletions backend/utils/graphs.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func ConvertJobsToDiggerJobs(jobsMap map[string]orchestrator.Job, projectMap map
log.Printf("failed to create a job, error: %v", err)
return false
}
_, err = models.DB.CreateDiggerJobLink(parentJob.DiggerJobId, repoFullName)
_, err = models.DB.CreateDiggerJobLink(parentJob.DiggerJobID, repoFullName)
if err != nil {
log.Printf("failed to create a digger job link")
return false
Expand All @@ -70,12 +70,12 @@ func ConvertJobsToDiggerJobs(jobsMap map[string]orchestrator.Job, projectMap map
log.Printf("failed to create a job")
return false
}
_, err = models.DB.CreateDiggerJobLink(childJob.DiggerJobId, repoFullName)
_, err = models.DB.CreateDiggerJobLink(childJob.DiggerJobID, repoFullName)
if err != nil {
log.Printf("failed to create a digger job link")
return false
}
err = models.DB.CreateDiggerJobParentLink(parentDiggerJob.DiggerJobId, childJob.DiggerJobId)
err = models.DB.CreateDiggerJobParentLink(parentDiggerJob.DiggerJobID, childJob.DiggerJobID)
if err != nil {
log.Printf("failed to create a digger job parent link")
return false
Expand Down

0 comments on commit cf5fa92

Please sign in to comment.