Class: BaseCradle::TimelineTasks

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/basecradle/items.rb

Overview

One timeline's tasks: create here, or iterate (newest first).

Instance Method Summary collapse

Constructor Details

#initialize(client, timeline_uuid) ⇒ TimelineTasks

Returns a new instance of TimelineTasks.



215
216
217
218
# File 'lib/basecradle/items.rb', line 215

def initialize(client, timeline_uuid)
  @client = client
  @timeline_uuid = timeline_uuid
end

Instance Method Details

#create(instructions:, activate_at:, idempotency_key: nil) ⇒ Object

Schedule a task on this timeline. activate_at accepts a Time/DateTime (serialized to ISO 8601 — make it timezone-aware to be unambiguous) or an ISO 8601 string.

idempotency_key (optional, a UUID recommended) makes the create safe to retry: the platform stores at most one task per key — so a resend returns the original task and never schedules a second activation. See BaseCradle::Client#max_retries.



226
227
228
229
230
231
232
233
234
# File 'lib/basecradle/items.rb', line 226

def create(instructions:, activate_at:, idempotency_key: nil)
  activate_at = activate_at.iso8601 if activate_at.respond_to?(:iso8601)
  response = @client.request(
    "POST", "/timelines/#{@timeline_uuid}/tasks",
    json: { "task" => { "instructions" => instructions, "activate_at" => activate_at } },
    headers: BaseCradle.idempotency_headers(idempotency_key)
  )
  Task.new(response.fetch("task"), client: @client)
end

#each(&block) ⇒ Object



236
237
238
# File 'lib/basecradle/items.rb', line 236

def each(&block)
  TasksResource.new(@client).filter(timeline: @timeline_uuid).each(&block)
end