script_tracker 0.1.0 → 0.1.3

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: 6c4624d6b1fc0ede5e5691a6ec4b2ced79513620505434524b9d1d980e93d4ca
4
- data.tar.gz: 427a3b57e4fe3436db63864e7a9d323f285c4ad5d1c763c15813a9da92c2d43d
3
+ metadata.gz: 1035933e320fe159fddb60f9f99e67f3d707250f8e6ba1901460973995df3567
4
+ data.tar.gz: 203bb6d7a9139e9e9069b0f98017cbe1e682a52c9f7fef67f6ccde5dc503a607
5
5
  SHA512:
6
- metadata.gz: 776ff4218886ee763f1b93d8212dfae35c68fa2f685f89a2664d642b4934ace4a1a0c3260bd692b7688c3cfc58864dd812329f24161ac91462b5d2ee92cf183a
7
- data.tar.gz: 1ce7a1b8dc3b65888dbe2e9117b4cb06b3e31d0ff24f195d2e4bdb66d9b1782a2bd2441df09b66ff2aa4e8cb9ace86068bd0bb5af9c81051b2a90d325f1be7cf
6
+ metadata.gz: 6a48bc5347dfdb40f412bff93e89a872e6a07756643e705f2f6a49232b5eed14ca742c229254ffd6759142b5444d57d1753d4ef74f2e74bf58d945baa051ed7e
7
+ data.tar.gz: 71a2e8e39d6a20d0da06517d43f190fe6811ca5164115a2c4171238b6900ecad0bebd2cdf3d93430e4161d171ba68219d0720a3464fba238a592681c813af05f
data/CHANGELOG.md CHANGED
@@ -7,24 +7,42 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.1.3] - 2025-01-17
11
+
12
+ ### Changed
13
+ - Simplified and streamlined README documentation
14
+ - Cleaned up CHANGELOG format
15
+
16
+ ## [0.1.2] - 2025-01-17
17
+
18
+ ### Fixed
19
+ - Updated GitHub Actions workflows to use v4 actions
20
+ - Fixed GitHub release permissions
21
+ - Refactored workflows to match successful gem release pattern
22
+
23
+ ## [0.1.1] - 2025-01-17
24
+
25
+ ### Added
26
+ - CI/CD workflows for automated testing and releases
27
+ - GitHub Actions workflow for automatic releases on tag push
28
+ - Manual release workflow via GitHub Actions UI
29
+ - Local release script (`bin/release`)
30
+
10
31
  ## [0.1.0] - 2025-01-17
11
32
 
12
33
  ### Added
13
- - Initial release of ScriptTracker
34
+ - Initial release
14
35
  - Script execution tracking with status management
15
36
  - Transaction support for script execution
16
37
  - Built-in logging and progress tracking
17
38
  - Batch processing helpers
18
39
  - Timeout support for long-running scripts
19
40
  - Stale script cleanup functionality
20
- - Rake tasks for managing scripts:
21
- - `scripts:create` - Create new scripts
22
- - `scripts:run` - Run pending scripts
23
- - `scripts:status` - View script status
24
- - `scripts:rollback` - Rollback scripts
25
- - `scripts:cleanup` - Cleanup stale scripts
41
+ - Rake tasks for managing scripts
26
42
  - Comprehensive RSpec test suite
27
- - Full documentation and examples
28
43
 
29
- [Unreleased]: https://github.com/blink-global/script_tracker/compare/v0.1.0...HEAD
30
- [0.1.0]: https://github.com/blink-global/script_tracker/releases/tag/v0.1.0
44
+ [Unreleased]: https://github.com/a-abdellatif98/script_tracker/compare/v0.1.3...HEAD
45
+ [0.1.3]: https://github.com/a-abdellatif98/script_tracker/compare/v0.1.2...v0.1.3
46
+ [0.1.2]: https://github.com/a-abdellatif98/script_tracker/compare/v0.1.1...v0.1.2
47
+ [0.1.1]: https://github.com/a-abdellatif98/script_tracker/compare/v0.1.0...v0.1.1
48
+ [0.1.0]: https://github.com/a-abdellatif98/script_tracker/releases/tag/v0.1.0
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Blink
3
+ Copyright (c) 2025 Ahmed Abd El-Latif
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,276 +1,167 @@
1
1
  # ScriptTracker
2
2
 
3
- ScriptTracker is a Ruby gem that provides a migration-like system for managing one-off scripts in Rails applications. It tracks script execution history, provides transaction support, and includes built-in logging and progress tracking.
3
+ A Ruby gem that provides a migration-like system for managing one-off scripts in Rails applications with execution tracking, transaction support, and built-in logging.
4
4
 
5
5
  ## Features
