Class: Sumologic::Search::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/sumologic/search/job.rb

Overview

Manages search job lifecycle: create, poll, fetch, delete

Instance Method Summary collapse

Constructor Details

#initialize(http_client:, config:) ⇒ Job

Returns a new instance of Job.



10
11
12
13
14
15
16
# File 'lib/sumologic/search/job.rb', line 10

def initialize(http_client:, config:)
  @http = http_client
  @config = config
  @poller = Poller.new(http_client: http_client, config: config)
  @message_fetcher = MessageFetcher.new(http_client: http_client, config: config)
  @record_fetcher = RecordFetcher.new(http_client: http_client, config: config)
end

Instance Method Details

#execute(query:, from_time:, to_time:, time_zone: 'UTC', limit: nil) ⇒ Object

Execute a complete search workflow for raw messages Returns array of messages



20
21
22
23
24
25
26
27
28
29
# File 'lib/sumologic/search/job.rb', line 20

def execute(query:, from_time:, to_time:, time_zone: 'UTC', limit: nil)
  job_id = create(query, from_time, to_time, time_zone)
  @poller.poll(job_id)
  messages = @message_fetcher.fetch_all(job_id, limit: limit)
  delete(job_id)
  messages
rescue StandardError => e
  delete(job_id) if job_id
  raise Error, "Search failed: #{e.message}"
end

#execute_aggregation(query:, from_time:, to_time:, time_zone: 'UTC', limit: nil) ⇒ Object

Execute a complete search workflow for aggregation records Use this for queries with: count by, group by, etc. Returns array of records



34
35
36
37
38
39
40
41
42
43
# File 'lib/sumologic/search/job.rb', line 34

def execute_aggregation(query:, from_time:, to_time:, time_zone: 'UTC', limit: nil)
  job_id = create(query, from_time, to_time, time_zone)
  @poller.poll(job_id)
  records = @record_fetcher.fetch_all(job_id, limit: limit)
  delete(job_id)
  records
rescue StandardError => e
  delete(job_id) if job_id
  raise Error, "Search failed: #{e.message}"
end