wallflower 0.2.0 → 0.3.0

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: 777814642256dec3caef9316ece5411d3ae340dd7073f3b56258b2a79804603c
4
- data.tar.gz: 19545678d642b13d461f26408fc8f8844d3dd79fccaddf10c2b394e892561cef
3
+ metadata.gz: 5e7e00290ad10fba0bfe3584638d18335a880f10613804803b84fc1bb3f5f7e9
4
+ data.tar.gz: 032ccc7ddcbacfbae89c35533de1be75765ce9b02750816cd6a6f5497d99fafa
5
5
  SHA512:
6
- metadata.gz: 1fbef5b2d7cf042c5c4c6063726696520396fc4fba134ae5dfda7ce4456b5d25c904e26fe1efd1a718f7a555c58e36a163f77cc41008acaa21ec78108ee63778
7
- data.tar.gz: 345abf578eb99a1043797466ad1c5c81d29f91086bd4ec1497c24d20bdb95b2551cfff6925409ea7ebe7afb1b09360b23fd4e57bb4d1a0691b4ebfbe1888b60b
6
+ metadata.gz: eb831b13ef2dc9a434c657c187695222e0bf9f7b49857583beffaee7ff6a4e665c3fb54f1fd00e89a1a14d80bacd24c3237978b2f66f3814ccbd0890b31919d7
7
+ data.tar.gz: 4abf66b6611750f47ffd3db7852acada04fc7687ef3dbcca85fbce2b937966fced569059d024c062430d107be2e8a6d6e15c9987d90b7f0270012b79428c8c17
data/README.md CHANGED
@@ -132,11 +132,11 @@ With `keep_for` set, the same sweep deletes each finished or failed task that en
132
132
 
133
133
  ## The task list
134
134
 
135
- The engine's root lists the tasks the signed-in person started in the current account, newest first. Each row shows the kind's title, the status as a coloured badge, the progress and when it was started, links to the task's page, and updates while the task runs.
135
+ The engine's root lists the tasks the signed-in person started in the current account, newest first. Each row shows the kind's title, the status as a coloured badge, the progress, the time left while it runs and when it was started, links to the task's page, and updates while the task runs.
136
136
 
137
137
  ## The task page
138
138
 
139
- A task's page lives at `tasks/:id` under the engine's mount path. The person who started the task sees its kind's title, its status and, once the runner has set a total, a progress bar of done against total. The page listens for changes to its task over Turbo Streams, so its status and progress update without a reload, in a browser and in the Hotwire Native iOS app alike. Anyone else, and the same person viewing from another account, gets a not-found response.
139
+ A task's page lives at `tasks/:id` under the engine's mount path. The person who started the task sees its kind's title, its status and, once the runner has set a total, a progress bar of done against total. While the task runs and is at least five percent done, an estimate of the time left sits under the bar, worked out from how fast the task has gone since it started running. The page listens for changes to its task over Turbo Streams, so its status, progress and time left update without a reload, in a browser and in the Hotwire Native iOS app alike. Anyone else, and the same person viewing from another account, gets a not-found response.
140
140
 
141
141
  The task page and the task list reload in place when they are shown again after being hidden, such as when the iOS app returns from the background, so they show changes broadcast while they could not receive them. A page that stays visible makes no extra request. The copied controller is registered by the host's own Stimulus setup, as `wallflower--catch-up`.
142
142
 
@@ -10,7 +10,7 @@ module Wallflower
10
10
  private
11
11
 
12
12
  def run(task)
13
- task.update!(status: "running")
13
+ task.update!(status: "running", started_at: Time.current)
14
14
  Wallflower.kind(task.kind).runner.constantize.new.call(task)
15
15
  task.update!(status: "finished", finished_at: Time.current)
16
16
  rescue StandardError => error
@@ -44,6 +44,15 @@ module Wallflower
44
44
  update!(total: total)
45
45
  end
46
46
 
47
+ ESTIMATE_AFTER_SHARE = 0.05
48
+
49
+ def seconds_left
50
+ return unless estimable?
51
+
52
+ seconds_per_row = (Time.current - started_at) / done
53
+ ((total - done) * seconds_per_row).round
54
+ end
55
+
47
56
  PROGRESS_SAVE_INTERVAL = 1.second
48
57
 
49
58
  def advance(by = 1)
@@ -53,5 +62,11 @@ module Wallflower
53
62
  save!
54
63
  @progress_saved_at = Time.current
55
64
  end
65
+
66
+ private
67
+
68
+ def estimable?
69
+ status == "running" && started_at && total && done.positive? && done >= total * ESTIMATE_AFTER_SHARE
70
+ end
56
71
  end
57
72
  end
@@ -8,4 +8,7 @@
8
8
  <%= render Keystone::Ui::ProgressComponent.new(value: task.done, max: task.total, label: "#{task.done} of #{task.total}") %>
9
9
  <% end %>
10
10
  </div>
11
+ <% if task.seconds_left %>
12
+ <p id="<%= dom_id(task, :time_left) %>"><%= "#{distance_of_time_in_words(task.seconds_left)} left" %></p>
13
+ <% end %>
11
14
  </div>
@@ -17,6 +17,7 @@ module Wallflower
17
17
  migration_template "create_wallflower_refusals.rb.erb", "db/migrate/create_wallflower_refusals.rb"
18
18
  migration_template "add_result_url_to_wallflower_tasks.rb.erb", "db/migrate/add_result_url_to_wallflower_tasks.rb"
19
19
  migration_template "add_error_message_to_wallflower_tasks.rb.erb", "db/migrate/add_error_message_to_wallflower_tasks.rb"
20
+ migration_template "add_started_at_to_wallflower_tasks.rb.erb", "db/migrate/add_started_at_to_wallflower_tasks.rb"
20
21
  end
21
22
 
22
23
  def copy_catch_up_controller
@@ -0,0 +1,5 @@
1
+ class AddStartedAtToWallflowerTasks < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
2
+ def change
3
+ add_column :wallflower_tasks, :started_at, :datetime
4
+ end
5
+ end
@@ -24,6 +24,10 @@ module Wallflower
24
24
  migration_template "add_error_message_to_wallflower_tasks.rb.erb", "db/migrate/add_error_message_to_wallflower_tasks.rb"
25
25
  end
26
26
 
27
+ def copy_started_at_migration
28
+ migration_template "add_started_at_to_wallflower_tasks.rb.erb", "db/migrate/add_started_at_to_wallflower_tasks.rb"
29
+ end
30
+
27
31
  def copy_catch_up_controller
28
32
  source = File.expand_path("../../../../app/javascript/wallflower/catch_up_controller.js", __dir__)
29
33
  create_file "app/javascript/controllers/wallflower/catch_up_controller.js", File.read(source)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wallflower
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wallflower
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider
@@ -105,6 +105,7 @@ files:
105
105
  - lib/generators/wallflower/install/install_generator.rb
106
106
  - lib/generators/wallflower/install/templates/add_error_message_to_wallflower_tasks.rb.erb
107
107
  - lib/generators/wallflower/install/templates/add_result_url_to_wallflower_tasks.rb.erb
108
+ - lib/generators/wallflower/install/templates/add_started_at_to_wallflower_tasks.rb.erb
108
109
  - lib/generators/wallflower/install/templates/create_wallflower_refusals.rb.erb
109
110
  - lib/generators/wallflower/install/templates/create_wallflower_tasks.rb.erb
110
111
  - lib/generators/wallflower/update/update_generator.rb