change_requests 0.3.0 → 0.4.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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -0
  3. data/config/locales/en.yml +7 -0
  4. data/docs/05_execution_and_idempotency.md +129 -0
  5. data/docs/adr/0015-one-guard-object-per-transition.md +25 -6
  6. data/docs/adr/0016-commands-are-the-only-writers.md +28 -7
  7. data/docs/adr/0022-execution-in-three-transactions.md +77 -0
  8. data/docs/adr/0023-one-declaration-surface.md +68 -0
  9. data/docs/adr/0024-idempotence-is-required-not-declared.md +57 -0
  10. data/docs/adr/0025-verification-from-one-set-of-checks.md +62 -0
  11. data/docs/adr/0026-distinct-intent-distinct-command.md +59 -0
  12. data/docs/adr/0027-activejob-is-optional.md +55 -0
  13. data/docs/adr/0028-sweeps-are-rake-tasks.md +67 -0
  14. data/docs/adr/README.md +7 -0
  15. data/lib/change_requests/commands/cancel.rb +11 -1
  16. data/lib/change_requests/commands/cancel_undeclared.rb +46 -0
  17. data/lib/change_requests/commands/reap.rb +37 -0
  18. data/lib/change_requests/commands/settle_execution.rb +27 -3
  19. data/lib/change_requests/configuration.rb +35 -0
  20. data/lib/change_requests/engine.rb +7 -0
  21. data/lib/change_requests/execution/job.rb +27 -0
  22. data/lib/change_requests/execution/runner.rb +31 -2
  23. data/lib/change_requests/guards/base.rb +2 -0
  24. data/lib/change_requests/guards/cancel.rb +9 -1
  25. data/lib/change_requests/guards/reap.rb +59 -0
  26. data/lib/change_requests/maintenance.rb +48 -0
  27. data/lib/change_requests/models/request.rb +18 -0
  28. data/lib/change_requests/version.rb +1 -1
  29. data/lib/change_requests.rb +37 -1
  30. data/lib/tasks/change_requests.rake +39 -1
  31. metadata +14 -1
@@ -1,8 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Loaded by the engine's lib/tasks path, so a host gets these from its own `Rails.application
4
- # .load_tasks` with nothing to require. M3b adds the maintenance sweepers to this namespace.
4
+ # .load_tasks` with nothing to require.
5
+ #
6
+ # The three sweepers below raise on error and say nothing else, so cron's own mail-on-failure is
7
+ # the alarm. See docs/05_execution_and_idempotency.md for which of them belong on a schedule.
5
8
  namespace :change_requests do
9
+ # A local rather than a method: `def` in a .rake file defines on the top level, where it would
10
+ # collide with whatever the host calls its own helpers. The task blocks close over it.
11
+ #
12
+ # Rake exits non-zero when a task raises, so nothing below rescues: an error is an error, and a
13
+ # sweep that moved nothing is not one.
14
+ report = lambda do |verb, count|
15
+ puts "ChangeRequests: #{verb} #{count} #{"request".pluralize(count)}."
16
+ end
17
+
6
18
  desc "Verify every declared operation: its version, target and workflow (§6.12 point 6)"
7
19
  task verify: :environment do
8
20
  count = ChangeRequests.operations.keys.size
@@ -18,4 +30,30 @@ namespace :change_requests do
18
30
 
19
31
  puts "ChangeRequests: #{count} #{"operation".pluralize(count)} verified."
20
32
  end
