Crea trabajo con un cliente mediante atributos personalizados.
Páginas de documentación que incluyen esta muestra de código
Para ver la muestra de código usada en contexto, consulta la siguiente documentación:
- Atributos personalizados
- Atributos personalizados (v4beta1)
- Conceptos básicos de los trabajos
- Conceptos básicos de los trabajos (v4beta1)
- Guía de inicio rápido: Crea empresas y trabajos
- Guía de inicio rápido: crea empresas y trabajos (v4beta1)
Muestra de código
C#
public static object CreateJobCustomAttributes(string projectId, string tenantId, string companyId, string requisitionId)
{
JobServiceClient jobServiceClient = JobServiceClient.Create();
TenantName tenantName = TenantName.FromProjectTenant(projectId, tenantId);
// Custom attribute can be string or numeric value, and can be filtered in search queries.
// https://cloud.google.com/talent-solution/job-search/docs/custom-attributes
CustomAttribute customAttributes = new CustomAttribute
{
Filterable = true
};
customAttributes.StringValues.Add("Internship");
customAttributes.StringValues.Add("Intern");
customAttributes.StringValues.Add("Apprenticeship");
Job job = new Job
{
Company = companyId,
RequisitionId = requisitionId,
Title = "Software Developer I",
Description = "This is a description of this <i>wonderful</i> job!",
LanguageCode = "en-US"
};
job.CustomAttributes.Add("FOR_STUDENTS", customAttributes);
CreateJobRequest request = new CreateJobRequest
{
ParentAsTenantName = tenantName,
Job = job
};
Job response = jobServiceClient.CreateJob(request);
Console.WriteLine($"Created Job: {response.Name}");
return 0;
}
Go
import (
"context"
"fmt"
"io"
talent "cloud.google.com/go/talent/apiv4beta1"
"github.com/gofrs/uuid"
talentpb "google.golang.org/genproto/googleapis/cloud/talent/v4beta1"
money "google.golang.org/genproto/googleapis/type/money"
)
// createJobWithCustomAttributes creates a job with custom attributes.
func createJobWithCustomAttributes(w io.Writer, projectID, companyID, jobTitle string) (*talentpb.Job, error) {
ctx := context.Background()
// Initialize a job service client.
c, err := talent.NewJobClient(ctx)
if err != nil {
return nil, fmt.Errorf("talent.NewJobClient: %v", err)
}
// requisitionID shoud be the unique ID in your system
requisitionID := fmt.Sprintf("job-with-custom-attribute-%s", uuid.Must(uuid.NewV4()).String())
jobToCreate := &talentpb.Job{
Company: fmt.Sprintf("projects/%s/companies/%s", projectID, companyID),
RequisitionId: requisitionID,
Title: jobTitle,
ApplicationInfo: &talentpb.Job_ApplicationInfo{
Uris: []string{"https://googlesample.com/career"},
},
Description: "Design, devolop, test, deploy, maintain and improve software.",
LanguageCode: "en-US",
PromotionValue: 2,
EmploymentTypes: []talentpb.EmploymentType{talentpb.EmploymentType_FULL_TIME},
Addresses: []string{"Mountain View, CA"},
CustomAttributes: map[string]*talentpb.CustomAttribute{
"someFieldString": {
Filterable: true,
StringValues: []string{"someStrVal"},
},
"someFieldLong": {
Filterable: true,
LongValues: []int64{900},
},
},
CompensationInfo: &talentpb.CompensationInfo{
Entries: []*talentpb.CompensationInfo_CompensationEntry{
{
Type: talentpb.CompensationInfo_BASE,
Unit: talentpb.CompensationInfo_HOURLY,
CompensationAmount: &talentpb.CompensationInfo_CompensationEntry_Amount{
Amount: &money.Money{
CurrencyCode: "USD",
Units: 1,
},
},
},
},
},
}
// Construct a createJob request.
req := &talentpb.CreateJobRequest{
Parent: fmt.Sprintf("projects/%s", projectID),
Job: jobToCreate,
}
resp, err := c.CreateJob(ctx, req)
if err != nil {
return nil, fmt.Errorf("CreateJob: %v", err)
}
fmt.Fprintf(w, "Created job with custom attributres: %q\n", resp.GetName())
fmt.Fprintf(w, "Custom long field has value: %v\n", resp.GetCustomAttributes()["someFieldLong"].GetLongValues())
return resp, nil
}
Java
import com.google.cloud.talent.v4beta1.CreateJobRequest;
import com.google.cloud.talent.v4beta1.CustomAttribute;
import com.google.cloud.talent.v4beta1.Job;
import com.google.cloud.talent.v4beta1.JobServiceClient;
import com.google.cloud.talent.v4beta1.TenantName;
import java.io.IOException;
public class JobSearchCreateJobCustomAttributes {
public static void createJob() throws IOException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
String tenantId = "your-tenant-id";
String companyId = "your-company-id";
String requisitionId = "your-unique-req-id";
createJob(projectId, tenantId, companyId, requisitionId);
}
// Create Job with Custom Attributes.
public static void createJob(
String projectId,
String tenantId,
String companyId,
String requisitionId)
throws IOException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
TenantName parent = TenantName.of(projectId, tenantId);
// Custom attribute can be string or numeric value, and can be filtered in search queries.
// https://cloud.google.com/talent-solution/job-search/docs/custom-attributes
CustomAttribute customAttribute = CustomAttribute.newBuilder()
.addStringValues("Internship")
.addStringValues("Apprenticeship")
.setFilterable(true)
.build();
Job job =
Job.newBuilder()
.setCompany(companyId)
.setTitle("Software Developer I")
.setDescription("This is a description of this <i>wonderful</i> job!")
.putCustomAttributes("FOR_STUDENTS", customAttribute)
.setRequisitionId(requisitionId)
.setLanguageCode("en-US")
.build();
CreateJobRequest request =
CreateJobRequest.newBuilder().setParent(parent.toString()).setJob(job).build();
Job response = jobServiceClient.createJob(request);
System.out.printf("Created job: %s\n", response.getName());
}
}
}
Node.js
const talent = require('@google-cloud/talent').v4;
/**
* Create Job with Custom Attributes
*
* @param projectId {string} Your Google Cloud Project ID
* @param tenantId {string} Identifier of the Tenantd
*/
function sampleCreateJob(
projectId,
tenantId,
companyName,
requisitionId,
languageCode
) {
const client = new talent.JobServiceClient();
// const projectId = 'Your Google Cloud Project ID';
// const tenantId = 'Your Tenant ID (using tenancy is optional)';
// const companyName = 'Company name, e.g. projects/your-project/companies/company-id';
// const requisitionId = 'Job requisition ID, aka Posting ID. Unique per job.';
// const languageCode = 'en-US';
const formattedParent = client.tenantPath(projectId, tenantId);
const job = {
company: companyName,
requisitionId: requisitionId,
languageCode: languageCode,
};
const request = {
parent: formattedParent,
job: job,
};
client
.createJob(request)
.then(responses => {
const response = responses[0];
console.log(`Created job: ${response.name}`);
})
.catch(err => {
console.error(err);
});
}
Python
from google.cloud import talent
import six
def create_job(project_id, tenant_id, company_id, requisition_id):
"""Create Job with Custom Attributes"""
client = talent.JobServiceClient()
# project_id = 'Your Google Cloud Project ID'
# tenant_id = 'Your Tenant ID (using tenancy is optional)'
# company_id = 'Company name, e.g. projects/your-project/companies/company-id'
# requisition_id = 'Job requisition ID, aka Posting ID. Unique per job.'
# language_code = 'en-US'
if isinstance(project_id, six.binary_type):
project_id = project_id.decode("utf-8")
if isinstance(tenant_id, six.binary_type):
tenant_id = tenant_id.decode("utf-8")
if isinstance(company_id, six.binary_type):
company_id = company_id.decode("utf-8")
# Custom attribute can be string or numeric value,
# and can be filtered in search queries.
# https://cloud.google.com/talent-solution/job-search/docs/custom-attributes
custom_attribute = talent.CustomAttribute()
custom_attribute.filterable = True
custom_attribute.string_values.append("Intern")
custom_attribute.string_values.append("Apprenticeship")
parent = f"projects/{project_id}/tenants/{tenant_id}"
job = talent.Job(
company=company_id,
title="Software Engineer",
requisition_id=requisition_id,
description="This is a description of this job",
language_code="en-us",
custom_attributes={"FOR_STUDENTS": custom_attribute}
)
response = client.create_job(parent=parent, job=job)
print(f"Created job: {response.name}")
return response.name
Ruby
require "google/cloud/talent"
# Instantiate a client
job_service = Google::Cloud::Talent.job_service
# project_id = "Your Google Cloud Project ID"
# tenant_id = "Your Tenant ID (using tenancy is required)"
parent = job_service.tenant_path project: project_id, tenant: tenant_id
# title = "Software Engineer"
# description = "This is a description of this <i>wonderful</i> job!"
# company_name = "Company name, e.g. projects/your-project/companies/company-id"
# requisition_id = "Job requisition ID, aka Posting ID. Unique per job."
# language_code = "en-US"
job = {
title: title,
description: description,
company: company_name,
requisition_id: requisition_id,
language_code: language_code
}
response = job_service.create_job parent: parent, job: job
puts "Created job: #{response.name}"