Files
coder/coderd/database/provisionerjobs/provisionerjobs.go
Steven Masley 687d9538de chore: provisioner acquirer to respect organization ID of jobs (#13874)
* test: add unit test to verify creation of templates in multiple orgs
* chore: provisioner acquirer to respect organization ID of jobs

Prior to this the wrong provisioner was awakened on any new job
posting.

* add comment and stricter check
2024-07-11 11:26:47 -05:00

33 lines
802 B
Go

package provisionerjobs
import (
"encoding/json"
"github.com/google/uuid"
"golang.org/x/xerrors"
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/pubsub"
)
const EventJobPosted = "provisioner_job_posted"
type JobPosting struct {
OrganizationID uuid.UUID `json:"organization_id"`
ProvisionerType database.ProvisionerType `json:"type"`
Tags map[string]string `json:"tags"`
}
func PostJob(ps pubsub.Pubsub, job database.ProvisionerJob) error {
msg, err := json.Marshal(JobPosting{
OrganizationID: job.OrganizationID,
ProvisionerType: job.Provisioner,
Tags: job.Tags,
})
if err != nil {
return xerrors.Errorf("marshal job posting: %w", err)
}
err = ps.Publish(EventJobPosted, msg)
return err
}