README.md in ruby-clock-0.7.0 vs README.md in ruby-clock-0.8.0.rc1

- old
+ new

@@ -69,10 +69,16 @@ To run your clock process in your app's environment: bundle exec rails runner bin/clock +To get smarter database connection management (such as in the case of a database restart or upgrade, +and maybe other benefits) and code reloading in dev (app code, not the code in Clockfile itself), +jobs are automatically wrapped in the +[rails app reloader](https://guides.rubyonrails.org/threading_and_code_execution.html). + + ### Non-Rails Require your app's code at the top of Clockfile: ```ruby @@ -120,10 +126,50 @@ You can define before, after, and around callbacks which will run for all jobs. Read [the rufus-scheduler documentation](https://github.com/jmettraux/rufus-scheduler/#callbacks) to learn how to do this. Where the documentation references `s`, you should use `schedule`. +### Shell commands + +You can run shell commands in your jobs. They are invoked using +[posix-spawn](https://github.com/rtomayko/posix-spawn), which means +the ruby process is not forked. + +```ruby +schedule.every '1 day' do + shell('sh scripts/process_stuff.sh') +end +``` + +`shell` is a very simple convenience method which is implemented with +[terrapin](https://github.com/thoughtbot/terrapin). If you want to use other terrapin +features you can do so: + +```ruby +schedule.every '1 day' do + line = Terrapin::CommandLine.new('optimize_png', ":file") + Organization.with_new_logos.find_each do |o| + line.run(file: o.logo_file_path) + o.update!(logo_optimized: true) + end +end +``` + +### Rake tasks + +You can run tasks from within the persistent runtime of ruby-clock, without +needing to shell out and start another process. + +```ruby +schedule.every '1 day' do + rake('reports:daily') +end +``` + +There is also `rake_execute` and `rake_async`. See [the code](https://github.com/jjb/ruby-clock/blob/main/lib/ruby-clock.rb) +and [this article](https://code.jjb.cc/running-rake-tasks-from-within-ruby-on-rails-code) for more info. + ### Job Identifier ruby-clock adds the `identifier` method to `Rufus::Scheduler::Job`. This method will return the job's [name](https://github.com/jmettraux/rufus-scheduler/#name--string) if one was given. If a name is not given, the last non-comment code line in the job's block @@ -131,23 +177,23 @@ fallback is the line number of the job in Clockfile. Some examples of jobs and their identifiers: ```ruby -schedule.every '1 second', name: 'my job' do |variable| +schedule.every '1 second', name: 'my job' do Foo.bar end # => my job -schedule.every '1 day' do |variable| +schedule.every '1 day' do daily_things = Foo.setup_daily daily_things.process # TODO: figure out best time of day end # => daily_things.process # n.b. ruby-clock isn't yet smart enough to remove trailing comments -schedule.every '1 week' do |variable| +schedule.every '1 week' do weekly_things = Foo.setup_weekly weekly_things.process # does this work???!1~ end # => weekly_things.process # does this work???!1~ ```