lita-jobs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3f70475371e353c2fd7125259bddb05786f9b473
4
+ data.tar.gz: baffd0a72a316b6aa442b766f42e8151f7b3be83
5
+ SHA512:
6
+ metadata.gz: 54d50c8d9ee176517b31f289bd0111cdf9f84225ea5b011bfe0ed3235f70a595161d0b9760ea016b3d0e25272373c197c8d217ee108e7df2ea1c26c86e9f699f
7
+ data.tar.gz: b61039fe1d3d8df884f3cfc429097a656a004a9f42c96d0c7a7f0ca4eafea0c542b81d93057e0026158abf48338f6e62bc727643a44b75fc49a324b6f3d3735e
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script: bundle exec rspec
5
+ before_install:
6
+ - gem update --system
7
+ services:
8
+ - redis-server
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2014 Jose Luis Salas
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,30 @@
1
+ # lita-jobs
2
+
3
+ Control jobs from yaml gem.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/lita-jobs.png)](http://badge.fury.io/rb/lita-jobs)
6
+ [![Build Status](https://secure.travis-ci.org/josacar/lita-jobs.png)](http://travis-ci.org/josacar/lita-jobs)
7
+ [![Coverage Status](https://coveralls.io/repos/josacar/lita-jobs/badge.png)](https://coveralls.io/r/josacar/lita-jobs)
8
+ [![Code Climate](https://codeclimate.com/github/josacar/lita-jobs.png)](https://codeclimate.com/github/josacar/lita-jobs)
9
+ [![Dependency Status](https://gemnasium.com/josacar/lita-jobs.png)](https://gemnasium.com/josacar/lita-jobs)
10
+
11
+ ## Installation
12
+
13
+ Add lita-jobs to your Lita instance's Gemfile:
14
+
15
+ ``` ruby
16
+ gem "lita-jobs"
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```
22
+ lita jobs list - List active and finished jobs
23
+ lita jobs kill JOB_ID - Kill an active job
24
+ lita jobs tail JOB_ID - Print last output for a job
25
+ lita jobs output JOB_ID - Print output for a job
26
+ ```
27
+
28
+ ## License
29
+
30
+ [MIT](http://opensource.org/licenses/MIT)
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,7 @@
1
+ require 'lita'
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join('..', '..', 'locales', '*.yml'), __FILE__
5
+ )]
6
+
7
+ require 'lita/handlers/jobs'
@@ -0,0 +1,89 @@
1
+ require 'yajm/job_manager'
2
+
3
+ module Lita
4
+ module Handlers
5
+ class Jobs < Handler
6
+ route /^jobs\slist$/, :job_list,
7
+ :help => { 'jobs list' => t('help.job_list') }
8
+ route /^jobs\skill\s(\d+)$/, :job_kill,
9
+ :help => { 'jobs kill JOB_ID' => t('help.job_kill') }
10
+ route /^jobs\stail\s(\d+)$/, :job_tail,
11
+ :help => { 'jobs tail JOB_ID' => t('help.job_tail') }
12
+ route /^jobs\sout(?:put)?\s(\d+)$/, :job_output,
13
+ :help => { 'jobs out JOB_ID' => t('help.job_output') }
14
+
15
+ def job_list(response)
16
+ jobs = ::Yajm::JobManager.list
17
+ if jobs[:active].length == 0 && jobs[:finished].length == 0
18
+ response.reply(t('job_list.no_job'))
19
+ else
20
+ str = ''
21
+ str << active_jobs(jobs[:active]) << finished_jobs(jobs[:finished])
22
+
23
+ response.reply(str)
24
+ end
25
+ end
26
+
27
+ def job_kill(response)
28
+ in_job(response) do |job|
29
+ job.kill!
30
+ end
31
+ end
32
+
33
+ def job_tail(response)
34
+ in_job(response) do |job|
35
+ response.reply(job.output_tail)
36
+ end
37
+ end
38
+
39
+ def job_output(response)
40
+ in_job(response) do |job|
41
+ response.reply(job.output)
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def active_jobs(jobs)
48
+ "".tap do |str|
49
+ if jobs.length > 0
50
+ str << "> #{t('job_list.active_jobs')}:\n"
51
+ jobs.each do |job|
52
+ str << " ID: %d Cmd: '%s' #{t('job_list.started')}: %s\n" %
53
+ [job.pid, job.command, job.start_time.to_s]
54
+ end
55
+ str << "\n"
56
+ end
57
+ end
58
+ end
59
+
60
+ def finished_jobs(jobs)
61
+ "".tap do |str|
62
+ if jobs.length > 0
63
+ str << "> #{t('job_list.finished_jobs')}:\n"
64
+ jobs.each do |job|
65
+ str << " ID: %d Cmd: '%s' #{t('job_list.started')}: %s, #{t('job_list.finished')}: %s\n" %
66
+ [job.pid, job.command, job.start_time.to_s, job.end_time.to_s]
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ def retrieve_job(job_id)
73
+ Yajm::JobManager.getjob(job_id)
74
+ end
75
+
76
+ def in_job(response)
77
+ job_id = response.matches[0][0]
78
+ job = retrieve_job(job_id)
79
+ if job
80
+ yield(job)
81
+ else
82
+ response.reply(t('in_job.no_job', job_id: job_id))
83
+ end
84
+ end
85
+ end
86
+
87
+ Lita.register_handler(Jobs)
88
+ end
89
+ end
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'lita-jobs'
3
+ spec.version = '0.0.1'
4
+ spec.authors = ['Jose Luis Salas']
5
+ spec.email = ['josacar@gmail.com']
6
+ spec.description = %q{Run jobs in lita}
7
+ spec.summary = %q{Spawn and control deferred jobs in lita}
8
+ spec.homepage = 'https://github.com/josacar/lita-jobs'
9
+ spec.license = 'MIT'
10
+ spec.metadata = { 'lita_plugin_type' => 'handler' }
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ['lib']
16
+
17
+ spec.add_runtime_dependency 'lita', '>= 3.0'
18
+ spec.add_runtime_dependency 'yajm'
19
+ spec.add_runtime_dependency 'eventmachine'
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rspec', '>= 3.0.0.beta2'
23
+ spec.add_development_dependency 'simplecov'
24
+ spec.add_development_dependency 'coveralls'
25
+ end
@@ -0,0 +1,17 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ jobs:
5
+ help:
6
+ job_list: List active and finished jobs
7
+ job_kill: Kill an active job
8
+ job_tail: List last output for a job
9
+ job_output: List output for a job
10
+ job_list:
11
+ no_job: No active or finished jobs.
12
+ active_jobs: Active Jobs
13
+ started: Started
14
+ finished_jobs: Finished Jobs
15
+ finished: Finished
16
+ in_job:
17
+ no_job: "No such job: %{job_id}"
@@ -0,0 +1,98 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::Jobs, lita_handler: true do
4
+ let(:running_job1) do
5
+ instance_double(Yajm::Job,
6
+ :pid => 123,
7
+ :command => 'shutdown',
8
+ :start_time => Time.parse('Thu Nov 29 14:33:20 UTC 2001')
9
+ )
10
+ end
11
+ let(:finished_job1) do
12
+ instance_double(Yajm::Job,
13
+ :pid => 3131,
14
+ :command => 'last',
15
+ :start_time => Time.parse('Thu Jan 19 14:33:20 UTC 2013'),
16
+ :end_time => Time.parse('Thu Jan 19 15:33:20 UTC 2013')
17
+ )
18
+ end
19
+ let(:job) { instance_double(Yajm::Job) }
20
+ let(:empty_jobs) do
21
+ { :active => [], :finished => [] }
22
+ end
23
+ let(:active_jobs) do
24
+ { :active => [running_job1], :finished => [] }
25
+ end
26
+ let(:finished_jobs) do
27
+ { :active => [], :finished => [finished_job1] }
28
+ end
29
+
30
+ it { routes('jobs list').to(:job_list) }
31
+ it { routes('jobs kill 1231').to(:job_kill) }
32
+ it { routes('jobs tail 2231').to(:job_tail) }
33
+ it { routes('jobs output 232').to(:job_output) }
34
+ it { routes('jobs out 232').to(:job_output) }
35
+ it { doesnt_route('jobs wadus').to(:job_list) }
36
+
37
+ shared_examples_for 'prints error message when job not found' do
38
+ it 'returns error message when not found' do
39
+ allow(Yajm::JobManager).to receive(:getjob).with('1123')
40
+ send_command('jobs tail 1123')
41
+ expect(replies.last).to eq('No such job: 1123')
42
+ end
43
+ end
44
+
45
+ describe '#job_list' do
46
+ it 'returns no job if there is no job' do
47
+ allow(::Yajm::JobManager).to receive(:list).and_return(empty_jobs)
48
+ send_command('jobs list')
49
+ expect(replies.last).to eq('No active or finished jobs.')
50
+ end
51
+
52
+ it 'returns active jobs list for running jobs' do
53
+ allow(::Yajm::JobManager).to receive(:list).and_return(active_jobs)
54
+ send_command('jobs list')
55
+ expect(replies.last).to eq("> Active Jobs:\n ID: 123 Cmd: 'shutdown' Started: 2001-11-29 14:33:20 UTC\n\n")
56
+ end
57
+
58
+ it 'returns finished jobs list for finished jobs' do
59
+ allow(::Yajm::JobManager).to receive(:list).and_return(finished_jobs)
60
+ send_command('jobs list')
61
+ expect(replies.last).to eq("> Finished Jobs:\n ID: 3131 Cmd: 'last' Started: 2013-01-19 14:33:20 UTC, Finished: 2013-01-19 15:33:20 UTC\n")
62
+ end
63
+ end
64
+
65
+ describe '#job_kill' do
66
+ it 'kills a jobs when found' do
67
+ allow(Yajm::JobManager).to receive(:getjob).with('1123').and_return(job)
68
+ expect(job).to receive(:kill!)
69
+ send_command('jobs kill 1123')
70
+ end
71
+
72
+ it_behaves_like 'prints error message when job not found'
73
+ end
74
+
75
+ describe '#job_tail' do
76
+ it 'gets last output from a job when found' do
77
+ output = 'Hello world!'
78
+ allow(Yajm::JobManager).to receive(:getjob).with('1123').and_return(job)
79
+ allow(job).to receive(:output_tail).and_return(output)
80
+ send_command('jobs tail 1123')
81
+ expect(replies.last).to eq(output)
82
+ end
83
+
84
+ it_behaves_like 'prints error message when job not found'
85
+ end
86
+
87
+ describe '#job_output' do
88
+ it 'gets output from a job when found' do
89
+ output = "I'm Muzzy big Muzzy"
90
+ allow(Yajm::JobManager).to receive(:getjob).with('1123').and_return(job)
91
+ allow(job).to receive(:output).and_return(output)
92
+ send_command('jobs output 1123')
93
+ expect(replies.last).to eq(output)
94
+ end
95
+
96
+ it_behaves_like 'prints error message when job not found'
97
+ end
98
+ end
@@ -0,0 +1,13 @@
1
+ require "simplecov"
2
+ require "coveralls"
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter
6
+ ]
7
+ SimpleCov.start do
8
+ add_filter "/spec/"
9
+ add_filter "/vendor/"
10
+ end
11
+
12
+ require "lita-jobs"
13
+ require "lita/rspec"
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-jobs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jose Luis Salas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: yajm
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: eventmachine
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0.beta2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0.beta2
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: coveralls
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Run jobs in lita
112
+ email:
113
+ - josacar@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".travis.yml"
120
+ - Gemfile
121
+ - LICENSE
122
+ - README.md
123
+ - Rakefile
124
+ - lib/lita-jobs.rb
125
+ - lib/lita/handlers/jobs.rb
126
+ - lita-jobs.gemspec
127
+ - locales/en.yml
128
+ - spec/lita/handlers/jobs_spec.rb
129
+ - spec/spec_helper.rb
130
+ homepage: https://github.com/josacar/lita-jobs
131
+ licenses:
132
+ - MIT
133
+ metadata:
134
+ lita_plugin_type: handler
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.2.2
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Spawn and control deferred jobs in lita
155
+ test_files:
156
+ - spec/lita/handlers/jobs_spec.rb
157
+ - spec/spec_helper.rb