lazylead 0.3.0 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.0pdd.yml +4 -1
  3. data/.circleci/config.yml +2 -0
  4. data/.docs/accuracy.md +107 -0
  5. data/.docs/accuracy_email.jpg +0 -0
  6. data/.docs/accuracy_jira_comment.jpg +0 -0
  7. data/.docs/propagate_down.md +1 -1
  8. data/.github/dependabot.yml +6 -0
  9. data/.pdd +1 -1
  10. data/.rubocop.yml +6 -0
  11. data/bin/lazylead +9 -3
  12. data/lazylead.gemspec +5 -4
  13. data/lib/lazylead/cc.rb +12 -6
  14. data/lib/lazylead/cli/app.rb +4 -3
  15. data/lib/lazylead/exchange.rb +1 -1
  16. data/lib/lazylead/log.rb +30 -8
  17. data/lib/lazylead/model.rb +44 -18
  18. data/lib/lazylead/opts.rb +68 -0
  19. data/lib/lazylead/postman.rb +1 -1
  20. data/lib/lazylead/schedule.rb +6 -4
  21. data/lib/lazylead/smtp.rb +1 -1
  22. data/lib/lazylead/system/fake.rb +1 -1
  23. data/lib/lazylead/system/jira.rb +17 -15
  24. data/lib/lazylead/system/synced.rb +2 -1
  25. data/lib/lazylead/task/accuracy/accuracy.rb +140 -0
  26. data/lib/lazylead/task/accuracy/affected_build.rb +43 -0
  27. data/lib/lazylead/task/accuracy/requirement.rb +40 -0
  28. data/lib/lazylead/task/alert.rb +8 -6
  29. data/lib/lazylead/task/confluence_ref.rb +4 -3
  30. data/lib/lazylead/task/echo.rb +4 -0
  31. data/lib/lazylead/task/fix_version.rb +10 -6
  32. data/lib/lazylead/task/missing_comment.rb +7 -5
  33. data/lib/lazylead/task/propagate_down.rb +11 -3
  34. data/lib/lazylead/task/savepoint.rb +1 -1
  35. data/lib/lazylead/task/touch.rb +104 -0
  36. data/lib/lazylead/version.rb +1 -1
  37. data/lib/messages/accuracy.erb +118 -0
  38. data/lib/messages/svn_touch.erb +147 -0
  39. data/readme.md +19 -18
  40. data/test/lazylead/cc_test.rb +22 -2
  41. data/test/lazylead/cli/app_test.rb +2 -2
  42. data/test/lazylead/exchange_test.rb +3 -3
  43. data/test/lazylead/model_test.rb +4 -4
  44. data/test/lazylead/opts_test.rb +70 -0
  45. data/test/lazylead/postman_test.rb +1 -1
  46. data/test/lazylead/smtp_test.rb +1 -1
  47. data/test/lazylead/system/jira_test.rb +35 -1
  48. data/test/lazylead/task/accuracy/accuracy_test.rb +73 -0
  49. data/test/lazylead/task/accuracy/affected_build_test.rb +42 -0
  50. data/test/lazylead/task/assignee_alert_test.rb +2 -2
  51. data/test/lazylead/task/duedate_test.rb +37 -27
  52. data/test/lazylead/task/fix_version_test.rb +9 -6
  53. data/test/lazylead/task/missing_comment_test.rb +11 -9
  54. data/test/lazylead/task/propagate_down_test.rb +4 -2
  55. data/test/lazylead/task/touch_test.rb +61 -0
  56. data/test/test.rb +9 -0
  57. data/upgrades/sqlite/999.testdata.sql +2 -1
  58. metadata +40 -8
  59. data/todo.yml +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1515ec779095fe067759c774a8f81a7f563d55e7f7c9dc9f8cb96644688d1a7e
