djinn 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -45,7 +45,7 @@ Assuming you didn't sleep there your script would end and the daemon would
45
45
  detach and run in the background until it dies or gets killed. You can wrap
46
46
  argument parsing around that if you want, or do it in any other way. By default
47
47
  the daemon will look for a config YAML file in same directory as you executed it
48
- from, named the same as the Djinn class, so in this case _basic.yml_. It will by
48
+ from, named the same as the Djinn class, so in this case *basic.yml*. It will by
49
49
  default create the pid and log files in the same way. You can change this by
50
50
  putting it in the config file or supplying an options hash:
51
51
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{djinn}
8
- s.version = "0.0.7"
8
+ s.version = "0.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Craig Paterson"]
@@ -1,3 +1,4 @@
1
+ require 'yaml'
1
2
  require 'djinn/base'
2
3
 
3
4
  # This is a base implementation which handles looking for config
@@ -31,25 +31,27 @@ module Djinn
31
31
  end
32
32
 
33
33
  # Starts the Djinn in the background
34
- def start config={}
35
- @config = (config.empty?) ? load_config : config.empty?
34
+ def start config={}, &block
35
+ @config = (config.empty?) ? load_config : config
36
36
  log "Starting #{name} in the background.."
37
37
  logfile = get_logfile(config)
38
38
  daemonize(logfile, get_pidfile(config)) do
39
+ yield if block_given?
39
40
  trap('TERM') { handle_exit }
40
41
  trap('INT') { handle_exit }
41
- perform(config)
42
+ perform(@config)
42
43
  end
43
44
  end
44
45
 
45
46
  # Starts the Djinn in the foreground, which is often useful for
46
47
  # testing or other noble pursuits
47
- def run config={}
48
- @config = (config.empty?) ? load_config : config.empty?
48
+ def run config={}, &block
49
+ @config = (config.empty?) ? load_config : config
49
50
  log "Starting #{name} in the foreground.."
50
51
  trap('TERM') { handle_exit }
51
52
  trap('INT') { handle_exit }
52
- perform(config)
53
+ yield if block_given?
54
+ perform(@config)
53
55
  end
54
56
 
55
57
  # Convenience method, really just calls *stop* and then *start* for you :P
@@ -61,7 +63,7 @@ module Djinn
61
63
  # Stops the Djinn, unless you change the location of the pid file, in
62
64
  # which case its all about you and the *kill* command
63
65
  def stop config={}
64
- @config = (config.empty?) ? load_config : config.empty?
66
+ @config = (config.empty?) ? load_config : config
65
67
  pidfile = get_pidfile(@config)
66
68
  log 'No such process' and exit unless pidfile.pid
67
69
  begin
@@ -1,5 +1,10 @@
1
1
  module Djinn
2
2
  module Logging
3
+
4
+ def djinn_log msg
5
+ puts "#{Time.now.strftime("%m/%d/%Y %H:%M:%S")}: #{msg}"
6
+ STDOUT.flush
7
+ end
3
8
 
4
9
  def log msg
5
10
  puts "#{Time.now.strftime("%m/%d/%Y %H:%M:%S")}: #{msg}"
@@ -1,5 +1,6 @@
1
1
  $:.unshift(File.join(File.dirname(__FILE__)))
2
2
 
3
+ require 'yaml'
3
4
  require 'rails/handlers'
4
5
 
5
6
  module Djinn
@@ -21,7 +22,7 @@ module Djinn
21
22
  end
22
23
 
23
24
  end
24
-
25
+
25
26
  private
26
27
 
27
28
  def get_pidfile(config)
@@ -6,8 +6,9 @@ module Djinn
6
6
 
7
7
  def go args=[]
8
8
  action = parse_args(args)
9
- load_rails unless %w(stop restart).include?(action)
10
- self.new.__send__(action.intern)
9
+ self.new.__send__(action.intern) do
10
+ load_rails unless %w(stop restart).include?(action)
11
+ end
11
12
  end
12
13
 
13
14
  private
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: djinn
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Craig Paterson