lex-task_pruner 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0fd67ef8d795f7c241e8f54b68582d291e70d3f0cec016e612024196eb1c58d3
4
+ data.tar.gz: 12a0ad834c9438b56414c7218770597c2584bf50bf8b37414bcbb975562d89c7
5
+ SHA512:
6
+ metadata.gz: 24141b90fc334cf90ff45a45e480bb5b5644586c904166622b6157e3e73e444fb2a202234fba1121ecc0c263f83602fd44d091ca9e517e5ce3f6916e65ba320f
7
+ data.tar.gz: 6492c8f2a33470373d819d97e92490c29f2ea89a7154d79c003ff5c69a048b9502c8f010e815c81abeaee59bd7465d8779a9e9406a5a5dec6e7bbff47c9ebb1f
@@ -0,0 +1,16 @@
1
+ name: CI
2
+ on:
3
+ push:
4
+ branches: [main]
5
+ pull_request:
6
+
7
+ jobs:
8
+ ci:
9
+ uses: LegionIO/.github/.github/workflows/ci.yml@main
10
+
11
+ release:
12
+ needs: ci
13
+ if: github.event_name == 'push' && github.ref == 'refs/heads/main'
14
+ uses: LegionIO/.github/.github/workflows/release.yml@main
15
+ secrets:
16
+ rubygems-api-key: ${{ secrets.RUBYGEMS_API_KEY }}
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,50 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.4
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Layout/LineLength:
7
+ Max: 160
8
+
9
+ Layout/SpaceAroundEqualsInParameterDefault:
10
+ EnforcedStyle: space
11
+
12
+ Layout/HashAlignment:
13
+ EnforcedHashRocketStyle: table
14
+ EnforcedColonStyle: table
15
+
16
+ Metrics/MethodLength:
17
+ Max: 50
18
+
19
+ Metrics/ClassLength:
20
+ Max: 1500
21
+
22
+ Metrics/ModuleLength:
23
+ Max: 1500
24
+
25
+ Metrics/BlockLength:
26
+ Max: 40
27
+ Exclude:
28
+ - 'spec/**/*'
29
+
30
+ Metrics/AbcSize:
31
+ Max: 60
32
+
33
+ Metrics/CyclomaticComplexity:
34
+ Max: 15
35
+
36
+ Metrics/PerceivedComplexity:
37
+ Max: 17
38
+
39
+ Style/Documentation:
40
+ Enabled: false
41
+
42
+ Style/SymbolArray:
43
+ Enabled: true
44
+
45
+ Style/FrozenStringLiteralComment:
46
+ Enabled: true
47
+ EnforcedStyle: always
48
+
49
+ Naming/FileName:
50
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+
3
+ ## [0.1.1] - 2026-03-18
4
+
5
+ ### Fixed
6
+ - `find_expired` status filter now applied (was silently dropped due to missing reassignment)
7
+ - `find_expired` uses cross-DB `Sequel.lit` instead of MySQL-specific `DATE_SUB(SYSDATE())`
8
+
9
+ ### Added
10
+ - `delete_task(task_id:)` deletes a specific task by ID (was an empty stub)
11
+ - `expire_queued(age:, limit:)` marks stuck queued tasks as `task.expired` (was incomplete)
12
+ - All three runner methods return structured `{ success:, ... }` result hashes
13
+ - 13 new specs for `find_expired`, `delete_task`, and `expire_queued`
14
+ - Guard clauses on `include` statements for standalone loading
15
+
16
+ ## [0.1.0]
17
+
18
+ ### Added
19
+ - Initial release
data/CLAUDE.md ADDED
@@ -0,0 +1,64 @@
1
+ # lex-task_pruner: Task History Cleanup for LegionIO
2
+
3
+ **Repository Level 3 Documentation**
4
+ - **Parent**: `/Users/miverso2/rubymine/legion/extensions-core/CLAUDE.md`
5
+ - **Grandparent**: `/Users/miverso2/rubymine/legion/CLAUDE.md`
6
+
7
+ ## Purpose
8
+
9
+ Legion Extension that prunes old task history records from the LegionIO database. Runs periodically to prevent unbounded growth of task logs and status records. Requires `legion-data` (`data_required? true`).
10
+
11
+ **GitHub**: https://github.com/LegionIO/task_pruner
12
+ **License**: MIT
13
+ **Version**: 0.1.1
14
+
15
+ ## Architecture
16
+
17
+ ```
18
+ Legion::Extensions::TaskPruner
19
+ └── Runners/
20
+ └── Prune # Task cleanup logic (no explicit actor - auto-generated subscription)
21
+ ├── find_expired # Delete tasks older than N days (default: 31), limited batch size
22
+ ├── delete_task # Delete a specific task by task_id
23
+ └── expire_queued # Mark stuck queued tasks as task.expired
24
+ ```
25
+
26
+ No explicit actors directory - the framework auto-generates a subscription actor for the Prune runner.
27
+
28
+ ## Key Files
29
+
30
+ | Path | Purpose |
31
+ |------|---------|
32
+ | `lib/legion/extensions/task_pruner.rb` | Entry point (`data_required? true`) |
33
+ | `lib/legion/extensions/task_pruner/runners/prune.rb` | Pruning logic |
34
+
35
+ ## Runner Details
36
+
37
+ **`find_expired(age: 31, limit: 1000, status: ['task.completed'], **)`**
38
+ Deletes task records older than `age` days using `Sequel.lit('created <= ?', cutoff)` for cross-DB compatibility. Runs in batches up to `limit`. Status filter is applied unless `status` is `'*'`, `nil`, or empty string.
39
+
40
+ **`delete_task(task_id:, **)`**
41
+ Deletes a specific task by primary key. Returns `{ success: false, error: 'task not found' }` if missing.
42
+
43
+ **`expire_queued(age: 1, limit: 10, **)`**
44
+ Finds tasks stuck in `conditioner.queued`, `transformer.queued`, or `task.queued` status older than `age` days and updates their status to `task.expired`.
45
+
46
+ ## Dependencies
47
+
48
+ | Gem | Purpose |
49
+ |-----|---------|
50
+ | `legion-data` | Database access for task history tables |
51
+
52
+ ## Testing
53
+
54
+ ```bash
55
+ bundle install
56
+ bundle exec rspec
57
+ bundle exec rubocop
58
+ ```
59
+
60
+ Spec count: 14 examples
61
+
62
+ ---
63
+
64
+ **Maintained By**: Matthew Iverson (@Esity)
data/Dockerfile ADDED
@@ -0,0 +1,8 @@
1
+ FROM legionio/legion:latest
2
+ LABEL maintainer="Matthew Iverson <matthewdiverson@gmail.com>"
3
+
4
+ RUN apk update && apk add build-base tzdata postgresql-dev mysql-client mariadb-dev tzdata gcc git
5
+
6
+ COPY . ./
7
+ RUN gem install lex-task_pruner legion-data --no-document --no-prerelease
8
+ CMD ruby --yjit $(which legionio)
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+ group :test do
7
+ gem 'rake'
8
+ gem 'rspec'
9
+ gem 'rspec_junit_formatter'
10
+ gem 'rubocop'
11
+ gem 'simplecov'
12
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Esity
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # lex-task_pruner
2
+
3
+ Task history cleanup extension for [LegionIO](https://github.com/LegionIO/LegionIO). Prunes old task history records from the database to prevent unbounded growth of task logs and status records.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ gem install lex-task_pruner
9
+ ```
10
+
11
+ ## Functions
12
+
13
+ - **find_expired** - Delete completed tasks older than N days (default: 31 days, batch size: 1000)
14
+ - **delete_task** - Delete a specific task by ID
15
+ - **expire_queued** - Query tasks stuck in queued statuses (conditioner.queued, transformer.queued, task.queued)
16
+
17
+ ## Configuration
18
+
19
+ `find_expired` accepts optional parameters:
20
+
21
+ | Parameter | Default | Description |
22
+ |-----------|---------|-------------|
23
+ | `age` | `31` | Delete tasks older than this many days |
24
+ | `limit` | `1000` | Maximum records to delete per run |
25
+ | `status` | `['task.completed']` | Status filter (currently not applied due to a bug - all records older than `age` days are deleted) |
26
+
27
+ ## Requirements
28
+
29
+ - Ruby >= 3.4
30
+ - [LegionIO](https://github.com/LegionIO/LegionIO) framework
31
+ - `legion-data` (database access required)
32
+
33
+ ## License
34
+
35
+ MIT
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/legion/extensions/task_pruner/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'lex-task_pruner'
7
+ spec.version = Legion::Extensions::TaskPruner::VERSION
8
+ spec.authors = ['Esity']
9
+ spec.email = ['matthewdiverson@gmail.com']
10
+
11
+ spec.summary = 'Prunes old task history from LegionIO'
12
+ spec.description = 'Prunes old task history from LegionIO'
13
+ spec.homepage = 'https://github.com/LegionIO/task_pruner'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 3.4'
16
+
17
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
19
+ end
20
+ spec.require_paths = ['lib']
21
+ spec.extra_rdoc_files = %w[README.md LICENSE CHANGELOG.md]
22
+ spec.metadata = {
23
+ 'bug_tracker_uri' => 'https://github.com/LegionIO/task_pruner/issues',
24
+ 'changelog_uri' => 'https://github.com/LegionIO/task_pruner/blob/main/CHANGELOG.md',
25
+ 'documentation_uri' => 'https://github.com/LegionIO/task_pruner',
26
+ 'homepage_uri' => 'https://github.com/LegionIO/task_pruner',
27
+ 'source_code_uri' => 'https://github.com/LegionIO/task_pruner',
28
+ 'wiki_uri' => 'https://github.com/LegionIO/task_pruner/wiki',
29
+ 'rubygems_mfa_required' => 'true'
30
+ }
31
+
32
+ spec.add_dependency 'legion-data'
33
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module TaskPruner
6
+ module Runners
7
+ module Prune
8
+ def find_expired(age: 31, limit: 1000, status: ['task.completed'], **)
9
+ log.debug("purging old completed tasks with an age > #{age} days, limit: #{limit}")
10
+ cutoff = Time.now - (age * 86_400)
11
+ dataset = Legion::Data::Model::Task
12
+ .where(Sequel.lit('created <= ?', cutoff))
13
+ .limit(limit)
14
+ dataset = dataset.where(status: status) unless ['*', nil, ''].include?(status)
15
+ count = dataset.count
16
+ log.debug("Deleting #{count} records") if count.positive?
17
+ dataset.delete
18
+ { success: true, deleted: count }
19
+ end
20
+
21
+ def delete_task(task_id:, **)
22
+ task = Legion::Data::Model::Task[task_id]
23
+ return { success: false, error: 'task not found' } unless task
24
+
25
+ task.delete
26
+ { success: true, task_id: task_id }
27
+ end
28
+
29
+ def expire_queued(age: 1, limit: 10, **)
30
+ cutoff = Time.now - (age * 86_400)
31
+ dataset = Legion::Data::Model::Task
32
+ .where(status: ['conditioner.queued', 'transformer.queued', 'task.queued'])
33
+ .where(Sequel.lit('created <= ?', cutoff))
34
+ .limit(limit)
35
+ count = dataset.count
36
+ dataset.update(status: 'task.expired') if count.positive?
37
+ { success: true, expired: count }
38
+ end
39
+
40
+ include Legion::Extensions::Helpers::Task if defined?(Legion::Extensions::Helpers::Task)
41
+ include Legion::Extensions::Helpers::Lex if defined?(Legion::Extensions::Helpers::Lex)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module TaskPruner
6
+ VERSION = '0.1.1'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/task_pruner/version'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module TaskPruner
8
+ extend Legion::Extensions::Core if Legion::Extensions.const_defined? :Core
9
+
10
+ def self.data_required?
11
+ true
12
+ end
13
+
14
+ def data_required?
15
+ true
16
+ end
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lex-task_pruner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Esity
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: legion-data
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ description: Prunes old task history from LegionIO
27
+ email:
28
+ - matthewdiverson@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files:
32
+ - CHANGELOG.md
33
+ - LICENSE
34
+ - README.md
35
+ files:
36
+ - ".github/workflows/ci.yml"
37
+ - ".gitignore"
38
+ - ".rspec"
39
+ - ".rubocop.yml"
40
+ - CHANGELOG.md
41
+ - CLAUDE.md
42
+ - Dockerfile
43
+ - Gemfile
44
+ - LICENSE
45
+ - README.md
46
+ - lex-task_pruner.gemspec
47
+ - lib/legion/extensions/task_pruner.rb
48
+ - lib/legion/extensions/task_pruner/runners/prune.rb
49
+ - lib/legion/extensions/task_pruner/version.rb
50
+ homepage: https://github.com/LegionIO/task_pruner
51
+ licenses:
52
+ - MIT
53
+ metadata:
54
+ bug_tracker_uri: https://github.com/LegionIO/task_pruner/issues
55
+ changelog_uri: https://github.com/LegionIO/task_pruner/blob/main/CHANGELOG.md
56
+ documentation_uri: https://github.com/LegionIO/task_pruner
57
+ homepage_uri: https://github.com/LegionIO/task_pruner
58
+ source_code_uri: https://github.com/LegionIO/task_pruner
59
+ wiki_uri: https://github.com/LegionIO/task_pruner/wiki
60
+ rubygems_mfa_required: 'true'
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.6.9
76
+ specification_version: 4
77
+ summary: Prunes old task history from LegionIO
78
+ test_files: []