Skip to content

Commit

Permalink
do not initialize task cache volumes for one off builds
Browse files Browse the repository at this point in the history
You cannot have task caches for one off builds, but we were never
disallowing that before.

Also, we shouldn't be ignoring foreign key violations and doing a Safe
Retry.

#230

Signed-off-by: Maria Shaldibina <mshaldibina@pivotal.io>
  • Loading branch information
Chris Hendrix authored and mariash committed Jun 26, 2017
1 parent 71f27ac commit e4b9dc9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
4 changes: 0 additions & 4 deletions db/worker_task_cache_factory.go
Expand Up @@ -126,10 +126,6 @@ func (wtc WorkerTaskCache) FindOrCreate(
QueryRow().
Scan(&id)
if err != nil {
if pqErr, ok := err.(*pq.Error); ok && pqErr.Code.Name() == "foreign_key_violation" {
return nil, ErrSafeRetryFindOrCreate
}

if pqErr, ok := err.(*pq.Error); ok && pqErr.Code.Name() == "unique_violation" {
return nil, ErrSafeRetryFindOrCreate
}
Expand Down
23 changes: 13 additions & 10 deletions exec/task_action.go
Expand Up @@ -403,19 +403,22 @@ func (action *TaskAction) registerOutputs(logger lager.Logger, repository *worke
}
}

logger.Debug("initializing-caches", lager.Data{"caches": config.Caches})
// Do not initialize caches for one-off builds
if action.jobID != 0 {
logger.Debug("initializing-caches", lager.Data{"caches": config.Caches})

for _, cacheConfig := range config.Caches {
for _, volumeMount := range volumeMounts {
if volumeMount.MountPath == filepath.Join(action.artifactsRoot, cacheConfig.Path) {
logger.Debug("initializing-cache", lager.Data{"path": volumeMount.MountPath})
for _, cacheConfig := range config.Caches {
for _, volumeMount := range volumeMounts {
if volumeMount.MountPath == filepath.Join(action.artifactsRoot, cacheConfig.Path) {
logger.Debug("initializing-cache", lager.Data{"path": volumeMount.MountPath})

err := volumeMount.Volume.InitializeTaskCache(logger, action.jobID, action.stepName, cacheConfig.Path, bool(action.privileged))
if err != nil {
return err
}
err := volumeMount.Volume.InitializeTaskCache(logger, action.jobID, action.stepName, cacheConfig.Path, bool(action.privileged))
if err != nil {
return err
}

continue
continue
}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions exec/task_action_test.go
Expand Up @@ -673,6 +673,18 @@ var _ = Describe("TaskAction", func() {
Expect(cachePath).To(Equal("some-path-2"))
Expect(p).To(Equal(bool(privileged)))
})

Context("when task does not belong to job (one-off build)", func() {
BeforeEach(func() {
jobID = 0
})

It("does not initialize caches", func() {
Eventually(process.Wait()).Should(Receive(BeNil()))
Expect(fakeVolume1.InitializeTaskCacheCallCount()).To(Equal(0))
Expect(fakeVolume2.InitializeTaskCacheCallCount()).To(Equal(0))
})
})
})

Context("when the configuration specifies paths for outputs", func() {
Expand Down

0 comments on commit e4b9dc9

Please sign in to comment.