func (s *StateStore) updateSummaryWithJob(index uint64, job *structs.Job,
	txn *memdb.Txn) error {

	// Update the job summary
	summaryRaw, err := txn.First("job_summary", "id", job.ID)
	if err != nil {
		return fmt.Errorf("job summary lookup failed: %v", err)
	}

	// Get the summary or create if necessary
	var summary *structs.JobSummary
	hasSummaryChanged := false
	if summaryRaw != nil {
		summary = summaryRaw.(*structs.JobSummary).Copy()
	} else {
		summary = &structs.JobSummary{
			JobID:       job.ID,
			Summary:     make(map[string]structs.TaskGroupSummary),
			Children:    new(structs.JobChildrenSummary),
			CreateIndex: index,
		}
		hasSummaryChanged = true
	}

	for _, tg := range job.TaskGroups {
		if _, ok := summary.Summary[tg.Name]; !ok {
			newSummary := structs.TaskGroupSummary{
				Complete: 0,
				Failed:   0,
				Running:  0,
				Starting: 0,
			}
			summary.Summary[tg.Name] = newSummary
			hasSummaryChanged = true
		}
	}

	// The job summary has changed, so update the modify index.
	if hasSummaryChanged {
		summary.ModifyIndex = index

		// Update the indexes table for job summary
		if err := txn.Insert("index", &IndexEntry{"job_summary", index}); err != nil {
			return fmt.Errorf("index update failed: %v", err)
		}
		if err := txn.Insert("job_summary", summary); err != nil {
			return err
		}
	}

	return nil
}
// updateSummaryWithJob creates or updates job summaries when new jobs are
// upserted or existing ones are updated
updateSummaryWithJob creates or updates job summaries when new jobs are
upserted or existing ones are updated
// updateSummaryWithJob creates or updates job summaries when new jobs are // upserted or existing ones are updated
func (s *StateStore) updateSummaryWithJob(index uint64, job *structs.Job,
	txn *memdb.Txn) error {
	summaryRaw, err := txn.First("job_summary", "id", job.ID)
	if err != nil {
		return fmt.Errorf("job summary lookup failed: %v", err)
	}
	var summary *structs.JobSummary
	hasSummaryChanged := false
	if summaryRaw != nil {
		summary = summaryRaw.(*structs.JobSummary).Copy()
	} else {
		summary = &structs.JobSummary{
			JobID:       job.ID,
			Summary:     make(map[string]structs.TaskGroupSummary),
			Children:    new(structs.JobChildrenSummary),
			CreateIndex: index,
		}
		hasSummaryChanged = true
	}
	for _, tg := range job.TaskGroups {
		if _, ok := summary.Summary[tg.Name]; !ok {
			newSummary := structs.TaskGroupSummary{
				Complete: 0,
				Failed:   0,
				Running:  0,
				Starting: 0,
			}
			summary.Summary[tg.Name] = newSummary
			hasSummaryChanged = true
		}
	}
	if hasSummaryChanged {
		summary.ModifyIndex = index
		if err := txn.Insert("index", &IndexEntry{"job_summary", index}); err != nil {
			return fmt.Errorf("index update failed: %v", err)
		}
		if err := txn.Insert("job_summary", summary); err != nil {
			return err
		}
	}
	return nil
}
func ( s * StateStore ) updateSummaryWithJob ( index uint64 , job * structs . Job , txn * memdb . Txn ) error { summaryRaw , err := txn . First ( " " , " " , job . ID ) if err != nil { return fmt . Errorf ( " " , err ) } var summary * structs . JobSummary hasSummaryChanged := false if summaryRaw != nil { summary = summaryRaw . ( * structs . JobSummary ) . Copy ( ) } else { summary = & structs . JobSummary { JobID : job . ID , Summary : make ( map [ string ] structs . TaskGroupSummary ) , Children : new ( structs . JobChildrenSummary ) , CreateIndex : index , } hasSummaryChanged = true } for _ , tg := range job . TaskGroups { if _ , ok := summary . Summary [ tg . Name ] ; ! ok { newSummary := structs . TaskGroupSummary { Complete : 0 , Failed : 0 , Running : 0 , Starting : 0 , } summary . Summary [ tg . Name ] = newSummary hasSummaryChanged = true } } if hasSummaryChanged { summary . ModifyIndex = index if err := txn . Insert ( " " , & IndexEntry { " " , index } ) ; err != nil { return fmt . Errorf ( " " , err ) } if err := txn . Insert ( " " , summary ) ; err != nil { return err } } return nil }
updateSummaryWithJob creates or updates job summaries when new jobs are
upserted or existing ones are updated
updateSummaryWithJob creates or updates job summaries when new jobs are upserted or existing ones are updated
// Update the job summary // Get the summary or create if necessary // The job summary has changed, so update the modify index. // Update the indexes table for job summary