rcron 0.1.0 → 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.
- data/CHANGELOG.rdoc +3 -0
 - data/{README.rdoc → README.markdown} +59 -50
 - data/VERSION +1 -1
 - data/lib/rcron/scheduler.rb +2 -1
 - data/lib/rcron/task.rb +2 -1
 - data/test/test_rcron.rb +2 -2
 - metadata +15 -15
 
    
        data/CHANGELOG.rdoc
    CHANGED
    
    
| 
         @@ -1,65 +1,74 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            # rcron
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            A simple cron-like scheduler for Ruby.
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
      
 5 
     | 
    
         
            +
            ## Installation
         
     | 
| 
      
 6 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 7 
     | 
    
         
            +
            gem install rcron
         
     | 
| 
      
 8 
     | 
    
         
            +
            ```
         
     | 
| 
       7 
9 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
      
 10 
     | 
    
         
            +
            ## Cron format
         
     | 
| 
       9 
11 
     | 
    
         
             
            As of now, most of the expressions except for ? and W are supported.
         
     | 
| 
       10 
12 
     | 
    
         | 
| 
       11 
13 
     | 
    
         
             
            http://en.wikipedia.org/wiki/Cron#Format
         
     | 
| 
       12 
14 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
               
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
               
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
      
 15 
     | 
    
         
            +
            ## Examples
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            ### Basic
         
     | 
| 
      
 18 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 19 
     | 
    
         
            +
            require 'rcron'
         
     | 
| 
      
 20 
     | 
    
         
            +
            rcron = RCron.new
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
            # Enqueue a task running every two minutes
         
     | 
| 
      
 23 
     | 
    
         
            +
            rcron.enq('task #1', '*/2 * * * *') do |task|
         
     | 
| 
      
 24 
     | 
    
         
            +
              # Task logic
         
     | 
| 
      
 25 
     | 
    
         
            +
              # ...
         
     | 
| 
      
 26 
     | 
    
         
            +
            end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
            # You can `enq' any number of tasks before starting rcron
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
            rcron.start
         
     | 
| 
      
 31 
     | 
    
         
            +
            ```
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            ### One-time only task
         
     | 
| 
      
 34 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 35 
     | 
    
         
            +
            rcron = RCron.new
         
     | 
| 
      
 36 
     | 
    
         
            +
            # will run once at 8pm next second friday
         
     | 
| 
      
 37 
     | 
    
         
            +
            rcron.enq('task #2', '0 8 * * fri#2') do |task|
         
     | 
| 
      
 38 
     | 
    
         
            +
              # Removes the task from the queue
         
     | 
| 
      
 39 
     | 
    
         
            +
              task.deq
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
              # Task logic
         
     | 
| 
      
 42 
     | 
    
         
            +
              # ...
         
     | 
| 
      
 43 
     | 
    
         
            +
            end
         
     | 
| 
      
 44 
     | 
    
         
            +
            rcron.start
         
     | 
| 
      
 45 
     | 
    
         
            +
            ```
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
            ### Options
         
     | 
| 
      
 48 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 49 
     | 
    
         
            +
            rcron = RCron.new
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
            # :exclusive - Only one instance of this task will run simultaneously.
         
     | 
| 
      
 52 
     | 
    
         
            +
            # :timeout   - Task will be terminated if it takes longer than the specified seconds.
         
     | 
| 
      
 53 
     | 
    
         
            +
            rcron.enq('Every ten-minutes during summer', 
         
     | 
| 
      
 54 
     | 
    
         
            +
                    '*/10 * * jun-aug *', 
         
     | 
| 
      
 55 
     | 
    
         
            +
                    :exclusive => true, 
         
     | 
| 
      
 56 
     | 
    
         
            +
                    :timeout => 1200) do |task|
         
     | 
| 
      
 57 
     | 
    
         
            +
              # Task logic
         
     | 
| 
      
 58 
     | 
    
         
            +
              # ...
         
     | 
