Class: MyEventMachineDojin

Inherits:
Object
  • Object
show all
Includes:
MyMachine
Defined in:
lib/lib/machine.rb

Instance Method Summary collapse

Methods included from MyMachine

#retry, #setup

Constructor Details

#initialize(args = { }) ⇒ MyEventMachineDojin

Returns a new instance of MyEventMachineDojin.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/lib/machine.rb', line 44

def initialize(args={ })
  super(args)
  @args = args
  @args[:start] ||= 3000
  @args[:stop] ||= 3100
  @args[:concurrency] ||= 10
  @args[:savedir] ||= "#{ENV['HOME']}/Downloads/jpg"
  @endbooks = []
  require 'rubygems'
  require 'eventmachine'
  @connection_count = 0
  require 'thread'
  @connection_que = Queue.new
  @list = []
  @gaman = 0
end

Instance Method Details

#connection_count!Object



83
84
85
# File 'lib/lib/machine.rb', line 83

def connection_count!
  @connection_que.push(:t)
end

#connection_end!Object



87
88
89
# File 'lib/lib/machine.rb', line 87

def connection_end!
  @connection_que.pop
end

#connection_exceed?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/lib/machine.rb', line 79

def connection_exceed?
  @args[:concurrency] <= @connection_que.size
end

#goObject

EventMachine用の定義



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/lib/machine.rb', line 62

def go
  EM.run do
    EM.add_periodic_timer(0.00001) do
      print "."
      EM.stop if should_stop_machine?
      if !connection_exceed?
        unless @queue.empty?
          job = @queue.pop
          job.run if job
        end
      end
    end
  end
  p @endbooks.uniq!.sort if @debug
  puts "End of fetch".green.bold
end

#savecontent(path) ⇒ Object



91
92
93
# File 'lib/lib/machine.rb', line 91

def savecontent(path)
  @list <<  path
end

#writeObject



95
96
97
98
99
100
101
# File 'lib/lib/machine.rb', line 95

def write
  open("#{@args[:savedir]}/emit.txt" ,"w") do |io|
    io.write('["')
    io.write(@list.sort.join('","'))
    io.write('"]')
  end
end