@@ -89,24 +89,25 @@ func NewAcquirer(ctx context.Context, logger slog.Logger, store AcquirerStore, p
8989// done, or the database returns an error _other_ than that no jobs are available.
9090// If no jobs are available, this method handles retrying as appropriate.
9191func (a * Acquirer ) AcquireJob (
92- ctx context.Context , worker uuid.UUID , pt []database.ProvisionerType , tags Tags ,
92+ ctx context.Context , organization uuid. UUID , worker uuid.UUID , pt []database.ProvisionerType , tags Tags ,
9393) (
9494 retJob database.ProvisionerJob , retErr error ,
9595) {
9696 logger := a .logger .With (
97+ slog .F ("organization_id" , organization ),
9798 slog .F ("worker_id" , worker ),
9899 slog .F ("provisioner_types" , pt ),
99100 slog .F ("tags" , tags ))
100101 logger .Debug (ctx , "acquiring job" )
101- dk := domainKey (pt , tags )
102+ dk := domainKey (organization , pt , tags )
102103 dbTags , err := tags .ToJSON ()
103104 if err != nil {
104105 return database.ProvisionerJob {}, err
105106 }
106107 // buffer of 1 so that cancel doesn't deadlock while writing to the channel
107108 clearance := make (chan struct {}, 1 )
108109 for {
109- a .want (pt , tags , clearance )
110+ a .want (organization , pt , tags , clearance )
110111 select {
111112 case <- ctx .Done ():
112113 err := ctx .Err ()
@@ -120,6 +121,7 @@ func (a *Acquirer) AcquireJob(
120121 case <- clearance :
121122 logger .Debug (ctx , "got clearance to call database" )
122123 job , err := a .store .AcquireProvisionerJob (ctx , database.AcquireProvisionerJobParams {
124+ OrganizationID : organization ,
123125 StartedAt : sql.NullTime {
124126 Time : dbtime .Now (),
125127 Valid : true ,
@@ -152,8 +154,8 @@ func (a *Acquirer) AcquireJob(
152154}
153155
154156// want signals that an acquiree wants clearance to query for a job with the given dKey.
155- func (a * Acquirer ) want (pt []database.ProvisionerType , tags Tags , clearance chan <- struct {}) {
156- dk := domainKey (pt , tags )
157+ func (a * Acquirer ) want (organization uuid. UUID , pt []database.ProvisionerType , tags Tags , clearance chan <- struct {}) {
158+ dk := domainKey (organization , pt , tags )
157159 a .mu .Lock ()
158160 defer a .mu .Unlock ()
159161 cleared := false
@@ -404,13 +406,16 @@ type dKey string
404406// unprintable control character and won't show up in any "reasonable" set of
405407// string tags, even in non-Latin scripts. It is important that Tags are
406408// validated not to contain this control character prior to use.
407- func domainKey (pt []database.ProvisionerType , tags Tags ) dKey {
409+ func domainKey (orgID uuid.UUID , pt []database.ProvisionerType , tags Tags ) dKey {
410+ sb := strings.Builder {}
411+ _ , _ = sb .WriteString (orgID .String ())
412+ _ = sb .WriteByte (0x00 )
413+
408414 // make a copy of pt before sorting, so that we don't mutate the original
409415 // slice or underlying array.
410416 pts := make ([]database.ProvisionerType , len (pt ))
411417 copy (pts , pt )
412418 slices .Sort (pts )
413- sb := strings.Builder {}
414419 for _ , t := range pts {
415420 _ , _ = sb .WriteString (string (t ))
416421 _ = sb .WriteByte (0x00 )
0 commit comments