lazylead 0.3.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.0pdd.yml +4 -1
- data/.docs/accuracy.md +107 -0
- data/.docs/accuracy_email.jpg +0 -0
- data/.docs/accuracy_jira_comment.jpg +0 -0
- data/.docs/duedate_expired.md +3 -3
- data/.docs/propagate_down.md +4 -4
- data/.gitattributes +1 -0
- data/.github/dependabot.yml +6 -0
- data/.pdd +1 -1
- data/.rubocop.yml +6 -0
- data/Rakefile +2 -0
- data/bin/lazylead +7 -4
- data/lazylead.gemspec +5 -4
- data/lib/lazylead/exchange.rb +16 -9
- data/lib/lazylead/log.rb +30 -8
- data/lib/lazylead/model.rb +78 -22
- data/lib/lazylead/opts.rb +80 -0
- data/lib/lazylead/postman.rb +1 -1
- data/lib/lazylead/schedule.rb +18 -17
- data/lib/lazylead/smtp.rb +1 -1
- data/lib/lazylead/system/jira.rb +55 -14
- data/lib/lazylead/system/synced.rb +2 -1
- data/lib/lazylead/task/accuracy/accuracy.rb +136 -0
- data/lib/lazylead/task/accuracy/affected_build.rb +39 -0
- data/lib/lazylead/task/accuracy/attachment.rb +44 -0
- data/lib/lazylead/task/accuracy/environment.rb +39 -0
- data/lib/lazylead/task/accuracy/logs.rb +40 -0
- data/lib/lazylead/task/accuracy/records.rb +45 -0
- data/lib/lazylead/task/accuracy/requirement.rb +49 -0
- data/lib/lazylead/task/accuracy/servers.rb +50 -0
- data/lib/lazylead/task/accuracy/stacktrace.rb +63 -0
- data/lib/lazylead/task/accuracy/testcase.rb +75 -0
- data/lib/lazylead/task/accuracy/wiki.rb +41 -0
- data/lib/lazylead/task/alert.rb +8 -6
- data/lib/lazylead/task/confluence_ref.rb +4 -3
- data/lib/lazylead/task/echo.rb +22 -0
- data/lib/lazylead/task/fix_version.rb +18 -7
- data/lib/lazylead/task/missing_comment.rb +7 -5
- data/lib/lazylead/task/propagate_down.rb +11 -3
- data/lib/lazylead/task/savepoint.rb +1 -1
- data/lib/lazylead/task/touch.rb +119 -0
- data/lib/lazylead/version.rb +1 -1
- data/lib/messages/accuracy.erb +118 -0
- data/lib/messages/svn_log.erb +117 -0
- data/lib/messages/svn_touch.erb +147 -0
- data/license.txt +1 -1
- data/readme.md +20 -19
- data/test/lazylead/cc_test.rb +2 -2
- data/test/lazylead/cli/app_test.rb +12 -12
- data/test/lazylead/exchange_test.rb +3 -3
- data/test/lazylead/model_test.rb +4 -4
- data/test/lazylead/opts_test.rb +70 -0
- data/test/lazylead/postman_test.rb +1 -1
- data/test/lazylead/smtp_test.rb +1 -1
- data/test/lazylead/system/jira_test.rb +65 -1
- data/test/lazylead/task/accuracy/accuracy_test.rb +73 -0
- data/test/lazylead/task/accuracy/affected_build_test.rb +42 -0
- data/test/lazylead/task/accuracy/attachment_test.rb +50 -0
- data/test/lazylead/task/accuracy/environment_test.rb +42 -0
- data/test/lazylead/task/accuracy/logs_test.rb +78 -0
- data/test/lazylead/task/accuracy/records_test.rb +60 -0
- data/test/lazylead/task/accuracy/servers_test.rb +66 -0
- data/test/lazylead/task/accuracy/stacktrace_test.rb +113 -0
- data/test/lazylead/task/accuracy/testcase_test.rb +205 -0
- data/test/lazylead/task/accuracy/wiki_test.rb +40 -0
- data/test/lazylead/task/assignee_alert_test.rb +2 -2
- data/test/lazylead/task/duedate_test.rb +36 -26
- data/test/lazylead/task/fix_version_test.rb +9 -6
- data/test/lazylead/task/missing_comment_test.rb +11 -9
- data/test/lazylead/task/propagate_down_test.rb +4 -2
- data/test/lazylead/task/touch_test.rb +88 -0
- data/test/test.rb +25 -0
- data/upgrades/sqlite/001-install-main-lazylead-tables.sql +1 -5
- data/upgrades/sqlite/999.testdata.sql +12 -16
- metadata +65 -8
- data/.travis.yml +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8358ec8da9d97621f9c5ec28ddfa3114699f260af8ae4fd9632a998263f795e
|
4
|
+
data.tar.gz: 4a11f6cbd5cffbc91a2b40a5b7fb6c82d608301d16ebba1d8b2155a256101f48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31259a7b7305b519f610e68dbbb7649fee65257415aae4a0bfe1a77bdd88f62662279a4689bb18872d37eba4d8c0b6537ddf5f1a1c415762085e507fb39d05ae
|
7
|
+
data.tar.gz: 2c6bc24efc4696496c8a0c58c697af93377bc7c6d216141138ce8d18f3606104e7a945c715d3657ebc97ede3f97db586da3a6fe57c01f826eb86c61f024f91b7
|
data/.0pdd.yml
CHANGED
data/.docs/accuracy.md
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
## Give the score for the format of each incoming ticket to your team
|
2
|
+
#### Why?
|
3
|
+
When you have a pipeline between several teams, there should be criteria on how to pass a task between groups.
|
4
|
+
Without this, you may get the delays for your task because your team members have to do the work that is not their business, or they even don't have the skills to do it properly.
|
5
|
+
As a result, it may cause task delays or quality decreasing.
|
6
|
+
|
7
|
+
Even if you define the criteria for passing tasks between teams, it's tough to monitor that those criteria aren't violating. To hire a well-paid additional manager who will check each ticket and send emails its expensive unless you work for a bloody reach company.
|
8
|
+
|
9
|
+
This rule periodically checks the format of the ticket, post score results to the ticket, and raise email (one email per bunch of tickets) to you with details.
|
10
|
+
|
11
|
+
#### How to use lazylead for this
|
12
|
+
Let's assume that
|
13
|
+
1. Your team is working in Jira
|
14
|
+
2. You want daily to check the format of incoming defects to your team
|
15
|
+
3. [JQL](https://www.atlassian.com/blog/jira-software/jql-the-most-flexible-way-to-search-jira-14) for incoming defects: `project='PRJ' and type=Defect and created < -2h and created > -26h`.
|
16
|
+
This `< -2h` and `> -26h` gives reporter 2h to fill the ticket correctly, and, after that, the task will evaluate the ticket score.
|
17
|
+
4. you've saved this [JQL](https://www.atlassian.com/blog/jira-software/jql-the-most-flexible-way-to-search-jira-14) as jira filter with id `222`.
|
18
|
+
|
19
|
+
For simplicity, we are using [docker-compose](https://docs.docker.com/compose/):
|
20
|
+
1. Define yml file with `docker-compose` configuration in `lazylead.yml`
|
21
|
+
```yml
|
22
|
+
version: '2.3'
|
23
|
+
services:
|
24
|
+
lazylead:
|
25
|
+
image: dgroup/lazylead:latest
|
26
|
+
container_name: lazylead
|
27
|
+
mem_limit: 128m
|
28
|
+
environment:
|
29
|
+
# The jira server details.
|
30
|
+
# Please ensure that your jira filter(s) grants this user to see issues.
|
31
|
+
# Sometimes jira filter(s) may be created with restricted visibility, thus
|
32
|
+
# lazylead can't find the issues.
|
33
|
+
jira_url: https://your.jira.com
|
34
|
+
jira_user: theuser
|
35
|
+
jira_password: thepass
|
36
|
+
volumes:
|
37
|
+
- ./:/lazylead/db
|
38
|
+
# db/ll.db is sqlite file with jira related annoying tasks
|
39
|
+
entrypoint: bin/lazylead --sqlite db/ll.db --trace --verbose
|
40
|
+
```
|
41
|
+
|
42
|
+
2. Create a container, using `docker-compose -f lazylead.yml up`
|
43
|
+
The container will stop as there were no tasks provided:
|
44
|
+
```bash
|
45
|
+
ll > docker-compose -f lazylead.yml up
|
46
|
+
Creating lazylead ... done
|
47
|
+
Attaching to lazylead
|
48
|
+
lazylead | [2020-08-09T06:17:32] DEBUG [main] Version: 0.4.0
|
49
|
+
lazylead | [2020-08-09T06:17:32] DEBUG [main] Memory footprint at start is 52MB
|
50
|
+
lazylead | [2020-08-09T06:17:32] DEBUG [main] Database: '/lazylead/db/ll.db', sql migration dir: '/lazylead/upgrades/sqlite'
|
51
|
+
lazylead | [2020-08-09T06:17:32] DEBUG [main] Migration applied to /lazylead/db/ll.db from /lazylead/upgrades/sqlite
|
52
|
+
lazylead | [2020-08-09T06:17:32] DEBUG [main] Database connection established
|
53
|
+
lazylead | [2020-08-09T06:17:32] DEBUG [main] SMTP connection established with {host} as {user}.
|
54
|
+
lazylead | [2020-08-09T06:17:32] WARN [main] ll-001: No tasks found.
|
55
|
+
lazylead | [2020-08-09T06:17:32] DEBUG [main] Memory footprint at the end is 67MB
|
56
|
+
ll >
|
57
|
+
```
|
58
|
+
|
59
|
+
3. Define your team and tasks in database.
|
60
|
+
The tables structure defined [here](../upgrades/sqlite/001-install-main-lazylead-tables.sql).
|
61
|
+
Modify you [sqlite](https://sqlite.com/index.html) file(`ll.db`) using [DB Browser](https://sqlitebrowser.org/) or any similar tool.
|
62
|
+
```sql
|
63
|
+
insert into teams (id, name, properties)
|
64
|
+
values (1, 'Dream team with lazylead', '{}');
|
65
|
+
insert into systems(id, properties)
|
66
|
+
values (1,'{"type":"Lazylead::Jira", "username":"${jira_user}", "password":"${jira_password}", "site":"${jira_url}", "context_path":""}');
|
67
|
+
insert into tasks (name, cron, enabled, id, system, team_id, action, properties)
|
68
|
+
values ('Post ticket score and accuracy to the tickets',
|
69
|
+
'cron:0 8 * * 1-5',
|
70
|
+
'true',
|
71
|
+
1, 1, 1,
|
72
|
+
'Lazylead::Task::Accuracy',
|
73
|
+
'{
|
74
|
+
"jql": "filter=222",
|
75
|
+
"to": "lead@fake.com",
|
76
|
+
"rules": "Lazylead::AffectedBuild",
|
77
|
+
"colors": "{ "0": "#FF4F33", "35": "#FF9F33", "57": "#19DD1E", "90": "#0FA81A" }",
|
78
|
+
"docs": "https://github.com/dgroup/lazylead/blob/master/.github/ISSUE_TEMPLATE/bug_report.md",
|
79
|
+
"max_results": "200",
|
80
|
+
"subject": "[LL] Raised tickets",
|
81
|
+
"template": "lib/messages/accuracy.erb"
|
82
|
+
}
|
83
|
+
');
|
84
|
+
```
|
85
|
+
Yes, for task scheduling we are using [cron](https://crontab.guru) here, but you may use other scheduling types from [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler).
|
86
|
+
|
87
|
+
4. Once you changed `./ll.db`, please restart the container using `docker-compose -f .github/tasks.yml restart`
|
88
|
+
```bash
|
89
|
+
ll > docker-compose -f .github/tasks.yml restart
|
90
|
+
Restarting lazylead ... done
|
91
|
+
```
|
92
|
+
|
93
|
+
5. Once task completed, please check your defects, they should have comment like
|
94
|
+
![jira comment](accuracy_jira_comment.jpg)
|
95
|
+
|
96
|
+
and you'll get an email like
|
97
|
+
![email](accuracy_email.jpg)
|
98
|
+
|
99
|
+
|
100
|
+
#### Where is the code?
|
101
|
+
| Logic | Tests |
|
102
|
+
| :-----: | :------: |
|
103
|
+
| [accuracy.rb](../lib/lazylead/task/accuracy/accuracy.rb)| [accuracy_test.rb](../test/lazylead/task/accuracy/accuracy_test.rb) |
|
104
|
+
|
105
|
+
#### How can I add my own rules?
|
106
|
+
The custom rules should extend `Lazylead::Requirement` class and placed it to the `lib/lazylead/task/accuracy` folder.
|
107
|
+
After that, you need to mention your custom rules in `rules` option in the column `properties` from `tasks` table
|
Binary file
|
Binary file
|
data/.docs/duedate_expired.md
CHANGED
@@ -68,16 +68,16 @@ For simplicity, we are using [docker-compose](https://docs.docker.com/compose/):
|
|
68
68
|
values (1, 'Dream team with lazylead', '{}');
|
69
69
|
insert into systems(id, properties)
|
70
70
|
values (1,'{"type":"Lazylead::Jira", "username":"${jira_user}", "password":"${jira_password}", "site":"${jira_url}", "context_path":""}');
|
71
|
-
insert into tasks (name,
|
71
|
+
insert into tasks (name, schedule, enabled, id, system, team_id, action, properties)
|
72
72
|
values ('Expired due dates',
|
73
|
-
'0 8 * * 1-5',
|
73
|
+
'cron:0 8 * * 1-5',
|
74
74
|
'true',
|
75
75
|
1, 1, 1,
|
76
76
|
'Lazylead::Task::AssigneeAlert',
|
77
77
|
'{"sql":"filter=222", "cc":"<youremail.com>", "subject":"[LL] Expired due dates", "template":"lib/messages/due_date_expired.erb", "postman":"Lazylead::Exchange"}');
|
78
78
|
|
79
79
|
```
|
80
|
-
Yes, for task scheduling we are using [cron](https://crontab.guru).
|
80
|
+
Yes, for task scheduling we are using [cron](https://crontab.guru) here, but you may use other scheduling types from [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler).
|
81
81
|
|
82
82
|
4. Once you changed `./ll.db`, please restart the container using `docker-compose -f .github/tasks.yml restart`
|
83
83
|
```bash
|
data/.docs/propagate_down.md
CHANGED
@@ -58,16 +58,16 @@ For simplicity, we are using [docker-compose](https://docs.docker.com/compose/):
|
|
58
58
|
values (1, 'Dream team with lazylead', '{}');
|
59
59
|
insert into systems(id, properties)
|
60
60
|
values (1,'{"type":"Lazylead::Jira", "username":"${jira_user}", "password":"${jira_password}", "site":"${jira_url}", "context_path":""}');
|
61
|
-
insert into tasks (name,
|
61
|
+
insert into tasks (name, schedule, enabled, id, system, team_id, action, properties)
|
62
62
|
values ('Propagate customfield_1 (External ID) to sub-tasks',
|
63
|
-
'0 8 * * 1-5',
|
63
|
+
'cron:0 8 * * 1-5',
|
64
64
|
'true',
|
65
65
|
1, 1, 1,
|
66
66
|
'Lazylead::Task::PropagateDown',
|
67
|
-
'{"jql":"filter=222", "
|
67
|
+
'{"jql":"filter=222", "propagate":"customfield_1"}');
|
68
68
|
|
69
69
|
```
|
70
|
-
Yes, for task scheduling we are using [cron](https://crontab.guru).
|
70
|
+
Yes, for task scheduling we are using [cron](https://crontab.guru) here, but you may use other scheduling types from [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler).
|
71
71
|
|
72
72
|
4. Once you changed `./ll.db`, please restart the container using `docker-compose -f .github/tasks.yml restart`
|
73
73
|
```bash
|
data/.gitattributes
CHANGED
data/.pdd
CHANGED
data/.rubocop.yml
CHANGED
@@ -77,6 +77,12 @@ Style/HashTransformKeys:
|
|
77
77
|
Style/HashTransformValues:
|
78
78
|
Enabled: true
|
79
79
|
|
80
|
+
# @todo #/DEV accuracy.rb is using % symbol in text message and rubocop
|
81
|
+
# complains about it. It's false-positive violation, thus, for now ignored for this file
|
82
|
+
Style/FormatStringToken:
|
83
|
+
Exclude:
|
84
|
+
- "lib/lazylead/task/accuracy/accuracy.rb"
|
85
|
+
|
80
86
|
Lint/RaiseException:
|
81
87
|
Enabled: true
|
82
88
|
|
data/Rakefile
CHANGED
@@ -127,4 +127,6 @@ task :docker do
|
|
127
127
|
system "docker-compose -f .docker/docker-compose.yml build "\
|
128
128
|
" --build-arg release_tags='latest 1.0'"\
|
129
129
|
" --build-arg version=1.0"
|
130
|
+
system "docker-compose -f .docker/docker-compose.yml rm --force -s lazylead"
|
131
|
+
system "docker-compose -f .docker/docker-compose.yml up"
|
130
132
|
end
|
data/bin/lazylead
CHANGED
@@ -39,11 +39,14 @@ require_relative "../lib/lazylead/schedule"
|
|
39
39
|
require_relative "../lib/lazylead/allocated"
|
40
40
|
require_relative "../lib/lazylead/cli/app"
|
41
41
|
|
42
|
-
log = Lazylead::Log
|
42
|
+
log = Lazylead::Log.new
|
43
43
|
Thread.current.name = "main"
|
44
|
+
Logging.mdc["tid"] = Thread.current.name
|
44
45
|
Encoding.default_external = Encoding::UTF_8
|
45
46
|
Encoding.default_internal = Encoding::UTF_8
|
46
47
|
|
48
|
+
# @todo #/DEV Decorate ARGV with custom methods in order to avoid code
|
49
|
+
# duplication, like { ARGV.include? "--trace" }
|
47
50
|
opts = Slop.parse(ARGV, strict: false, suppress_errors: true) do |o|
|
48
51
|
o.banner = "Usage: lazylead [options]
|
49
52
|
Available options:"
|
@@ -67,7 +70,7 @@ Available options:"
|
|
67
70
|
"Apply the database VCS migration with test data",
|
68
71
|
default: false
|
69
72
|
o.on "--verbose", "Enable extra logging information" do
|
70
|
-
log
|
73
|
+
log.verbose
|
71
74
|
end
|
72
75
|
o.on "-v", "--version", "Show current version" do
|
73
76
|
log.debug Lazylead::VERSION
|
@@ -79,7 +82,7 @@ log.debug("Memory footprint at start is #{Lazylead::Allocated.new}")
|
|
79
82
|
cmd = lambda do
|
80
83
|
Lazylead::CLI::App.new(
|
81
84
|
log,
|
82
|
-
Lazylead::Schedule.new(log),
|
85
|
+
Lazylead::Schedule.new(log: log),
|
83
86
|
Lazylead::Smtp.new(
|
84
87
|
log, Lazylead::Salt.new("smtp_salt"),
|
85
88
|
smtp_host: ENV["smtp_host"],
|
@@ -91,7 +94,7 @@ cmd = lambda do
|
|
91
94
|
return 0
|
92
95
|
rescue StandardError => e
|
93
96
|
log.error("#{e.message} (#{e.class.name})")
|
94
|
-
log.error(Backtrace.new(e)) if
|
97
|
+
log.error(Backtrace.new(e)) if ARGV.include? "--trace"
|
95
98
|
return -1
|
96
99
|
end
|
97
100
|
code = 0
|
data/lazylead.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
s.rubygems_version = "2.2"
|
33
33
|
s.required_ruby_version = ">=2.6.5"
|
34
34
|
s.name = "lazylead"
|
35
|
-
s.version = "0.
|
35
|
+
s.version = "0.5.0"
|
36
36
|
s.license = "MIT"
|
37
37
|
s.summary = "Eliminate the annoying work within bug-trackers."
|
38
38
|
s.description = "Ticketing systems (Github, Jira, etc.) are strongly
|
@@ -45,7 +45,7 @@ tasks instead of solving technical problems."
|
|
45
45
|
s.authors = ["Yurii Dubinka"]
|
46
46
|
s.email = "yurii.dubinka@gmail.com"
|
47
47
|
s.homepage = "http://github.com/dgroup/lazylead"
|
48
|
-
s.post_install_message = "Thanks for installing Lazylead v0.
|
48
|
+
s.post_install_message = "Thanks for installing Lazylead v0.5.0!
|
49
49
|
Read our blog posts: https://lazylead.org
|
50
50
|
Stay in touch with the community in Telegram: https://t.me/lazylead
|
51
51
|
Follow us on Twitter: https://twitter.com/lazylead
|
@@ -60,7 +60,7 @@ tasks instead of solving technical problems."
|
|
60
60
|
s.add_runtime_dependency "faraday", "1.0.1"
|
61
61
|
s.add_runtime_dependency "get_process_mem", "0.2.5"
|
62
62
|
s.add_runtime_dependency "jira-ruby", "1.7.1"
|
63
|
-
s.add_runtime_dependency "json", "2.
|
63
|
+
s.add_runtime_dependency "json", "2.3.0"
|
64
64
|
s.add_runtime_dependency "logging", "2.2.2"
|
65
65
|
s.add_runtime_dependency "mail", "2.7.1"
|
66
66
|
s.add_runtime_dependency "memory_profiler", "0.9.13"
|
@@ -75,13 +75,14 @@ tasks instead of solving technical problems."
|
|
75
75
|
s.add_runtime_dependency "tzinfo-data", "1.2019.3"
|
76
76
|
s.add_runtime_dependency "vcs4sql", "0.1.0"
|
77
77
|
s.add_runtime_dependency "viewpoint", "1.1.0"
|
78
|
-
s.add_development_dependency "codecov", "0.
|
78
|
+
s.add_development_dependency "codecov", "0.2.3"
|
79
79
|
s.add_development_dependency "guard", "2.15.0"
|
80
80
|
s.add_development_dependency "guard-minitest", "2.4.6"
|
81
81
|
s.add_development_dependency "minitest", "5.11.3"
|
82
82
|
s.add_development_dependency "minitest-fail-fast", "0.1.0"
|
83
83
|
s.add_development_dependency "minitest-hooks", "1.5.0"
|
84
84
|
s.add_development_dependency "minitest-reporters", "1.3.6"
|
85
|
+
s.add_development_dependency "net-ping", "2.0.8"
|
85
86
|
s.add_development_dependency "rake", "12.3.3"
|
86
87
|
s.add_development_dependency "random-port", "0.3.1"
|
87
88
|
s.add_development_dependency "rdoc", "6.1.1"
|
data/lib/lazylead/exchange.rb
CHANGED
@@ -42,7 +42,7 @@ module Lazylead
|
|
42
42
|
include Emailing
|
43
43
|
|
44
44
|
def initialize(
|
45
|
-
log = Log
|
45
|
+
log = Log.new, salt = Salt.new("exchange_salt"), opts = ENV.to_h
|
46
46
|
)
|
47
47
|
@log = log
|
48
48
|
@salt = salt
|
@@ -54,19 +54,26 @@ module Lazylead
|
|
54
54
|
def send(opts)
|
55
55
|
to = opts["to"] || opts[:to]
|
56
56
|
to = [to] unless to.is_a? Array
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
to_recipients: to
|
63
|
-
}
|
57
|
+
if to.reject { |e| e.nil? || e.blank? }.empty?
|
58
|
+
@log.warn "Email can't be sent to '#{to}, more: '#{opts}'"
|
59
|
+
return
|
60
|
+
end
|
61
|
+
msg = make_msg(to, opts)
|
64
62
|
msg.update(cc_recipients: opts["cc"]) if opts.key? "cc"
|
65
63
|
add_attachments(msg, opts)
|
66
64
|
cli.send_message msg
|
67
65
|
close_attachments msg
|
68
66
|
@log.debug "Email was generated from #{opts} and send by #{__FILE__}. " \
|
69
|
-
"Here is the body: #{
|
67
|
+
"Here is the body: '#{msg[:body]}'"
|
68
|
+
end
|
69
|
+
|
70
|
+
def make_msg(to, opts)
|
71
|
+
{
|
72
|
+
subject: opts["subject"],
|
73
|
+
body: make_body(opts),
|
74
|
+
body_type: "HTML",
|
75
|
+
to_recipients: to
|
76
|
+
}
|
70
77
|
end
|
71
78
|
|
72
79
|
def add_attachments(msg, opts)
|
data/lib/lazylead/log.rb
CHANGED
@@ -23,16 +23,38 @@
|
|
23
23
|
# OR OTHER DEALINGS IN THE SOFTWARE.
|
24
24
|
|
25
25
|
require "logging"
|
26
|
+
require "forwardable"
|
26
27
|
|
27
28
|
module Lazylead
|
28
|
-
#
|
29
|
+
# The main application logger
|
30
|
+
class Log
|
31
|
+
extend Forwardable
|
32
|
+
def_delegators :@log, :debug, :info, :warn, :error
|
33
|
+
|
34
|
+
def initialize(log = Lazylead::Level::ERRORS)
|
35
|
+
@log = log
|
36
|
+
@log = Lazylead::Level::DEBUG if ARGV.include? "--trace"
|
37
|
+
end
|
38
|
+
|
39
|
+
def nothing
|
40
|
+
@log = Lazylead::Level::NOTHING
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def verbose
|
45
|
+
@log = Lazylead::Level::DEBUG
|
46
|
+
self
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Predefined logging levels.
|
29
51
|
#
|
30
52
|
# There are 3 colored loggers so far:
|
31
53
|
# NOTHING - for cases when logging isn't required
|
32
54
|
# VERBOSE - all logging levels including debug
|
33
55
|
# ERRORS - for errors only which are critical for app.
|
34
56
|
#
|
35
|
-
module
|
57
|
+
module Level
|
36
58
|
# Coloring configuration for appender(s).
|
37
59
|
Logging.color_scheme("bright",
|
38
60
|
levels: {
|
@@ -46,7 +68,7 @@ module Lazylead
|
|
46
68
|
Logging.appenders.stdout(
|
47
69
|
"stdout",
|
48
70
|
layout: Logging.layouts.pattern(
|
49
|
-
pattern: "[%d] %-5l %m\n",
|
71
|
+
pattern: "[%d] %-5l [%X{tid}] %m\n",
|
50
72
|
color_scheme: "bright"
|
51
73
|
)
|
52
74
|
)
|
@@ -57,12 +79,12 @@ module Lazylead
|
|
57
79
|
NOTHING.freeze
|
58
80
|
|
59
81
|
# All levels including debug
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
82
|
+
DEBUG = Logging.logger["debug"]
|
83
|
+
DEBUG.level = :debug
|
84
|
+
DEBUG.add_appenders "stdout"
|
85
|
+
DEBUG.freeze
|
64
86
|
|
65
|
-
# Alerts
|
87
|
+
# Alerts/errors
|
66
88
|
ERRORS = Logging.logger["errors"]
|
67
89
|
ERRORS.level = :error
|
68
90
|
ERRORS.add_appenders "stdout"
|
data/lib/lazylead/model.rb
CHANGED
@@ -22,12 +22,15 @@
|
|
22
22
|
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
23
23
|
# OR OTHER DEALINGS IN THE SOFTWARE.
|
24
24
|
|
25
|
-
require "
|
25
|
+
require "backtrace"
|
26
26
|
require "require_all"
|
27
|
+
require "forwardable"
|
28
|
+
require "active_record"
|
27
29
|
require_rel "task"
|
28
30
|
require_rel "system"
|
29
31
|
require_relative "cc"
|
30
32
|
require_relative "log"
|
33
|
+
require_relative "opts"
|
31
34
|
require_relative "postman"
|
32
35
|
require_relative "exchange"
|
33
36
|
|
@@ -91,18 +94,31 @@ module Lazylead
|
|
91
94
|
belongs_to :team, foreign_key: "team_id"
|
92
95
|
belongs_to :system, foreign_key: "system"
|
93
96
|
|
94
|
-
#
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
def exec(log = Log::NOTHING)
|
99
|
-
log.debug("Task ##{id} '#{name}' is started")
|
100
|
-
sys = system.connect(log)
|
101
|
-
pman = postman(log)
|
102
|
-
opts = props(log)
|
97
|
+
# Execute task
|
98
|
+
def exec
|
99
|
+
sys = system.connect
|
100
|
+
opts = props
|
103
101
|
opts = detect_cc(sys) if opts.key? "cc"
|
104
|
-
action.constantize.new
|
105
|
-
|
102
|
+
action.constantize.new.run(sys, postman, opts)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Scheduling type.
|
106
|
+
# Current implementation is based on 'rufus-scheduler' gem and supports
|
107
|
+
# the following types: 'cron', 'interval', 'in', 'at', 'every'
|
108
|
+
def type
|
109
|
+
trigger.first
|
110
|
+
end
|
111
|
+
|
112
|
+
# Scheduling unit.
|
113
|
+
# Current implementation is based on 'rufus-scheduler' gem thus each
|
114
|
+
# scheduling type has own arguments:
|
115
|
+
# 1. Scheduling type 'cron' has 'unit' = '00 09 * * *'
|
116
|
+
# 2. Scheduling type 'interval' has 'unit' = '2h'
|
117
|
+
# 3. Scheduling type 'every' has 'unit' = '3h'
|
118
|
+
# 4. Scheduling type 'in' has 'unit' = '10d'
|
119
|
+
# 5. Scheduling type 'at' has 'unit' = '2014/12/24 2000'
|
120
|
+
def unit
|
121
|
+
trigger.last
|
106
122
|
end
|
107
123
|
|
108
124
|
def detect_cc(sys)
|
@@ -112,25 +128,66 @@ module Lazylead
|
|
112
128
|
opts
|
113
129
|
end
|
114
130
|
|
115
|
-
def props
|
131
|
+
def props
|
116
132
|
@props ||= begin
|
117
133
|
if team.nil?
|
118
|
-
|
119
|
-
env(to_hash)
|
134
|
+
Opts.new(env(to_hash))
|
120
135
|
else
|
121
|
-
env(team.to_hash.merge(to_hash))
|
136
|
+
Opts.new(env(team.to_hash.merge(to_hash)))
|
122
137
|
end
|
123
138
|
end
|
124
139
|
end
|
125
140
|
|
126
|
-
def postman
|
141
|
+
def postman
|
127
142
|
if props.key? "postman"
|
128
|
-
props["postman"].constantize.new
|
143
|
+
props["postman"].constantize.new
|
129
144
|
else
|
130
|
-
log.warn "No postman details provided, an local stub is used."
|
131
145
|
Postman.new
|
132
146
|
end
|
133
147
|
end
|
148
|
+
|
149
|
+
private
|
150
|
+
|
151
|
+
# Parse scheduling #type and #unit
|
152
|
+
def trigger
|
153
|
+
@trigger ||= begin
|
154
|
+
trg = schedule.split(":")
|
155
|
+
unless trg.size == 2
|
156
|
+
raise "ll-007: illegal schedule format '#{schedule}'"
|
157
|
+
end
|
158
|
+
trg.map(&:strip).map(&:chomp)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
# A task with extended logging
|
164
|
+
# @see Lazylead::ORM::Task
|
165
|
+
class VerboseTask
|
166
|
+
extend Forwardable
|
167
|
+
def_delegators :@orig, :id, :name, :team, :to_s, :inspect, :props, :type,
|
168
|
+
:unit
|
169
|
+
|
170
|
+
def initialize(orig, log = Log.new)
|
171
|
+
@orig = orig
|
172
|
+
@log = log
|
173
|
+
end
|
174
|
+
|
175
|
+
def exec
|
176
|
+
Logging.mdc["tid"] = "task #{id}"
|
177
|
+
@log.debug "'#{name}' is started."
|
178
|
+
@log.warn "No postman, stub is used." unless props.key? "postman"
|
179
|
+
@log.warn "No team." if team.nil?
|
180
|
+
@orig.exec
|
181
|
+
@log.debug "'#{name}' is completed"
|
182
|
+
rescue StandardError => e
|
183
|
+
msg = <<~MSG
|
184
|
+
ll-006: Task ##{id} #{e} (#{e.class}) at #{self}
|
185
|
+
#{Backtrace.new(e) if ARGV.include? '--trace'}"
|
186
|
+
MSG
|
187
|
+
@log.error msg
|
188
|
+
ensure
|
189
|
+
Logging.mdc["tid"] = ""
|
190
|
+
end
|
134
191
|
end
|
135
192
|
|
136
193
|
# Ticketing systems to monitor.
|
@@ -138,7 +195,7 @@ module Lazylead
|
|
138
195
|
include ORM
|
139
196
|
|
140
197
|
# Make an instance of ticketing system for future interaction.
|
141
|
-
def connect(log = Log
|
198
|
+
def connect(log = Log.new)
|
142
199
|
opts = to_hash
|
143
200
|
if opts["type"].empty?
|
144
201
|
log.warn "No task system details provided, an empty stub is used."
|
@@ -146,8 +203,7 @@ module Lazylead
|
|
146
203
|
else
|
147
204
|
opts["type"].constantize.new(
|
148
205
|
env(opts.except("type", "salt")),
|
149
|
-
opts["salt"].blank? ? NoSalt.new : Salt.new(opts["salt"])
|
150
|
-
log
|
206
|
+
opts["salt"].blank? ? NoSalt.new : Salt.new(opts["salt"])
|
151
207
|
)
|
152
208
|
end
|
153
209
|
end
|