usbunfreeze_daemon 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 725ed494565429b5bbedd0da8452be558a38db42
4
- data.tar.gz: 845b3b9a5e9800dc8d7a417cbfa496a360e9867f
3
+ metadata.gz: 0b110f278301391a6fc73c50ba0f88892f66e41d
4
+ data.tar.gz: 1c0b8bef3515d3b0e0daff8be61eca8828a36b7f
5
5
  SHA512:
6
- metadata.gz: 5478c8605e039f062954c7676dd86173d8eecef35fcc4143e642a85edbad48901c7472e463fecca8e5b47667bc57de72d922efd17063535d5afcd43e64554334
7
- data.tar.gz: 2c17a37668e607b7e6c679d030505ad05dca4df165c3dc3ab1d47471780b353a98757dc5b9d382b49b7059537509f1a24c7c96c41288f324e38a3f672c0866d3
6
+ metadata.gz: 85be19441557cd5a26d3eb2e8367cad894b28572aa54f7e22f4e38decc63b2ac3e0f173245bf9acc86dd0be5c9b80bd42d1c082dabe808563236b9365a20824e
7
+ data.tar.gz: 9eb83fb83126eca5e9d660b6ef40a4de0db63dd699d4879a4fe841f6e432a50bc386239396ab6bc82063f49439aacb8a2510f96766e57a18e0b96b6e39f2be59
data/README.md CHANGED
@@ -28,7 +28,7 @@ Possible flags:
28
28
 
29
29
  * `--directory PATH` -- use `PATH` for logs and pids. Used usually for non-system installation
30
30
  * `--system` -- use `/var/log` for logging and `/var/run` for pid storing. `-d` is not needed with this flag.s
31
- * `--no-daemonize` -- do not fork into daemon
31
+ * `--ontop` -- do not fork into daemon
32
32
  * `start|stop|status` -- self-describing control commands
33
33
 
34
34
  ## License information
@@ -29,14 +29,14 @@ class Daemon
29
29
  opts.on("-s", "--system", "Use /var for pids and logs") do |s|
30
30
  @options[:dir_mode] = :system
31
31
  end
32
- opts.on("-n", "--no-daemonize", "Do not daemonize") do |s|
32
+ opts.on("-t", "--no-daemonize", "Do not daemonize") do |s|
33
33
  @options[:ontop] = true
34
34
  end
35
35
 
36
36
  begin
37
37
  opts.parse(ARGV)
38
38
  rescue OptionParser::ParseError => e
39
- logger.error "Error: #{e.message}\nOpts: #{opts.inspect}"
39
+ @logger.error "Error: #{e.message}\nOpts: #{opts.inspect}"
40
40
  exit(-1)
41
41
  end
42
42
  end.parse!(args)
@@ -50,4 +50,4 @@ class Daemon
50
50
  end
51
51
  end
52
52
 
53
- Daemon.new(ARGV).run
53
+ Daemon.new(ARGV).run
@@ -1,6 +1,8 @@
1
1
  require 'settingslogic'
2
2
  require 'aws-sdk'
3
3
  require 'json'
4
+ require 'retries'
5
+ require 'net/http'
4
6
 
5
7
  module UsbunfreezeDaemon
6
8
 
@@ -19,6 +21,24 @@ module UsbunfreezeDaemon
19
21
 
20
22
  @logger.info "Running with executable=#{Settings.exec_command}"
21
23
 
24
+ handler = Proc.new do |e, attempt_number, total_delay|
25
+ log_exception "Encountered an error", e
26
+ @logger.info "Retries attempt #{attempt_number}; #{total_delay} seconds have passed."
27
+ end
28
+
29
+ with_retries(max_tries: 999999, base_sleep_seconds: 5, max_sleep_seconds: 30,
30
+ rescue: [SocketError, Seahorse::Client::NetworkingError], handler: handler) do |attempt|
31
+ @logger.info "Running network loop"
32
+ run_network
33
+ end
34
+
35
+ rescue StandardError => e
36
+ log_exception "Error in outer loop", e
37
+ end
38
+
39
+ private
40
+
41
+ def run_network
22
42
  sqs = Aws::SQS::Client.new(region: Settings.sqs.region,
23
43
  access_key_id: Settings.sqs.access_key_id,
24
44
  secret_access_key: Settings.sqs.secret_access_key)
@@ -41,15 +61,8 @@ module UsbunfreezeDaemon
41
61
  @logger.info "Deleting message returned data: #{resp.data}" unless resp.data
42
62
  end
43
63
  end
44
-
45
- rescue => e
46
- @logger.error "Error:" + e.message
47
- @logger.error e.backtrace.map{|s| "\t"+s}.join("\n")
48
- exit 1
49
64
  end
50
65
 
51
- private
52
-
53
66
  # Handle an incoming SQS message
54
67
  # Wrong message is not fatal error
55
68
  def handle_message m
@@ -65,10 +78,13 @@ module UsbunfreezeDaemon
65
78
  system(Settings.exec_command)
66
79
  @logger.info "Command execution code: #{$?}"
67
80
  end
68
- rescue => e
69
- @logger.info "Error parsing a message:" + e.message
70
- @logger.info e.backtrace.map{|s| "\t"+s}.join("\n")
71
- @logger.info "Continuing..."
81
+ rescue StandardError => e
82
+ log_exception "Non-fatal error parsing a message", e
83
+ end
84
+
85
+ def log_exception banner, exception
86
+ @logger.error "#{banner}: #{exception.message} (class #{exception.class})"
87
+ @logger.error exception.backtrace.map{|s| "\t"+s}.join("\n")
72
88
  end
73
89
 
74
90
  end
@@ -1,3 +1,3 @@
1
1
  module UsbunfreezeDaemon
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_runtime_dependency "settingslogic", "~> 2.0.0"
25
25
  spec.add_runtime_dependency "aws-sdk", "~> 2"
26
26
  spec.add_runtime_dependency "json", "~> 1.8.0"
27
+ spec.add_runtime_dependency "retries", "~> 0.0.5"
27
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usbunfreeze_daemon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - theirix
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-21 00:00:00.000000000 Z
11
+ date: 2015-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 1.8.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: retries
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.0.5
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.0.5
97
111
  description: Daemon application for Usbunfreeze kit
98
112
  email:
99
113
  - theirix@gmail.com