cnvrg 0.3.2 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,22 +1,28 @@
1
+ require 'net/http'
1
2
  module Cnvrg
2
3
  class Experiment
3
4
  attr_reader :slug
5
+ attr_reader :sync_before_terminate
6
+ attr_reader :sync_delay_time
4
7
 
5
8
  def initialize(owner, project_slug)
6
9
  @project_slug = project_slug
7
10
  @owner = owner
8
11
  @base_resource = "users/#{owner}/projects/#{project_slug}/"
9
12
  @slug = nil
13
+ @sync_before_terminate = nil
14
+ @sync_delay_time = nil
10
15
  end
11
16
 
12
- def start(input, platform, machine_name, start_commit, name, email_notification, machine_activity,script_path)
17
+ def start(input, platform, machine_name, start_commit, name, email_notification, machine_activity,script_path,sync_before_terminate, periodic_sync)
18
+
13
19
  res = Cnvrg::API.request(@base_resource + "experiment/start", 'POST',
14
- {input: input, platform: platform, machine_name: machine_name, start_commit: start_commit,
20
+ {input: input, platform: platform, machine_name: machine_name, start_commit: start_commit,sync_before_terminate:sync_before_terminate, periodic_sync:periodic_sync,
15
21
  title: name, email_notification: email_notification, machine_activity: machine_activity,script_path:script_path})
16
22
  Cnvrg::CLI.is_response_success(res,false)
17
-
18
23
  @slug = res.to_h["result"].to_h["slug"]
19
-
24
+ @sync_before_terminate = res.to_h["result"].to_h["sync_before_terminate"]
25
+ @sync_delay_time = res.to_h["result"].to_h["sync_delay_time"]
20
26
  return res
21
27
 
22
28
  end
@@ -113,5 +119,30 @@ module Cnvrg
113
119
 
114
120
  end
115
121
  end
122
+
123
+ def restart_spot_instance
124
+ restart = false
125
+ begin
126
+ url = URI.parse('http://169.254.169.254/latest/meta-data/spot/termination-time')
127
+ req = Net::HTTP::Get.new(url.to_s)
128
+ res = Net::HTTP.start(url.host, url.port) {|http|
129
+ http.request(req)
130
+ }
131
+ unless res.body.include? "404"
132
+ restart = true
133
+ end
134
+ if res.body.include? "Empty reply from server"
135
+ restart = false
136
+ end
137
+ rescue
138
+ end
139
+
140
+ return restart
141
+
142
+ end
143
+
144
+ def send_restart_request()
145
+ response = Cnvrg::API.request(@base_resource + "experiment/check_spot_instance", 'POST', {exp_slug: @slug})
146
+ end
116
147
  end
117
148
  end
data/lib/cnvrg/project.rb CHANGED
@@ -312,7 +312,7 @@ module Cnvrg
312
312
  File.open(@working_dir+"/.cnvrg/config.yml", "w+") { |f| f.write new_config.to_yaml }
313
313
  end
314
314
 
315
- def generate_idx
315
+ def generate_idx(deploy:false)
316
316
  if File.exists? "#{self.local_path}/.cnvrg/idx.yml"
317
317
  old_idx = YAML.load_file("#{self.local_path}/.cnvrg/idx.yml")
318
318
  else
@@ -322,6 +322,11 @@ module Cnvrg
322
322
  tree_idx = Hash.new(0)
323
323
  list = Dir.glob("#{self.local_path}/**/*", File::FNM_DOTMATCH).reject { |x| (x =~ /\/\.{1,2}$/) or (x =~ /^#{self.local_path}\/\.cnvrg\/*/) or (x =~/^#{self.local_path}\/\.cnvrgignore.conflict*/) and not (x =~/^#{self.local_path}\/\.cnvrgignore/) }
324
324
  list_ignore = self.get_ignore_list()
325
+ if deploy
326
+ list_ignore << ["main.py","main.pyc", "__init__.py", "uwsgi.ini"]
327
+ list_ignore.flatten!
328
+ end
329
+
325
330
  Parallel.map(list, in_threads: IDXParallelThreads) do |e|
326
331
  label = e.gsub(self.local_path + "/", "")
327
332
  ignore_label = label.gsub("/","//")
@@ -357,8 +362,8 @@ module Cnvrg
357
362
  return response
358
363
  end
359
364
 
360
- def compare_idx(new_branch, commit:last_local_commit,force:false)
361
- local_idx = self.generate_idx
365
+ def compare_idx(new_branch, commit:last_local_commit,force:false, deploy: false)
366
+ local_idx = self.generate_idx(deploy: deploy)
362
367
  ignore_list = self.send_ignore_list()
363
368
  if force
364
369
  added = []
data/lib/cnvrg/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Cnvrg
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.5'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cnvrg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yochay Ettun
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-02-07 00:00:00.000000000 Z
12
+ date: 2018-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler