workspaces 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 501f96e0f82b4dc9f30ec6682feb64329301b3ee888561e84e65941cff084ae7
4
- data.tar.gz: 4ae2d5e24099d7638b349a332daaadf89813a96e37996c4f03c41c7baf2f7636
3
+ metadata.gz: f3771d28dd38a7503c4ca8189e4ce6419d8ad5989c8ef8618fe5420b3572909a
4
+ data.tar.gz: 6dda806083d5074afeb3428d64eb9b05d67b0a1b84b5c485156d7d087606db5f
5
5
  SHA512:
6
- metadata.gz: 67865a47386639bfcff1218218bcf8f055c0b563d295d355d9667e1d8410da7a4981def707bc0f219f4179215b4839a689ec36bfa8bba90738ea92d7771b8ad7
7
- data.tar.gz: 4be62e33d0f29d0c19751b61bd3b9d0dab8cf334314ce62bc5bcfe5f59569235c960b10647cf5bb7060705068db6c1489052b59a97b543c662750f66df3e6f4d
6
+ metadata.gz: 9bfe8edb9cd5d06f9f10adf028da25cec903b5f3429971ef5521a99dd74142454985da667977d113c50129de27e5086cd040e8a6afaf111fbcfce406cb755634
7
+ data.tar.gz: a278582fd63bfae4d3f0f27afd68d36418854b6513e0fe50bcd96e30c73cacc9d8b3b008770d5c5b32dfd1b6abadb8ace1e60034b12909790b38fa169001adeb
data/README.md CHANGED
@@ -39,6 +39,17 @@ The returned JSON includes the workspace ID, dashboard URL, and preview URL. You
39
39
  create from a pull request with `create --pr NUMBER`, or create a new branch with
40
40
  `create --new-branch NAME --from REF`. Run `help` for lifecycle and other commands.
41
41
 
42
+ ### Step timings
43
+
44
+ Per-step durations are persisted in seconds in workspace step status JSON, so they
45
+ remain available after the command exits. Timings also appear in CLI progress,
46
+ the workspace setup log, and the dashboard's step list.
47
+
48
+ A background step measures only process launch, not the server's lifetime or
49
+ readiness. The following readiness step measures its own wait separately.
50
+ Interrupted steps have no recorded duration. Step timings are not the total
51
+ workflow wall-clock time; orchestration overhead can fall outside the steps.
52
+
42
53
  ## Serve the dashboard and previews
43
54
 
44
55
  Run `serve` in a separate terminal using the **same project root and `WORKSPACES_HOME`**
@@ -134,7 +134,7 @@ module Workspaces
134
134
  def publish_starting(id, restart)
135
135
  recipe = Recipe.new
136
136
  steps = recipe.for_operation(restart: restart).map do |step|
137
- { 'key' => step['id'], 'label' => step['name'], 'state' => 'pending' }
137
+ { 'key' => step['id'], 'label' => step['name'], 'state' => 'pending', 'duration_seconds' => nil }
138
138
  end
139
139
  update(id, 'status' => 'preparing', 'message' => restart ? 'Restarting application' : 'Preparing workspace',
140
140
  'steps' => steps,
@@ -54,11 +54,25 @@
54
54
  label.textContent = step.label;
55
55
  const outcome = document.createElement('span');
56
56
  outcome.className = 'step-outcome';
57
- outcome.textContent = step.state;
57
+ outcome.textContent = stepOutcome(step);
58
58
  item.append(bullet, label, outcome);
59
59
  return item;
60
60
  }
61
61
 
