zscheduler 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,67 @@
1
+ require 'eventmachine'
2
+ require 'zscheduler/version'
3
+
4
+ module Zscheduler
5
+ class << self
6
+
7
+ def every(frequency,options = {}, &block)
8
+ block_given? or raise ArgumentError, "no block was given..."
9
+
10
+ reactor_running? or start_reactor
11
+
12
+ add_shutdown_hook block if options[:on_shutdown]
13
+
14
+ timers.push EM::PeriodicTimer.new(Integer frequency) do
15
+ options[:on_thread] ? Thread.new(&block) : block.call
16
+ end
17
+
18
+ timers.last
19
+ end
20
+
21
+ def now_and_every(*args,&block)
22
+ block.call & every(*args,&block)
23
+ end
24
+
25
+ def stop
26
+ timers.each(&:cancel)
27
+ shutdown_hooks.each(&:call)
28
+ wrapper and EM.stop
29
+ end
30
+
31
+ alias_method :showdown, :stop
32
+
33
+ def add_shutdown_hook(&block)
34
+ shutdown_hooks.push block
35
+ end
36
+
37
+ def join
38
+ EM.reactor_thread.join
39
+ end
40
+
41
+ private
42
+
43
+ def start_reactor
44
+ @wrapper = Thread.new { EventMachine.run }
45
+ wrapper.abort_on_exception = true
46
+ Thread.pass until reactor_running?
47
+ end
48
+
49
+ def reactor_running?
50
+ EventMachine.reactor_running?
51
+ end
52
+
53
+ def wrapper
54
+ @wrapper
55
+ end
56
+
57
+ def timers
58
+ @timers ||= []
59
+ end
60
+
61
+ def shutdown_hooks
62
+ @shutdown_hooks ||= []
63
+ end
64
+
65
+ end
66
+ end
67
+
@@ -0,0 +1,20 @@
1
+ class Numeric
2
+ {
3
+ :year => 365 * 24 * 3600,
4
+ :month => 30 * 24 * 3600,
5
+ :week => 7 * 24 * 3600,
6
+ :day => 24 * 3600,
7
+ :hour => 3600,
8
+ :minute => 60,
9
+ :second => 1
10
+ }.each do |m,val|
11
+ respond_to? m or define_method m do
12
+ self * val
13
+ end
14
+
15
+ "#{m}s".tap do |plural|
16
+ respond_to? plural or alias_method plural, m
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Zscheduler
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zscheduler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eran Barak Levi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: eventmachine
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: ! 'minimalistic scheduler on top of event-machine '
31
+ email: wtf@wtf.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - lib/zscheduler/core_ext/numeric.rb
37
+ - lib/zscheduler/version.rb
38
+ - lib/zscheduler.rb
39
+ homepage: http://github.com/eranb/zscheduler
40
+ licenses: []
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: 1.8.5
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project: zscheduler
59
+ rubygems_version: 1.8.25
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: minimalistic scheduler on top of event-machine
63
+ test_files: []