4
- data.tar.gz: dfe37f6ed725f609ea1c685c85d17581a87dea40ff1bc3be7967cb15d5c81405
3
+ metadata.gz: cd5d4e1e8d89064bfa868e1c088166d3a42b4c155fde98246979a262854d15b0
4
+ data.tar.gz: fa0d3aefc186740945b1da68318aebe1d597d7b88f70b079644058f5e201126b
5
5
  SHA512:
6
- metadata.gz: 24246a8ef909f298256a358e6c59778b5e9440aeb8dadfd32dbae21a079832ef3ee6e8126949803784aa2543866626ee3e71a0ee1ef5a102d725b0269aef155c
7
- data.tar.gz: 445720af7f02f9497b9baf42b2657ea4c428fd2f088d72b1db03b9679f617fc45f049ba6af22dc9e05669c41c0d262fc63d76be06df051ab7e0cbf7f79a03923
6
+ metadata.gz: 7b018d644048900e19d03bbf8b24847a0b617ba74721f213743687b90d1cc2078ca84f35af29c2660b73207e5fc5b86d4b9e45d3394d9c095645198400602dfe
7
+ data.tar.gz: 842cf53e33f2376891d80dcd7f7802f2a27a37bf26ea42a55c88d4b53925b6a161b3962cbc7df0467c2c1049532db8029977c78776340e938cc20f757f5d89b3
data/.0pdd.yml CHANGED
@@ -1,5 +1,8 @@
1
1
  errors:
2
2
  - yurii.dubinka@gmail.com
3
-
3
+ alerts:
4
+ suppress:
5
+ - on-found-puzzle
6
+ - on-lost-puzzle
4
7
  tags:
5
8
  - pdd
@@ -21,6 +21,7 @@ jobs:
21
21
  command: |
22
22
  set -e
23
23
  COMMIT_URL="https://github.com/dgroup/lazylead/commit/${CIRCLE_SHA1}"
24
+ sed -i "s/0\.0\.0/${DOCKER_RELEASE_TAGS}/g" lib/lazylead/version.rb
24
25
  docker build --build-arg release_tags="${CIRCLE_SHA1}, ${CIRCLE_BRANCH}, ${COMMIT_URL}" --build-arg version="${DOCKER_RELEASE_TAGS:7}" \
25
26
  -t dgroup/lazylead:$CIRCLE_BRANCH . \
26
27
  -f .docker/Dockerfile
@@ -40,6 +41,7 @@ jobs:
40
41
  name: "Build & push LL VCS image"
41
42
  command: |
42
43
  sed -i "s/0\.0\.0/${DOCKER_RELEASE_TAGS}/g" .docker/vcs.dockerfile
44
+ sed -i "s/0\.0\.0/${DOCKER_RELEASE_TAGS}/g" lib/lazylead/version.rb
43
45
  docker build -t dgroup/lazylead:${DOCKER_RELEASE_TAGS}-vcs . -f .docker/vcs.dockerfile
44
46
  docker push dgroup/lazylead:${DOCKER_RELEASE_TAGS}-vcs
45
47
  - run:
@@ -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
+ '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).
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
@@ -64,7 +64,7 @@ For simplicity, we are using [docker-compose](https://docs.docker.com/compose/):
64
64
  'true',
65
65
  1, 1, 1,
66
66
  'Lazylead::Task::PropagateDown',
67
- '{"jql":"filter=222", "fields":"customfield_1"}');
67
+ '{"jql":"filter=222", "propagate":"customfield_1"}');
68
68
 
