Class: TrakFlow::CLI::WorkflowCommands
- Inherits:
-
Thor
- Object
- Thor
- TrakFlow::CLI::WorkflowCommands
- Defined in:
- lib/trak_flow/cli/workflow_commands.rb
Overview
Workflow subcommands (running instances of Plans)
Instance Method Summary collapse
Instance Method Details
#discard(id) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/trak_flow/cli/workflow_commands.rb', line 55 def discard(id) with_database do |db| workflow = db.find_task!(id) raise Error, "Can only discard ephemeral Workflows" unless workflow.discardable? db.child_tasks(id).each { |child| db.delete_task(child.id) } db.delete_task(id) output({ discarded: id }) do puts "Discarded Workflow: #{id}" end end end |
#gc ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/trak_flow/cli/workflow_commands.rb', line 94 def gc with_database do |db| hours = parse_duration([:age]) count = db.garbage_collect_ephemeral(max_age_hours: hours) output({ collected: count }) do puts "Collected #{count} ephemeral Workflow(s)" end end end |
#list ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/trak_flow/cli/workflow_commands.rb', line 12 def list with_database do |db| workflows = db.find_workflows(plan_id: [:plan]) workflows = workflows.select(&:ephemeral?) if [:ephemeral] output(workflows.map(&:to_h)) do if workflows.empty? puts "No workflows found" else puts "Workflows:" workflows.each do |wf| ephemeral_tag = wf.ephemeral? ? " [ephemeral]" : "" source_tag = wf.source_plan_id ? " (from: #{wf.source_plan_id})" : "" puts " #{wf.id}: #{wf.title} (#{wf.status})#{ephemeral_tag}#{source_tag}" end end end end end |
#show(id) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/trak_flow/cli/workflow_commands.rb', line 33 def show(id) with_database do |db| workflow = db.find_task!(id) tasks = db.find_workflow_tasks(id) output({ workflow: workflow.to_h, tasks: tasks.map(&:to_h) }) do puts "Workflow: #{workflow.id} - #{workflow.title}" puts "Status: #{workflow.status}" puts "Ephemeral: #{workflow.ephemeral?}" puts "Source Plan: #{workflow.source_plan_id || "(none)"}" puts "" puts "Tasks (#{tasks.size}):" if tasks.empty? puts " (no tasks)" else tasks.each { |task| puts " #{status_icon(task.status)} #{task.id}: #{task.title}" } end end end end |
#summarize(id) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/trak_flow/cli/workflow_commands.rb', line 71 def summarize(id) with_database do |db| workflow = db.find_task!(id) summary_text = File.exist?([:summary]) ? File.read([:summary]) : [:summary] workflow.notes = "#{workflow.notes}\n\n[Summary]\n#{summary_text}".strip workflow.close!(reason: "summarized") db.update_task(workflow) db.child_tasks(id).each do |child| child.close!(reason: "workflow summarized") db.update_task(child) end output(workflow.to_h) do puts "Summarized Workflow: #{id}" end end end |