module Meiriyigua

Constants

VERSION

Public Class Methods

__run() click to toggle source
# File lib/meiriyigua.rb, line 22
def __run
  Thread.abort_on_exception = true

  while true
    begin
      ((Meiriyigua::Models::UrlRecord.all(baidu_at: nil) | Meiriyigua::Models::UrlRecord.all(publish_at: nil)) & Meiriyigua::Models::UrlRecord.all(:detail_at.lt => (Date.today - 7))).each do |url_record|
        url_record.page_record.destroy
        url_record.destroy
      end

      Meiriyigua::Models::PageRecord.all(url_record: {:publish_at.not => nil}).destroy!

      threads = []
      threads << Thread.new do
        list_crawl = ListCrawl.new
        list_crawl.run
        detail_crawl = DetailCrawl.new(list_crawl.detail_urls)
        detail_crawl.run
        sleep(Meiriyigua::Config.update_time.to_i)
      end
      threads << Thread.new do
        baidu_crawl = BaiduCrawl.new
        baidu_crawl.run
        sleep(Meiriyigua::Config.update_time.to_i)
      end
      threads << Thread.new do
        if @type == 1
          post_client = PostClient.new
          post_client.run
        else
          post_client = PostClientTwo.new
          post_client.run
        end
        sleep(Meiriyigua::Config.post_time.to_i)
      end
      threads.each { |thr| thr.join }

    rescue
      puts "出错了 #{$!.class} #{$!.message}\n#{$!.backtrace.join("\n")}"
      threads.each { |thr| thr.exit rescue nil }
    end
    sleep 60*10
  end
end
run() click to toggle source
# File lib/meiriyigua.rb, line 11
def run
  @type = 1
  __run
end
run_two() click to toggle source
# File lib/meiriyigua.rb, line 16
def run_two
  @type = 2
  __run
end

Private Instance Methods

__run() click to toggle source
# File lib/meiriyigua.rb, line 22
def __run
  Thread.abort_on_exception = true

  while true
    begin
      ((Meiriyigua::Models::UrlRecord.all(baidu_at: nil) | Meiriyigua::Models::UrlRecord.all(publish_at: nil)) & Meiriyigua::Models::UrlRecord.all(:detail_at.lt => (Date.today - 7))).each do |url_record|
        url_record.page_record.destroy
        url_record.destroy
      end

      Meiriyigua::Models::PageRecord.all(url_record: {:publish_at.not => nil}).destroy!

      threads = []
      threads << Thread.new do
        list_crawl = ListCrawl.new
        list_crawl.run
        detail_crawl = DetailCrawl.new(list_crawl.detail_urls)
        detail_crawl.run
        sleep(Meiriyigua::Config.update_time.to_i)
      end
      threads << Thread.new do
        baidu_crawl = BaiduCrawl.new
        baidu_crawl.run
        sleep(Meiriyigua::Config.update_time.to_i)
      end
      threads << Thread.new do
        if @type == 1
          post_client = PostClient.new
          post_client.run
        else
          post_client = PostClientTwo.new
          post_client.run
        end
        sleep(Meiriyigua::Config.post_time.to_i)
      end
      threads.each { |thr| thr.join }

    rescue
      puts "出错了 #{$!.class} #{$!.message}\n#{$!.backtrace.join("\n")}"
      threads.each { |thr| thr.exit rescue nil }
    end
    sleep 60*10
  end
end
run() click to toggle source
# File lib/meiriyigua.rb, line 11
def run
  @type = 1
  __run
end
run_two() click to toggle source
# File lib/meiriyigua.rb, line 16
def run_two
  @type = 2
  __run
end