6
6
 
7
- - **Execution Tracking**: Automatically tracks which scripts have been run and their status
8
- - **Transaction Support**: Wraps script execution in database transactions
9
- - **Status Management**: Track scripts as success, failed, running, or skipped
10
- - **Built-in Logging**: Convenient logging methods with timestamps
11
- - **Batch Processing**: Helper methods for processing large datasets efficiently
12
- - **Timeout Support**: Configure custom timeouts for long-running scripts
13
- - **Stale Script Cleanup**: Automatically identify and cleanup stuck scripts
14
- - **Migration Generator**: Generate timestamped script files with templates
7
+ * **Execution Tracking** - Automatically tracks which scripts have been run and their status
8
+ * **Transaction Support** - Wraps script execution in database transactions
9
+ * **Status Management** - Track scripts as success, failed, running, or skipped
10
+ * **Built-in Logging** - Convenient logging methods with timestamps
11
+ * **Batch Processing** - Helper methods for processing large datasets efficiently
12
+ * **Timeout Support** - Configure custom timeouts for long-running scripts
15
13
 
16
14
  ## Installation
17
15
 
18
- Add this line to your application's Gemfile:
16
+ Add to your Gemfile:
19
17
 
20
18
  ```ruby
21
19
  gem 'script_tracker'
22
20
  ```
23
21
 
24
- And then execute:
22
+ Then run:
25
23
 
26
24
  ```bash
27
25
  bundle install
28
- ```
29
-
30
- Or install it yourself as:
31
-
32
- ```bash
33
- gem install script_tracker
34
- ```
35
-
36
- ## Setup
37
-
38
- 1. Install the gem using the generator:
39
-
40
- ```bash
41
26
  rails generate script_tracker:install
42
- ```
43
-
44
- This will:
45
- - Create a migration for the `executed_scripts` table
46
- - Create the `lib/scripts` directory for your scripts
47
-
48
- 2. Run the migration:
49
-
50
- ```bash
51
27
  rails db:migrate
52
28
  ```
53
29
 
54
- 3. (Optional) Configure the scripts directory in an initializer:
55
-
56
- ```ruby
57
- # config/initializers/script_tracker.rb
58
- ScriptTracker.configure do |config|
59
- config.scripts_path = Rails.root.join('lib', 'scripts')
60
- end
61
- ```
62
-
63
- ## Usage
64
-
65
- ### Creating a New Script
30
+ ## Quick Start
66
31
 
67
- Generate a new script with a descriptive name:
32
+ ### Create a Script
68
33
 
69
34
  ```bash
70
35
  rake scripts:create["update user preferences"]
71
36
  ```
72
37
 
73
- This creates a timestamped script file in `lib/scripts/`:
38
+ This creates a timestamped script file in `lib/scripts/` :
74
39
 
75
40
  ```ruby
76
- # lib/scripts/20231117120000_update_user_preferences.rb
77
41
  module Scripts
78
42
  class UpdateUserPreferences < ScriptTracker::Base
79
43
  def self.execute
80
- log "Starting script: update user preferences"
81
-
82
- # Your script logic here
44
+ log "Starting script"
45
+
83
46
  User.find_each do |user|
84
47
  user.update!(preferences: { theme: 'dark' })
85
48
  end
86
-
87
- log "Script completed successfully"
49
+
50
+ log "Script completed"
88
51
  end
89
52
  end
90
53
  end
91
54
  ```
92
55
 
93
- ### Running Scripts
94
-
95
- Run all pending (not yet executed) scripts:
96
-
97
- ```bash
98
- rake scripts:run
99
- ```
100
-
101
- ### Checking Script Status
102
-
103
- View the status of all scripts:
104
-
105
- ```bash
106
- rake scripts:status
107
- ```
108
-
109
- Output:
110
- ```
111
- Scripts:
112
- [SUCCESS] 20231117120000_update_user_preferences.rb (2.5s)
113
- [PENDING] 20231117130000_cleanup_old_data.rb
114
- ```
115
-
116
- ### Rolling Back a Script
117
-
118
- Remove a script from execution history (allows it to be run again):
119
-
120
- ```bash
121
- rake scripts:rollback[20231117120000_update_user_preferences.rb]
122
- ```
123
-
124
- ### Cleaning Up Stale Scripts
125
-
126
- Mark scripts stuck in "running" status as failed:
56
+ ### Run Scripts
127
57
 
128
58
  ```bash
129
- rake scripts:cleanup
59
+ rake scripts:run # Run all pending scripts
60
+ rake scripts:status # View script status
61
+ rake scripts:rollback[filename] # Rollback a script
62
+ rake scripts:cleanup # Cleanup stale scripts
130
63
  ```
