Module: ActiveJob::Temporal::SearchAttributes
- Extended by:
- SearchAttributes
- Included in:
- SearchAttributes
- Defined in:
- lib/activejob/temporal/search_attributes.rb
Overview
Pre-Registration Required Search attributes MUST be pre-registered in the Temporal cluster with the correct type (KEYWORD, TIME, INTEGER, etc.) before use. Unregistered attributes will cause workflow start failures. Use the Temporal CLI to register attributes:
tctl admin cluster add-search-attributes --name ajClass --type Keyword
tctl admin cluster add-search-attributes --name ajQueue --type Keyword
tctl admin cluster add-search-attributes --name ajJobId --type Keyword
tctl admin cluster add-search-attributes --name ajEnqueuedAt --type Datetime
tctl admin cluster add-search-attributes --name ajTenantId --type Int
tctl admin cluster add-search-attributes --name ajTags --type KeywordList
Tenant ID Extraction The module automatically extracts tenant_id from the first job argument if it responds to the ‘tenant_id` method. This supports multi-tenant architectures where jobs operate on tenant-specific data.
Builds Temporal search attributes for job metadata.
This module constructs typed search attributes that enable filtering and searching workflows in the Temporal UI and via the Temporal API. Attributes include job class, queue name, job ID, enqueued timestamp, and optionally tenant ID.
Constant Summary collapse
- SEARCH_ATTRIBUTE_KEY_DEFINITIONS =
{ aj_class: ["ajClass", :KEYWORD], aj_queue: ["ajQueue", :KEYWORD], aj_job_id: ["ajJobId", :KEYWORD], aj_enqueued_at: ["ajEnqueuedAt", :TIME], aj_tenant_id: ["ajTenantId", :INTEGER], aj_tags: ["ajTags", :KEYWORD_LIST] }.freeze
Instance Method Summary collapse
-
#for(job) ⇒ Temporalio::SearchAttributes
Builds a Temporalio::SearchAttributes object for a job.
Instance Method Details
#for(job) ⇒ Temporalio::SearchAttributes
Builds a Temporalio::SearchAttributes object for a job.
Creates typed search attribute keys and populates them with job metadata. If ‘enable_search_attributes` is disabled in configuration, this should still be called but may return an empty attributes object (handled by caller).
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/activejob/temporal/search_attributes.rb', line 97 def for(job) # Create Temporal search attributes with typed keys attributes = Temporalio::SearchAttributes.new # Define and set core attributes set_core_attributes(attributes, job) # Add tenant ID if available add_tenant_attribute(attributes, job) # Add job tags if available (attributes, job) attributes end |