| 
      
 59 
     | 
    
         
            +
            end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
            # log to $stderr instead of default $stdout
         
     | 
| 
      
 62 
     | 
    
         
            +
            rcron.start $stderr
         
     | 
| 
      
 63 
     | 
    
         
            +
            ```
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
            ## Notes
         
     | 
| 
       57 
66 
     | 
    
         
             
            - Minimum interval for each task is one-minute just like cron. So rcron usually sleeps most of the time and wakes up only once a minute. (Except when short timeouts for the tasks are specified. In that case, rcron wakes up more frequently to check whether the task should be terminated)
         
     | 
| 
       58 
67 
     | 
    
         
             
            - rcron checks to start tasks at the very first second of every minute. e.g. When you first start it at 12:00:45, it will sleep 15 seconds before doing anything.
         
     | 
| 
       59 
68 
     | 
    
         
             
            - Tested on Ruby 1.8.7, Ruby 1.9.2 and JRuby 1.6.4
         
     | 
| 
       60 
69 
     | 
    
         
             
            - 99.67% test coverage. (a false sense of security, though)
         
     | 
| 
       61 
70 
     | 
    
         | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
      
 71 
     | 
    
         
            +
            ## Contributing to rcron
         
     | 
| 
       63 
72 
     | 
    
         
             
            * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
         
     | 
| 
       64 
73 
     | 
    
         
             
            * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
         
     | 
| 
       65 
74 
     | 
    
         
             
            * Fork the project
         
     | 
| 
         @@ -68,7 +77,7 @@ http://en.wikipedia.org/wiki/Cron#Format 
     | 
|
| 
       68 
77 
     | 
    
         
             
            * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
         
     | 
| 
       69 
78 
     | 
    
         
             
            * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
         
     | 
| 
       70 
79 
     | 
    
         | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
      
 80 
     | 
    
         
            +
            ## Copyright
         
     | 
| 
       72 
81 
     | 
    
         | 
| 
       73 
82 
     | 
    
         
             
            Copyright (c) 2011 Junegunn Choi. See LICENSE.txt for
         
     | 
| 
       74 
83 
     | 
    
         
             
            further details.
         
     | 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0.1. 
     | 
| 
      
 1 
     | 
    
         
            +
            0.1.1
         
     | 
    
        data/lib/rcron/scheduler.rb
    CHANGED
    
    | 
         @@ -14,7 +14,7 @@ class RCron 
     | 
|
| 
       14 
14 
     | 
    
         
             
              # @param [String] schedule Cron-format schedule string
         
     | 
| 
       15 
15 
     | 
    
         
             
              # @param [Hash] options Additional options for the task. :exclusive and :timeout.
         
     | 
| 
       16 
16 
     | 
    
         
             
              # @return [RCron::Task]
         
     | 
| 
       17 
     | 
    
         
            -
              def  
     | 
| 
      
 17 
     | 
    
         
            +
              def enq name, schedule, options = {}, &block
         
     | 
| 
       18 
18 
     | 
    
         
             
                raise ArgumentError.new("Block not given") unless block_given?
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
                new_task = nil
         
     | 
| 
         @@ -26,6 +26,7 @@ class RCron 
     | 
|
| 
       26 
26 
     | 
    
         
             
                end
         
     | 
| 
       27 
27 
     | 
    
         
             
                return new_task
         
     | 
| 
       28 
28 
     | 
    
         
             
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
              alias q enq
         
     | 
| 
       29 
30 
     | 
    
         | 
| 
       30 
31 
     | 
    
         
             
              # Starts the scheduler
         
     | 
| 
       31 
32 
     | 
    
         
             
              # @param log_output_stream Stream to output scheduler log. Should implement puts method.
         
     | 
    
        data/lib/rcron/task.rb
    CHANGED
    
    
    
        data/test/test_rcron.rb
    CHANGED
    
    | 
         @@ -45,10 +45,10 @@ class TestRcron < Test::Unit::TestCase 
     | 
|
| 
       45 
45 
     | 
    
         
             
                  task.dq
         
     | 
| 
       46 
46 
     | 
    
         
             
                end
         
     | 
| 
       47 
47 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
                @task = rcron. 
     | 
| 
      
 48 
     | 
    
         
            +
                @task = rcron.enq('basic task 2 - auto dq', "* * * * *") do
         
     | 
| 
       49 
49 
     | 
    
         
             
                  counter += 2
         
     | 
| 
       50 
50 
     | 
    
         
             
                  sleep 3
         
     | 
| 
       51 
     | 
    
         
            -
                  @task. 
     | 
| 
      
 51 
     | 
    
         
            +
                  @task.deq
         
     | 
| 
       52 
52 
     | 
    
         
             
                end
         
     | 
| 
       53 
53 
     | 
    
         | 
| 
       54 
54 
     | 
    
         
             
                st = Time.now
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: rcron
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.1
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,11 +9,11 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2011- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2011-09-06 00:00:00.000000000Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: yard
         
     | 
| 
       16 
     | 
    
         
            -
              requirement: & 
     | 
| 
      
 16 
     | 
    
         
            +
              requirement: &2153035480 !ruby/object:Gem::Requirement
         
     | 
| 
       17 
17 
     | 
    
         
             
                none: false
         
     | 
| 
       18 
18 
     | 
    
         
             
                requirements:
         
     | 
| 
       19 
19 
     | 
    
         
             
                - - ~>
         
     | 
| 
         @@ -21,10 +21,10 @@ dependencies: 
     | 
|
| 
       21 
21 
     | 
    
         
             
                    version: 0.6.0
         
     | 
| 
       22 
22 
     | 
    
         
             
              type: :development
         
     | 
| 
       23 
23 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       24 
     | 
    
         
            -
              version_requirements: * 
     | 
| 
      
 24 
     | 
    
         
            +
              version_requirements: *2153035480
         
     | 
| 
       25 
25 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       26 
26 
     | 
    
         
             
              name: bundler
         
     | 
| 
       27 
     | 
    
         
            -
              requirement: & 
     | 
| 
      
 27 
     | 
    
         
            +
              requirement: &2153034680 !ruby/object:Gem::Requirement
         
     | 
| 
       28 
28 
     | 
    
         
             
                none: false
         
     | 
| 
       29 
29 
     | 
    
         
             
                requirements:
         
     | 
| 
       30 
30 
     | 
    
         
             
                - - ~>
         
     | 
| 
         @@ -32,10 +32,10 @@ dependencies: 
     | 
|
| 
       32 
32 
     | 
    
         
             
                    version: 1.0.0
         
     | 
| 
       33 
33 
     | 
    
         
             
              type: :development
         
     | 
| 
       34 
34 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       35 
     | 
    
         
            -
              version_requirements: * 
     | 
| 
      
 35 
     | 
    
         
            +
              version_requirements: *2153034680
         
     | 
| 
       36 
36 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       37 
37 
     | 
    
         
             
              name: jeweler
         
     | 
| 
       38 
     | 
    
         
            -
              requirement: & 
     | 
| 
      
 38 
     | 
    
         
            +
              requirement: &2153033680 !ruby/object:Gem::Requirement
         
     | 
| 
       39 
39 
     | 
    
         
             
                none: false
         
     | 
| 
       40 
40 
     | 
    
         
             
                requirements:
         
     | 
| 
       41 
41 
     | 
    
         
             
                - - ~>
         
     | 
| 
         @@ -43,10 +43,10 @@ dependencies: 
     | 
|
| 
       43 
43 
     | 
    
         
             
                    version: 1.6.4
         
     | 
| 
       44 
44 
     | 
    
         
             
              type: :development
         
     | 
| 
       45 
45 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       46 
     | 
    
         
            -
              version_requirements: * 
     | 
| 
      
 46 
     | 
    
         
            +
              version_requirements: *2153033680
         
     | 
| 
       47 
47 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       48 
48 
     | 
    
         
             
              name: rcov
         
     | 
| 
       49 
     | 
    
         
            -
              requirement: & 
     | 
| 
      
 49 
     | 
    
         
            +
              requirement: &2153032540 !ruby/object:Gem::Requirement
         
     | 
| 
       50 
50 
     | 
    
         
             
                none: false
         
     | 
| 
       51 
51 
     | 
    
         
             
                requirements:
         
     | 
| 
       52 
52 
     | 
    
         
             
                - - ! '>='
         
     | 
| 
         @@ -54,10 +54,10 @@ dependencies: 
     | 
|
| 
       54 
54 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       55 
55 
     | 
    
         
             
              type: :development
         
     | 
| 
       56 
56 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       57 
     | 
    
         
            -
              version_requirements: * 
     | 
| 
      
 57 
     | 
    
         
            +
              version_requirements: *2153032540
         
     | 
| 
       58 
58 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       59 
59 
     | 
    
         
             
              name: simplecov
         
     | 
| 
       60 
     | 
    
         
            -
              requirement: & 
     | 
| 
      
 60 
     | 
    
         
            +
              requirement: &2153029720 !ruby/object:Gem::Requirement
         
     | 
| 
       61 
61 
     | 
    
         
             
                none: false
         
     | 
| 
       62 
62 
     | 
    
         
             
                requirements:
         
     | 
| 
       63 
63 
     | 
    
         
             
                - - ! '>='
         
     | 
| 
         @@ -65,21 +65,21 @@ dependencies: 
     | 
|
| 
       65 
65 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       66 
66 
     | 
    
         
             
              type: :development
         
     | 
| 
       67 
67 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       68 
     | 
    
         
            -
              version_requirements: * 
     | 
| 
      
 68 
     | 
    
         
            +
              version_requirements: *2153029720
         
     | 
| 
       69 
69 
     | 
    
         
             
            description: A simple cron-like scheduler for Ruby
         
     | 
| 
       70 
70 
     | 
    
         
             
            email: junegunn.c@gmail.com
         
     | 
| 
       71 
71 
     | 
    
         
             
            executables: []
         
     | 
| 
       72 
72 
     | 
    
         
             
            extensions: []
         
     | 
| 
       73 
73 
     | 
    
         
             
            extra_rdoc_files:
         
     | 
| 
       74 
74 
     | 
    
         
             
            - LICENSE.txt
         
     | 
| 
       75 
     | 
    
         
            -
            - README. 
     | 
| 
      
 75 
     | 
    
         
            +
            - README.markdown
         
     | 
| 
       76 
76 
     | 
    
         
             
            files:
         
     | 
| 
       77 
77 
     | 
    
         
             
            - .document
         
     | 
| 
       78 
78 
     | 
    
         
             
            - CHANGELOG.rdoc
         
     | 
| 
       79 
79 
     | 
    
         
             
            - Gemfile
         
     | 
| 
       80 
80 
     | 
    
         
             
            - Gemfile.lock
         
     | 
| 
       81 
81 
     | 
    
         
             
            - LICENSE.txt
         
     | 
| 
       82 
     | 
    
         
            -
            - README. 
     | 
| 
      
 82 
     | 
    
         
            +
            - README.markdown
         
     | 
| 
       83 
83 
     | 
    
         
             
            - Rakefile
         
     | 
| 
       84 
84 
     | 
    
         
             
            - VERSION
         
     | 
| 
       85 
85 
     | 
    
         
             
            - lib/rcron.rb
         
     | 
| 
         @@ -107,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       107 
107 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       108 
108 
     | 
    
         
             
                  segments:
         
     | 
| 
       109 
109 
     | 
    
         
             
                  - 0
         
     | 
| 
       110 
     | 
    
         
            -
                  hash: - 
     | 
| 
      
 110 
     | 
    
         
            +
                  hash: -994378731135453233
         
     | 
| 
       111 
111 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       112 
112 
     | 
    
         
             
              none: false
         
     | 
| 
       113 
113 
     | 
    
         
             
              requirements:
         
     |