62
+ function stepOutcome(step) {
63
+ const state = step.state;
64
+ const rawDuration = step.duration_seconds;
65
+ if (typeof rawDuration !== 'number') return state;
66
+ const duration = rawDuration;
67
+ if (
68
+ (state === 'complete' || state === 'failed') &&
69
+ Number.isFinite(duration) &&
70
+ duration >= 0
71
+ )
72
+ return state + ' · ' + duration.toFixed(3) + 's';
73
+ return state;
74
+ }
75
+
62
76
  function updateLog(data) {
63
77
  if (data.log_source !== selectedLog) return;
64
78
  const log = node('log');
@@ -11,7 +11,7 @@
11
11
  <p id="message"><%= field('message') %></p>
12
12
  <ol class="stepper" id="progress" aria-label="Setup progress">
13
13
  <% @presentation['steps'].each do |step| %>
14
- <li class="step" data-step-state="<%= step['state'] %>" <%= 'aria-current="step"' if step['state'] == 'active' %>><span class="step-bullet" aria-hidden="true"></span><span><%= escape(step['label']) %></span><span class="step-outcome"><%= step['state'] %></span></li>
14
+ <li class="step" data-step-state="<%= step['state'] %>" <%= 'aria-current="step"' if step['state'] == 'active' %>><span class="step-bullet" aria-hidden="true"></span><span><%= escape(step['label']) %></span><span class="step-outcome"><%= escape(step_outcome(step)) %></span></li>
15
15
  <% end %>
16
16
  </ol>
17
17
  <section class="error-panel setup-error" id="error-panel" role="alert" <%= 'hidden' unless @presentation['error'] %>>
@@ -128,5 +128,15 @@ module Workspaces
128
128
  "<form method=\"post\" action=\"/workspaces/#{@id}/#{action.fetch('key')}\">" \
129
129
  "<button class=\"button #{style}\">#{escape(action.fetch('label'))}</button></form>"
130
130
  end
131
+
132
+ def step_outcome(step)
133
+ state = step['state'].to_s
134
+ return state unless %w(complete failed).include?(state)
135
+
136
+ duration = step['duration_seconds']
137
+ return state unless duration.is_a?(Numeric) && duration.finite? && duration >= 0
138
+
139
+ "#{state} · #{format('%.3f', duration)}s"
140
+ end
131
141
  end
132
142
  end
@@ -1,3 +1,3 @@
1
1
  module Workspaces
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -33,7 +33,7 @@ module Workspaces
33
33
 
34
34
  def publish_steps(steps)
35
35
  @state.set(@workspace.id, 'steps' => steps.map do |step|
36
- { 'key' => step['id'], 'label' => step['name'], 'state' => 'pending' }
36
+ { 'key' => step['id'], 'label' => step['name'], 'state' => 'pending', 'duration_seconds' => nil }
37
37
  end)
38
38
  end
39
39
 
@@ -48,6 +48,7 @@ module Workspaces
48
48
  end
49
49
 
50
50
  def execute(step, recipe, context, runner, overrides)
51
+ started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
51
52
  progress(step, 'active')
52
53
  @log.puts "==> #{step.fetch('name')}"
53
54
  command = recipe.command(step, context)
@@ -59,16 +60,24 @@ module Workspaces
59
60
  @backend.ensure_alive! if @server_started
60
61
  end
61
62
  @server_started = true if step['background']
62
- progress(step, 'complete')
63
63
  rescue StandardError
64
- progress(step, 'failed')
64
+ finish_step(step, 'failed', started_at)
65
65
  raise
66
+ else
67
+ finish_step(step, 'complete', started_at)
66
68
  end
67
69
 
68
- def progress(step, status)
70
+ def finish_step(step, status, started_at)
71
+ duration = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - started_at).round(3)
72
+ progress(step, status, duration_seconds: duration)
73
+ @log.puts format('==> %s %s (%.3fs)', step.fetch('name'), status, duration)
74
+ end
75
+
76
+ def progress(step, status, duration_seconds: nil)
69
77
  @state.transaction do |data|
70
78
  entry = data.fetch(@workspace.id)
71
- entry['steps'].find { |item| item['key'] == step['id'] }['state'] = status
79
+ entry['steps'].find { |item| item['key'] == step['id'] }
80
+ .merge!('state' => status, 'duration_seconds' => duration_seconds)
72
81
  entry['message'] = step['name']
73
82
  entry['current_step'] = step['id']
74
83
  entry['updated_at'] = Time.now.utc.iso8601
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workspaces
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Workspaces contributors