beanworker 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.0.3 2011-10-24
2
+
3
+ * 1 major enhancement:
4
+ * added error logging
5
+
1
6
  === 0.0.2 2011-10-24
2
7
 
3
8
  * 1 major enhancement:
data/README.rdoc CHANGED
@@ -49,7 +49,9 @@ jobs.rb:
49
49
  schedule :scheduled_job, 2*24*3600, at: '04:30', timeout: 3600, { param1: 'some_value' }
50
50
  end
51
51
 
52
- SlowWorker.perform 2, :some_job.
52
+ SomeWorker.logger = AnotherWorker.logger = Logger.new('/var/log/somelog.log')
53
+
54
+ SomeWorker.perform 2, :some_job.
53
55
  :another_job
54
56
 
55
57
  AnotherWorker.perform 1, :scheduled_jov
data/lib/beanworker.rb CHANGED
@@ -4,7 +4,7 @@ require 'beanqueue'
4
4
  require File.dirname(__FILE__) + '/beanworker/worker'
5
5
 
6
6
  module Beanworker
7
- VERSION = '0.0.2'
7
+ VERSION = '0.0.3'
8
8
 
9
9
  class << self
10
10
  attr_accessor :connection_config
@@ -9,7 +9,8 @@ module Beanworker
9
9
  num.times do
10
10
  Thread.new do
11
11
  connection = Beanqueue.connect Beanworker.connection_config
12
- tubes.each { |tube| connection.watch(tube.gsub('_', '.')) }
12
+ tubes.each { |tube| connection.watch(tube.to_s.gsub('_', '.')) }
13
+ logger.info("Listening: #{tubes.inspect}") if logger
13
14
  loop do
14
15
  get_one_job connection
15
16
  end
@@ -23,15 +24,19 @@ module Beanworker
23
24
  Thread.new do
24
25
  loop do
25
26
  sleep(at - Time.now)
26
- Timeout.timeout timeout_secs do
27
- self.send(name, *args)
28
- end
27
+ work_job(name, timeout_secs, args, @need_fork)
29
28
  at += frequency
30
29
  end
31
30
  end
32
31
  end
33
32
 
34
- private
33
+ def logger=(l)
34
+ @logger = l
35
+ end
36
+
37
+ def fork_default(val)
38
+ @need_fork = val
39
+ end
35
40
 
36
41
  def get_one_job(connection)
37
42
  job = connection.reserve
@@ -41,7 +46,8 @@ module Beanworker
41
46
  job.delete
42
47
  rescue SystemExit
43
48
  raise
44
- rescue
49
+ rescue => e
50
+ logger.error(e.backtrace.unshift(e.message)) if logger
45
51
  job.bury rescue nil
46
52
  end
47
53
 
@@ -61,10 +67,6 @@ module Beanworker
61
67
  end
62
68
  end
63
69
 
64
- def fork_default(val)
65
- @need_fork = val
66
- end
67
-
68
70
  def make_first_schedule(frequency, at)
69
71
  if at && (frequency % (24*3600) == 0)
70
72
  t = Time.parse at
@@ -73,5 +75,9 @@ module Beanworker
73
75
  Time.now + frequency
74
76
  end
75
77
  end
78
+
79
+ def logger
80
+ @logger ||= Logger.new(STDOUT)
81
+ end
76
82
  end
77
83
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beanworker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-10-24 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: beanstalk-client
16
- requirement: &15411580 !ruby/object:Gem::Requirement
16
+ requirement: &7708700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *15411580
24
+ version_requirements: *7708700
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: beanqueue
27
- requirement: &15410040 !ruby/object:Gem::Requirement
27
+ requirement: &7705900 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.1.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *15410040
35
+ version_requirements: *7705900
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: hoe
38
- requirement: &15407500 !ruby/object:Gem::Requirement
38
+ requirement: &7704520 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '2.12'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *15407500
46
+ version_requirements: *7704520
47
47
  description: ! 'It is a worker-side Beanstalk-based job-queueing dispatcher
48
48
 
49
49
  This is a pre-release, I will complete tests and docs in couple days'