resque-telework 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ # Load required file
2
+
3
+ require 'resque'
4
+ require 'resque/server'
5
+
6
+ require 'resque-telework/redis'
7
+ require 'resque-telework/server'
8
+ require 'resque-telework/global'
9
+ require 'resque-telework/manager'
10
+ require 'resque-telework/railtie' if defined?(Rails)
@@ -0,0 +1,98 @@
1
+ namespace :telework do
2
+
3
+ desc 'Register a new revision into Telework'
4
+ task :register_revision => :environment do
5
+ cfg= get_config
6
+ host= cfg['hostname']
7
+ cfg.delete('hostname')
8
+ TeleworkRedis.new.register_revision(host, cfg)
9
+ end
10
+
11
+ desc 'Start a Telework daemon on this machine and returns'
12
+ task :start_daemon => :environment do
13
+ cfg= get_config
14
+ host= cfg['hostname']
15
+ daemon= Resque::Plugins::Telework::Manager.new(cfg)
16
+ if daemon.is_alive(host)
17
+ msg= "There is already a daemon running on #{host}"
18
+ daemon.send_status( 'Error', msg)
19
+ daemon.send_status( 'Error', "This daemon (PID #{Process.pid}) cannot be started and will terminare now")
20
+ return nil
21
+ end
22
+ logp= cfg['daemon_log_path']
23
+ logp||= "."
24
+ logf= "#{logp}/telework_daemon.log"
25
+ lpid= "#{logp}/telework_daemon.pid"
26
+
27
+ # Forking
28
+ pid = fork do
29
+ File.open(logf, 'w') do |lf|
30
+ $stdout.reopen(lf)
31
+ $stderr.reopen(lf)
32
+ end
33
+ Process.setsid # I'm grown up now
34
+ daemon.start # Start the daemon
35
+ File.delete(lpid) # Delete the pid file
36
+ end
37
+ open(lpid, 'w') { |f| f.write("#{pid}\n") } if pid # Create the pid file
38
+
39
+ end
40
+
41
+ desc 'Run the Telework daemon'
42
+ task :daemon => :environment do
43
+ Resque::Plugins::Telework::Manager.new(get_config).start
44
+ end
45
+
46
+ desc 'Register the local git installation'
47
+ task :local_config_from_git => :environment do
48
+ begin
49
+ rev_date= Time.parse(`git show --format=format:"%aD"`)
50
+ rescue
51
+ rev_date= nil
52
+ end
53
+ github_repo= "https://github.com/john/reputedly"
54
+ latest_revision= `git rev-parse HEAD`.chomp
55
+ cfg= { :hostname => find_hostname,
56
+ :revision => latest_revision,
57
+ :revision_small => latest_revision[0..6],
58
+ :revision_type => 'Rails:Resque',
59
+ :revision_path => pwd,
60
+ :revision_link => "#{github_repo}/commit/#{latest_revision}",
61
+ :revision_branch => ( $1 if /\* (\S+)\s/.match(`git branch`) ),
62
+ :revision_date => rev_date,
63
+ :revision_deployement_date => Time.now,
64
+ :revision_info => `git log -1`,
65
+ :revision_log_path => "#{pwd}/log",
66
+ :daemon_pooling_interval => 2,
67
+ :daemon_log_path => pwd }
68
+ # Create the config file
69
+ require 'json'
70
+ open("telework.conf", 'w') { |f| f.write(cfg.to_json) }
71
+ end
72
+
73
+ # Helper functions
74
+ def get_config
75
+ ch= { 'hostname' => find_hostname }
76
+ # TELEWORK_CONFIG_FILE
77
+ fn= ENV['TELEWORK_CONFIG_FILE']
78
+ # Local config file
79
+ fn||= "telework.conf" if File.exist?("telework.conf")
80
+ fn||= "telework_config.log" if File.exist?("telework_config.log") # Legacy, this will be removed
81
+ raise "Could not find Telework configuration file.. exiting" unless fn
82
+ ActiveSupport::JSON.decode(open(fn, "r").read).merge(ch)
83
+ end
84
+
85
+ def find_hostname
86
+ # To find the hostname, we successively looks into
87
+ # 1) the environement variable TELEWORK_HOSTNAME
88
+ # 2) we get it through a Socket call
89
+ host= ENV['TELEWORK_HOSTNAME']
90
+ unless host
91
+ require 'socket'
92
+ host= Socket::gethostname()
93
+ end
94
+ raise "Could not find hostname.. exiting" unless host
95
+ host
96
+ end
97
+
98
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "resque-telework/global"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "resque-telework"
7
+ s.version = Resque::Plugins::Telework::Version
8
+ s.authors = "Gilles Pirio"
9
+ s.email = "gip.github@gmail.com"
10
+ s.date = Time.now.strftime('%Y-%m-%d')
11
+ s.homepage = "https://github.com/gip/resque-telework"
12
+ s.summary = %q{resque-telework: A Resque plugin aimed at controlling Resque workers from the web UI }
13
+
14
+ s.add_runtime_dependency 'resque', '>= 1.20.0'
15
+ s.add_runtime_dependency 'sys-cpu', '~> 0.7.0'
16
+ s.extra_rdoc_files = ["README.md", "MIT-LICENSE"]
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.require_paths = ["lib"]
20
+ s.description = <<description
21
+ Telework is a Resque plugin aimed at controlling Resque workers from the web UI. It makes it easy to manage workers on a
22
+ complex systems that may include several hosts, different queue(s) and an evolving source code that is deployed several times a day.
23
+ Beyond starting and stopping workers on remote hosts, the plugin makes it easy to switch between code revisions, gives a partial view of
24
+ each worker's log (stdout and stderr) and maintains a status of each workers.
25
+ description
26
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resque-telework
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gilles Pirio
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: resque
16
+ requirement: &70173135892440 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.20.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70173135892440
25
+ - !ruby/object:Gem::Dependency
26
+ name: sys-cpu
27
+ requirement: &70173135891940 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.7.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70173135891940
36
+ description: ! " Telework is a Resque plugin aimed at controlling Resque workers
37
+ from the web UI. It makes it easy to manage workers on a \n complex systems that
38
+ may include several hosts, different queue(s) and an evolving source code that is
39
+ deployed several times a day. \n Beyond starting and stopping workers on remote
40
+ hosts, the plugin makes it easy to switch between code revisions, gives a partial
41
+ view of \n each worker's log (stdout and stderr) and maintains a status of each
42
+ workers.\n"
43
+ email: gip.github@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files:
47
+ - README.md
48
+ - MIT-LICENSE
49
+ files:
50
+ - Gemfile
51
+ - MIT-LICENSE
52
+ - README.md
53
+ - doc/screenshots/view_overview.png
54
+ - lib/resque-telework.rb
55
+ - lib/resque-telework/global.rb
56
+ - lib/resque-telework/manager.rb
57
+ - lib/resque-telework/railtie.rb
58
+ - lib/resque-telework/redis.rb
59
+ - lib/resque-telework/server.rb
60
+ - lib/resque-telework/server/views/misc.erb
61
+ - lib/resque-telework/server/views/revision.erb
62
+ - lib/resque-telework/server/views/stopit.erb
63
+ - lib/resque-telework/server/views/telework.erb
64
+ - lib/resque-telework/server/views/worker.erb
65
+ - lib/tasks/telework.rake
66
+ - resque-telework.gemspec
67
+ homepage: https://github.com/gip/resque-telework
68
+ licenses: []
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 1.8.16
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: ! 'resque-telework: A Resque plugin aimed at controlling Resque workers from
91
+ the web UI'
92
+ test_files: []
93
+ has_rdoc: