Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kostya/bin_script
Easy writing and executing bins(executable scripts) in Rails Application (especially for crontab or god). For my purposes much better than Rake, Thor and Rails Runner.
https://github.com/kostya/bin_script
Last synced: 4 days ago
JSON representation
Easy writing and executing bins(executable scripts) in Rails Application (especially for crontab or god). For my purposes much better than Rake, Thor and Rails Runner.
- Host: GitHub
- URL: https://github.com/kostya/bin_script
- Owner: kostya
- License: mit
- Created: 2012-04-07T12:47:33.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-08-24T11:40:27.000Z (about 11 years ago)
- Last Synced: 2024-11-02T13:34:05.996Z (11 days ago)
- Language: Ruby
- Homepage:
- Size: 103 KB
- Stars: 6
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Rails BinScript
===============Gem for easy writing and executing scripts in Rails Application. For my purposes much better than Rake, Thor and Rails Runner.
Features:
1. Each bin is a class
2. Easy writing tests
3. Custom lock file
4. Custom logger with formatter for each script
5. Can be daemonizedTested on Rails 2.3 and 3.2
``` ruby
gem 'bin_script'
```rails generate bin:bin bla
Call like:
$ cd project && ./bin/bla -e production --test -d "2012-04-07" -u "asdf"
Call examples:
$ ./bin/bla -h
$ ./bin/bla -e production
$ ./bin/bla -e production -L ./locks/bla.lock
$ ./bin/bla -e production -l ./log/bla.log
$ ./bin/bla -e production --daemonize --pidfile ./tmp/bla.pidExample Bin
-----------
app/bins/bla_script.rb``` ruby
class BlaScript < BinScript
optional :u, "Update string"
required :d, :description => "Date in format YYYY-MM-DD or YYYY-MM", :default => "2012-04-01"
noarg :t, :decription => "Test run", :alias => 'test'self.description = "Super Bla script"
def test?
params(:t)
enddef do!
if test?
logger.info "update string #{params(:u)}"
else
logger.info "data #{params(:d)}"
end
end
end
```### Options
``` ruby
class BlaScript < BinScript
self.log_level = Logger::DEBUG
self.enable_locking = false
self.enable_logging = false
end
```### Custom exception notifier (create initializer with:)
``` ruby
class BinScript
def notify_about_error(exception)
Mailter.some_notification(exception)...
end
end
```