33
+
34
+ desc "Expire pending and approved requests whose deadline has passed (§8)"
35
+ task expire_stale: :environment do
36
+ report.call("expired", ChangeRequests::Maintenance.expire_stale!)
37
+ end
38
+
39
+ desc "Write off executions nobody settled - OLDER_THAN seconds, default one hour (§8)"
40
+ task reap_stuck_executions: :environment do
41
+ older_than = ENV.fetch("OLDER_THAN", nil)&.to_i
42
+
43
+ count = if older_than
44
+ ChangeRequests::Maintenance.reap_stuck_executions!(older_than: older_than)
45
+ else
46
+ ChangeRequests::Maintenance.reap_stuck_executions!
47
+ end
48
+
49
+ report.call("reaped", count)
50
+ end
51
+
52
+ # Deliberately not on a schedule: a missing declaration is as likely to be a deploy accident as
53
+ # a deliberate removal, and `canceled` is final (§5.11). Refusal and invisibility are immediate
54
+ # and reversible; this is not.
55
+ desc "Cancel open requests whose operation is no longer declared - run by hand (§5.11)"
56
+ task cancel_undeclared: :environment do
57
+ report.call("canceled", ChangeRequests::Maintenance.cancel_undeclared!)
58
+ end
21
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: change_requests
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Finger
@@ -310,6 +310,7 @@ files:
310
310
  - Rakefile
311
311
  - config/locales/en.yml
312
312
  - config/routes.rb
313
+ - docs/05_execution_and_idempotency.md
313
314
  - docs/08_events_and_notifications.md
314
315
  - docs/adr/0001-headless-domain-core.md
315
316
  - docs/adr/0002-mountable-engine-with-isolated-namespace.md
@@ -332,6 +333,13 @@ files:
332
333
  - docs/adr/0019-separation-of-duties.md
333
334
  - docs/adr/0020-refusal-vocabulary-and-fallback.md
334
335
  - docs/adr/0021-serialise-commands-let-the-index-arbitrate.md
336
+ - docs/adr/0022-execution-in-three-transactions.md
337
+ - docs/adr/0023-one-declaration-surface.md
338
+ - docs/adr/0024-idempotence-is-required-not-declared.md
339
+ - docs/adr/0025-verification-from-one-set-of-checks.md
340
+ - docs/adr/0026-distinct-intent-distinct-command.md
341
+ - docs/adr/0027-activejob-is-optional.md
342
+ - docs/adr/0028-sweeps-are-rake-tasks.md
335
343
  - docs/adr/README.md
336
344
  - lib/change_requests.rb
337
345
  - lib/change_requests/authorization/callable.rb
@@ -339,6 +347,7 @@ files:
339
347
  - lib/change_requests/commands/approve.rb
340
348
  - lib/change_requests/commands/base.rb
341
349
  - lib/change_requests/commands/cancel.rb
350
+ - lib/change_requests/commands/cancel_undeclared.rb
342
351
  - lib/change_requests/commands/claim_execution.rb
343
352
  - lib/change_requests/commands/comment.rb
344
353
  - lib/change_requests/commands/create.rb
@@ -346,6 +355,7 @@ files:
346
355
  - lib/change_requests/commands/execute.rb
347
356
  - lib/change_requests/commands/expire.rb
348
357
  - lib/change_requests/commands/override.rb
358
+ - lib/change_requests/commands/reap.rb
349
359
  - lib/change_requests/commands/reject.rb
350
360
  - lib/change_requests/commands/settle_execution.rb
351
361
  - lib/change_requests/commands/unapprove.rb
@@ -356,6 +366,7 @@ files:
356
366
  - lib/change_requests/engine.rb
357
367
  - lib/change_requests/errors.rb
358
368
  - lib/change_requests/execution/dispatcher.rb
369
+ - lib/change_requests/execution/job.rb
359
370
  - lib/change_requests/execution/runner.rb
360
371
  - lib/change_requests/execution/target_contract.rb
361
372
  - lib/change_requests/guards/.keep
@@ -365,8 +376,10 @@ files:
365
376
  - lib/change_requests/guards/comment.rb
366
377
  - lib/change_requests/guards/execute.rb
367
378
  - lib/change_requests/guards/expire.rb
379
+ - lib/change_requests/guards/reap.rb
368
380
  - lib/change_requests/guards/reject.rb
369
381
  - lib/change_requests/guards/unapprove.rb
382
+ - lib/change_requests/maintenance.rb
370
383
  - lib/change_requests/models/.keep
371
384
  - lib/change_requests/models/approval.rb
372
385
  - lib/change_requests/models/approval_quorum.rb