131
64
 
132
- ## Advanced Features
133
-
134
- ### Skipping Scripts
65
+ ## Advanced Usage
135
66
 
136
- Skip a script execution conditionally:
67
+ ### Skip Script Conditionally
137
68
 
138
69
  ```ruby
139
- module Scripts
140
- class ConditionalUpdate < ScriptTracker::Base
141
- def self.execute
142
- if User.where(needs_update: true).count.zero?
143
- skip! "No users need updating"
144
- end
145
-
146
- # Your script logic here
147
- end
148
- end
70
+ def self.execute
71
+ skip! "No users need updating" if User.where(needs_update: true).count.zero?
72
+ # Your logic here
149
73
  end
150
74
  ```
151
75
 
152
76
  ### Custom Timeout
153
77
 
154
- Override the default 5-minute timeout:
155
-
156
78
  ```ruby
157
- module Scripts
158
- class LongRunningScript < ScriptTracker::Base
159
- def self.timeout
160
- 3600 # 1 hour in seconds
161
- end
162
-
163
- def self.execute
164
- # Long-running logic here
165
- end
166
- end
79
+ def self.timeout
80
+ 3600 # 1 hour in seconds
167
81
  end
168
82
  ```
169
83
 
170
84
  ### Batch Processing
171
85
 
172
- Process large datasets efficiently:
173
-
174
86
  ```ruby
175
- module Scripts
176
- class ProcessUsers < ScriptTracker::Base
177
- def self.execute
178
- users = User.where(processed: false)
179
-
180
- process_in_batches(users, batch_size: 1000) do |user|
181
- user.update!(processed: true)
182
- end
183
- end
87
+ def self.execute
88
+ users = User.where(processed: false)
89
+ process_in_batches(users, batch_size: 1000) do |user|
90
+ user.update!(processed: true)
184
91
  end
185
92
  end
186
93
  ```
187
94
 
188
95
  ### Progress Logging
189
96
 
190
- Track progress during execution:
191
-
192
97
  ```ruby
193
- module Scripts
194
- class DataMigration < ScriptTracker::Base
195
- def self.execute
196
- total = User.count
197
- processed = 0
198
-
199
- User.find_each do |user|
200
- # Process user
201
- processed += 1
202
- log_progress(processed, total) if (processed % 100).zero?
203
- end
204
- end
98
+ def self.execute
99
+ total = User.count
100
+ processed = 0
101
+
102
+ User.find_each do |user|
103
+ # Process user
104
+ processed += 1
105
+ log_progress(processed, total) if (processed % 100).zero?
205
106
  end
206
107
  end
207
108
  ```
208
109
 
209
110
  ## API Reference
210
111
 
211
- ### ScriptTracker::Base
212
-
213
- Base class for all scripts.
112
+ ### ScriptTracker:: Base
214
113
 
215
114
  **Class Methods:**
115
+ * `execute` - Implement with your script logic (required)
116
+ * `timeout` - Override to set custom timeout (default: 300 seconds)
117
+ * `skip!(reason)` - Skip script execution
118
+ * `log(message, level: :info)` - Log a message
119
+ * `log_progress(current, total)` - Log progress percentage
120
+ * `process_in_batches(relation, batch_size: 1000, &block)` - Process in batches
216
121
 
217
- - `execute` - Implement this method with your script logic (required)
218
- - `run` - Execute the script with transaction and error handling
219
- - `timeout` - Override to set custom timeout (default: 300 seconds)
220
- - `skip!(reason)` - Skip script execution with optional reason
221
- - `log(message, level: :info)` - Log a message with timestamp
222
- - `log_progress(current, total, message = nil)` - Log progress percentage
223
- - `process_in_batches(relation, batch_size: 1000, &block)` - Process records in batches
122
+ ### ScriptTracker:: ExecutedScript
224
123
 
225
- ### ScriptTracker::ExecutedScript
124
+ **Scopes:** `successful` , `failed` , `running` , `skipped` , `completed` , `ordered` , `recent_first`
226
125
 
227
- ActiveRecord model for tracking script execution.
126
+ **Class Methods:**
127
+ * `executed?(filename)` - Check if script has been executed
128
+ * `cleanup_stale_running_scripts(older_than: 1.hour.ago)` - Clean up stale scripts
228
129
 
229
- **Scopes:**
130
+ ## Rake Tasks
230
131
 