69
69
  ```
70
70
  Yes, for task scheduling we are using [cron](https://crontab.guru).
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "bundler"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "daily"
data/.pdd CHANGED
@@ -2,4 +2,4 @@
2
2
  --verbose
3
3
  --exclude target/**/*
4
4
  --exclude coverage/**/*
5
- --rule min-words:5
5
+ --rule min-words:7
@@ -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
 
@@ -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::ERRORS
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:"
@@ -60,11 +63,14 @@ Available options:"
60
63
  o.string "--vcs4sql",
61
64
  "Home directory with database version control(vcs) scripts",
62
65
  default: "upgrades/sqlite"
66
+ o.integer "--max-connections",
67
+ "SQL connections pool size",
68
+ default: 5
63
69
  o.bool "--testdata",
64
70
  "Apply the database VCS migration with test data",
65
71
  default: false
66
72
  o.on "--verbose", "Enable extra logging information" do
67
- log = Lazylead::Log::VERBOSE
73
+ log.verbose
68
74
  end
69
75
  o.on "-v", "--version", "Show current version" do
70
76
  log.debug Lazylead::VERSION
@@ -88,7 +94,7 @@ cmd = lambda do
88
94
  return 0
89
95
  rescue StandardError => e
90
96
  log.error("#{e.message} (#{e.class.name})")
91
- log.error(Backtrace.new(e)) if opts["trace"]
97
+ log.error(Backtrace.new(e)) if ARGV.include? "--trace"
92
98
  return -1
93
99
  end
94
100
  code = 0
@@ -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.3.0"
35
+ s.version = "0.4.3"
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.3.0!
48
+ s.post_install_message = "Thanks for installing Lazylead v0.4.3!
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.2.0"
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.1.14"
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"
@@ -37,20 +37,26 @@ module Lazylead
37
37
  # - Empty
38
38
  #
39
39
  def detect(emails, sys)
40
+ return emails if recognized?(emails)
40
41
  return PlainCC.new(emails) if plain?(emails)
41
- return EmptyCC unless emails.key? "type"
42
- return EmptyCC if emails["type"].blank? || emails["type"].nil?
42
+ return EmptyCC.new if undefined?(emails)
43
43
  type = emails["type"].constantize
44
44
  return ComponentCC.new(emails["project"], sys) if type.is_a? ComponentCC
45
45
  type.new(emails["opts"])
46
46
  end
47
47
 
48
- private
49
-
50
48
  # Detect that raw CC is a string which may has plain email addresses
51
49
  def plain?(text)
52
- (text.is_a? String) &&
53
- (text.to_s.include?(",") || text.to_s.include?("@"))
50
+ (text.is_a? String) && text.to_s.include?("@")
51
+ end
52
+
53
+ def recognized?(emails)
54
+ [EmptyCC, PlainCC, ComponentCC, PredefinedCC].member? emails.class
55
+ end
56
+
57
+ def undefined?(emails)
58
+ return true unless emails.key? "type"
59
+ emails["type"].nil? || emails["type"].blank?
54
60
  end
55
61
  end
56
62
 
@@ -48,7 +48,7 @@ module Lazylead
48
48
 
49
49
  def run(opts)
50
50
  apply_vcs_migration opts
51
- enable_active_record
51
+ enable_active_record opts
52
52
  @smtp.enable
53
53
  schedule_tasks
54
54
  end
@@ -63,10 +63,11 @@ module Lazylead
63
63
  @log.debug "Migration applied to #{@db} from #{vcs}"
64
64
  end
65
65
 
66
- def enable_active_record
66
+ def enable_active_record(opts)
67
67
  ActiveRecord::Base.establish_connection(
68
68
  adapter: "sqlite3",
69
- database: @db
69
+ database: @db,
70
+ pool: opts[:max_connections]
70
71
  )
71
72
  @log.debug "Database connection established"
72
73
  end
@@ -42,7 +42,7 @@ module Lazylead
42
42
  include Emailing
43
43
 
44
44
  def initialize(
45
- log = Log::NOTHING, salt = Salt.new("exchange_salt"), opts = ENV.to_h
45
+ log = Log.new, salt = Salt.new("exchange_salt"), opts = ENV.to_h
46
46
  )
47
47
  @log = log
48
48
  @salt = salt
@@ -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
- # Loggers.
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 Log
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
- VERBOSE = Logging.logger["verbose"]
61
- VERBOSE.level = :debug
62
- VERBOSE.add_appenders "stdout"
63
- VERBOSE.freeze
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"
@@ -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 "active_record"
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,14 +94,11 @@ module Lazylead
91
94
  belongs_to :team, foreign_key: "team_id"
92
95
  belongs_to :system, foreign_key: "system"
93
96
 
94
- def exec(log = Log::NOTHING)
95
- log.debug("Task ##{id} '#{name}' is started")
96
- sys = system.connect(log)
97
- pman = postman(log)
98
- opts = props(log)
97
+ def exec
98
+ sys = system.connect
99
+ opts = props
99
100
  opts = detect_cc(sys) if opts.key? "cc"
100
- action.constantize.new(log).run(sys, pman, opts)
101
- log.debug("Task ##{id} '#{name}' is completed")
101
+ action.constantize.new.run(sys, postman, opts)
102
102
  end
103
103
 
104
104
  def detect_cc(sys)
@@ -108,33 +108,60 @@ module Lazylead
108
108
  opts
109
109
  end
110
110
 
111
- def props(log = Log::NOTHING)
111
+ def props
112
112
  @props ||= begin
113
113
  if team.nil?
114
- log.warn("Team for task #{id} isn't defined.")
115
- env(to_hash)
114
+ Opts.new(env(to_hash))
116
115
  else
117
- env(team.to_hash.merge(to_hash))
116
+ Opts.new(env(team.to_hash.merge(to_hash)))
118
117
  end
119
118
  end
120
119
  end
121
120
 
122
- def postman(log = Log::NOTHING)
121
+ def postman
123
122
  if props.key? "postman"
124
- props["postman"].constantize.new(log)
123
+ props["postman"].constantize.new
125
124
  else
126
- log.warn "No postman details provided, an local stub is used."
127
125
  Postman.new
128
126
  end
129
127
  end
130
128
  end
131
129
 
130
+ # A task with extended logging
131
+ # @see Lazylead::ORM::Task
132
+ class VerboseTask
133
+ extend Forwardable
134
+ def_delegators :@orig, :id, :name, :team, :to_s, :inspect, :props
135
+
136
+ def initialize(orig, log = Log.new)
137
+ @orig = orig
138
+ @log = log
139
+ end
140
+
141
+ def exec
142
+ Logging.mdc["tid"] = "task #{id}"
143
+ @log.debug "'#{name}' is started."
144
+ @log.warn "No postman, stub is used." unless props.key? "postman"
145
+ @log.warn "No team." if team.nil?
146
+ @orig.exec
147
+ @log.debug "'#{name}' is completed"
148
+ rescue StandardError => e
149
+ msg = <<~MSG
150
+ ll-006: Task ##{id} #{e} (#{e.class}) at #{self}
151
+ #{Backtrace.new(e) if ARGV.include? '--trace'}"
152
+ MSG
153
+ @log.error msg
154
+ ensure
155
+ Logging.mdc["tid"] = ""
156
+ end
157
+ end
158
+
132
159
  # Ticketing systems to monitor.
133
160
  class System < ActiveRecord::Base
134
161
  include ORM
135
162
 
136
163
  # Make an instance of ticketing system for future interaction.
137
- def connect(log = Log::NOTHING)
164
+ def connect(log = Log.new)
138
165
  opts = to_hash
139
166
  if opts["type"].empty?
140
167
  log.warn "No task system details provided, an empty stub is used."
@@ -142,8 +169,7 @@ module Lazylead
142
169
  else
143
170
  opts["type"].constantize.new(
144
171
  env(opts.except("type", "salt")),
145
- opts["salt"].blank? ? NoSalt.new : Salt.new(opts["salt"]),
146
- log
172
+ opts["salt"].blank? ? NoSalt.new : Salt.new(opts["salt"])
147
173
  )
148
174
  end
149
175
  end