jobmaster 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/job_master/job_methods.rb +134 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49a526c44aa912126b20e09c67fa3ae38955822d
|
4
|
+
data.tar.gz: b6c53cd48c38edccd9ee8d5e853b06727693b9e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a422accc2acb60a84223af4e054a2defbda10e5959e7a65b01abb95ddf221147c3d1240dc6ee64d53e27633bff25c9b985d382bd8ea42e82f346f447cc63a488
|
7
|
+
data.tar.gz: be62c7db023ebba3cfdcdd035849cee4d28c8b99ef56358109270fd5173c8529aa6151f13a10a01b2052fdc3aeeebefe939399272a980575f69fb49fe749ef90
|
@@ -0,0 +1,134 @@
|
|
1
|
+
class JobMaster
|
2
|
+
|
3
|
+
def master_cycle (sleep)
|
4
|
+
|
5
|
+
@schedule = database[:job_log].where(status: 'active').order(:frequency).reverse
|
6
|
+
@time_log = {}
|
7
|
+
|
8
|
+
stop = false
|
9
|
+
|
10
|
+
until stop
|
11
|
+
@schedule.each { |job|
|
12
|
+
program = job[:program]
|
13
|
+
if job[:frequency] == 0
|
14
|
+
step_single(program)
|
15
|
+
else
|
16
|
+
@time_log[program] ||= Time.now
|
17
|
+
difference = (Time.now - @time_log[program]) / 60
|
18
|
+
if difference > job[:frequency]
|
19
|
+
step_single(program)
|
20
|
+
@time_log[program] = Time.now
|
21
|
+
end
|
22
|
+
end
|
23
|
+
sleep(sleep)
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
def start_single (prog_name , minutes = 10, sleep = 3)
|
30
|
+
|
31
|
+
@start_time = Time.now
|
32
|
+
set_up_job(prog_name)
|
33
|
+
|
34
|
+
unit_time = 0.0
|
35
|
+
|
36
|
+
while (Time.now - @start_time) / 60 < minutes
|
37
|
+
|
38
|
+
unless unit_time == 0.0
|
39
|
+
update_job(unit_time)
|
40
|
+
end
|
41
|
+
|
42
|
+
unit_start = Time.now
|
43
|
+
unit = next_unit
|
44
|
+
|
45
|
+
break if unit.nil?
|
46
|
+
|
47
|
+
@websites.first.send(prog_name.to_sym, unit)
|
48
|
+
|
49
|
+
puts unit_time = (Time.now - unit_start) / 60
|
50
|
+
sleep(sleep)
|
51
|
+
unit_time += sleep / 60
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def step_single (prog_name)
|
57
|
+
|
58
|
+
@start_time = Time.now
|
59
|
+
set_up_job(prog_name)
|
60
|
+
unit = next_unit
|
61
|
+
return false if unit.nil?
|
62
|
+
|
63
|
+
@websites.first.send(prog_name.to_sym, unit)
|
64
|
+
puts unit_time = (Time.now - @start_time) / 60
|
65
|
+
update_job(unit_time)
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def set_up_job (program)
|
70
|
+
last_matching = programs_db.where(program: program, @myself => Sequel.pg_array_op(:machines).any).order(:id).last
|
71
|
+
|
72
|
+
@program_id = last_matching[:id]
|
73
|
+
the_job = jobs_db.where(program: program, constraints: @program_id).order(:id).last
|
74
|
+
|
75
|
+
if the_job.nil?
|
76
|
+
units = self.send(last_matching[:method].to_sym, last_matching[:constraints].merge(program: program))
|
77
|
+
insert_job_details(program, units, last_matching[:machines])
|
78
|
+
end
|
79
|
+
|
80
|
+
@job_id = the_job[:id]
|
81
|
+
end
|
82
|
+
|
83
|
+
def insert_job_details (program, units, machines)
|
84
|
+
|
85
|
+
time_share = machines.inject({}) { |acc, m|
|
86
|
+
acc.store(m, 0)
|
87
|
+
acc
|
88
|
+
}
|
89
|
+
|
90
|
+
details = {
|
91
|
+
program: program,
|
92
|
+
created: Time.now,
|
93
|
+
constraints: @program_id,
|
94
|
+
units: Sequel.pg_array(units),
|
95
|
+
size: units.size,
|
96
|
+
total_minutes: 0.0,
|
97
|
+
time_share: Sequel.hstore(time_share),
|
98
|
+
unit_checkout: Sequel.hstore({:apples => :bananas})
|
99
|
+
}
|
100
|
+
jobs_db.insert(details)
|
101
|
+
end
|
102
|
+
|
103
|
+
def next_unit
|
104
|
+
checkout = jobs_db[id: @job_id][:unit_checkout].to_hash
|
105
|
+
|
106
|
+
if checkout.keys.include?(@myself)
|
107
|
+
checkout[@myself]
|
108
|
+
else
|
109
|
+
units = jobs_db[id: @job_id][:units]
|
110
|
+
return false if units.empty?
|
111
|
+
next_unit = units.pop
|
112
|
+
jobs_db.where(id: @job_id).update(
|
113
|
+
:units => units,
|
114
|
+
:unit_checkout => Sequel.hstore(Sequel.expr(:unit_checkout)).merge(@myself => next_unit))
|
115
|
+
next_unit
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def update_job (unit_time)
|
120
|
+
|
121
|
+
time_share = jobs_db[id: @job_id][:time_share].to_hash
|
122
|
+
time_share.find_add!(@myself, unit_time)
|
123
|
+
|
124
|
+
unit_checkout = jobs_db[id: @job_id][:unit_checkout].to_hash
|
125
|
+
unit_checkout.delete!(@myself)
|
126
|
+
|
127
|
+
jobs_db.where(id: @job_id).update(
|
128
|
+
:total_minutes => Sequel.expr(:total_minutes) + unit_time,
|
129
|
+
:time_share => Sequel.hstore(time_share),
|
130
|
+
:unit_checkout => Sequel.hstore(unit_checkout)
|
131
|
+
)
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jobmaster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugene Lai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: flex_core
|
@@ -46,6 +46,7 @@ extra_rdoc_files: []
|
|
46
46
|
files:
|
47
47
|
- lib/job_master.rb
|
48
48
|
- lib/job_master/gen_methods.rb
|
49
|
+
- lib/job_master/job_methods.rb
|
49
50
|
- lib/job_master/stealth.rb
|
50
51
|
homepage:
|
51
52
|
licenses: []
|
@@ -66,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
67
|
version: '0'
|
67
68
|
requirements: []
|
68
69
|
rubyforge_project:
|
69
|
-
rubygems_version: 2.
|
70
|
+
rubygems_version: 2.6.1
|
70
71
|
signing_key:
|
71
72
|
specification_version: 4
|
72
73
|
summary: Job manager for multi-website automated scraping
|