231
- - `successful` - Scripts that completed successfully
232
- - `failed` - Scripts that failed
233
- - `running` - Scripts currently running
234
- - `skipped` - Scripts that were skipped
235
- - `completed` - Scripts that finished (success or failed)
236
- - `ordered` - Order by execution time ascending
237
- - `recent_first` - Order by execution time descending
132
+ * `rake scripts:create[description]` - Create a new script
133
+ * `rake scripts:run` - Run all pending scripts
134
+ * `rake scripts:status` - Show status of all scripts
135
+ * `rake scripts:rollback[filename]` - Rollback a script
136
+ * `rake scripts:cleanup` - Cleanup stale running scripts
238
137
 
239
- **Class Methods:**
138
+ ## Releasing
240
139
 
241
- - `executed?(filename)` - Check if a script has been executed
242
- - `mark_as_running(filename)` - Mark a script as running
243
- - `cleanup_stale_running_scripts(older_than: 1.hour.ago)` - Clean up stale scripts
140
+ ### GitHub Actions (Recommended)
244
141
 
245
- **Instance Methods:**
142
+ 1. Go to **Actions** → **Release** workflow
143
+ 2. Click **Run workflow**
144
+ 3. Enter version number (e.g., `0.1.3`)
246
145
 
247
- - `mark_success!(output, duration)` - Mark as successful
248
- - `mark_failed!(error, duration)` - Mark as failed
249
- - `mark_skipped!(output, duration)` - Mark as skipped
250
- - `success?`, `failed?`, `running?`, `skipped?` - Status predicates
251
- - `formatted_duration` - Human-readable duration
252
- - `formatted_output` - Truncated output text
253
- - `timeout_seconds` - Get timeout value
254
- - `timed_out?` - Check if script has timed out
255
-
256
- ## Rake Tasks
146
+ Or push a tag:
257
147
 
258
- - `rake scripts:create[description]` - Create a new script
259
- - `rake scripts:run` - Run all pending scripts
260
- - `rake scripts:status` - Show status of all scripts
261
- - `rake scripts:rollback[filename]` - Rollback a script
262
- - `rake scripts:cleanup` - Cleanup stale running scripts
148
+ ```bash
149
+ git tag -a v0.1.3 -m "Release version 0.1.3"
150
+ git push origin v0.1.3
151
+ ```
263
152
 
264
- ## Development
153
+ **Required:** Set `RUBYGEMS_AUTH_TOKEN` in GitHub repository secrets.
265
154
 
266
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
155
+ ### Local Release
267
156
 
268
- To install this gem onto your local machine, run `bundle exec rake install`.
157
+ ```bash
158
+ bin/release 0.1.3
159
+ ```
269
160
 
270
161
  ## Contributing
271
162
 
272
- Bug reports and pull requests are welcome on GitHub at https://github.com/blink-global/script_tracker.
163
+ Bug reports and pull requests welcome at https://github.com/a-abdellatif98/script_tracker.
273
164
 
274
165
  ## License
275
166
 
276
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
167
+ MIT License - see LICENSE file for details.
@@ -17,6 +17,6 @@ Next steps:
17
17
  rake scripts:status
18
18
 
19
19
  For more information, visit:
20
- https://github.com/blink-global/script_tracker
20
+ https://github.com/a-abdellatif98/script_tracker
21
21
 
22
22
  ===============================================================================
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ScriptTracker
4
- VERSION = "0.1.0"
4
+ VERSION = '0.1.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: script_tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ahmed Abd El-Latif
@@ -98,7 +98,7 @@ description: ScriptTracker provides a migration-like system for managing one-off
98
98
  with execution tracking, transaction support, and built-in logging. Perfect for
99
99
  data migrations, cleanup tasks, and administrative scripts.
100
100
  email:
101
- - ahmed.abdelatif@blink.com
101
+ - ahmed.abdelatife@gmail.com
102
102
  executables: []
103
103
  extensions: []
104
104
  extra_rdoc_files: []
@@ -117,11 +117,11 @@ files:
117
117
  - lib/script_tracker/version.rb
118
118
  - tasks/script_tracker.rake
119
119
  - templates/script_template.rb
120
- homepage: https://github.com/blink-global/script_tracker
120
+ homepage: https://github.com/a-abdellatif98/script_tracker
121
121
  licenses:
122
122
  - MIT
123
123
  metadata:
124
- homepage_uri: https://github.com/blink-global/script_tracker
124
+ homepage_uri: https://github.com/a-abdellatif98/script_tracker
125
125
  source_code_uri: https://github.com/a-abdellatif98/script_tracker
126
126
  changelog_uri: https://github.com/a-abdellatif98/script_tracker/blob/main/CHANGELOG.md
127
127
  post_install_message:
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
141
  requirements: []
142
- rubygems_version: 3.4.1
142
+ rubygems_version: 3.4.19
143
143
  signing_key:
144
144
  specification_version: 4
145
145
  summary: A Ruby gem for tracking and managing one-off script executions in Rails applications