jobly 0.5.10 → 0.5.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/bin/jobly +5 -5
  3. data/lib/jobly/api.rb +9 -10
  4. data/lib/jobly/cli.rb +4 -5
  5. data/lib/jobly/commands/base.rb +1 -1
  6. data/lib/jobly/commands/config.rb +7 -7
  7. data/lib/jobly/commands/info.rb +13 -12
  8. data/lib/jobly/commands/init.rb +7 -7
  9. data/lib/jobly/commands/run.rb +10 -11
  10. data/lib/jobly/commands/send.rb +7 -8
  11. data/lib/jobly/commands/server.rb +5 -5
  12. data/lib/jobly/commands/worker.rb +13 -11
  13. data/lib/jobly/exceptions.rb +1 -1
  14. data/lib/jobly/extensions/integer.rb +5 -5
  15. data/lib/jobly/helpers/logging.rb +1 -1
  16. data/lib/jobly/helpers/settings.rb +1 -1
  17. data/lib/jobly/helpers/shell.rb +2 -2
  18. data/lib/jobly/helpers/slack.rb +4 -4
  19. data/lib/jobly/job.rb +2 -5
  20. data/lib/jobly/job_extensions/actions.rb +0 -1
  21. data/lib/jobly/job_extensions/isolation.rb +2 -2
  22. data/lib/jobly/job_extensions/option_accessors.rb +1 -3
  23. data/lib/jobly/job_extensions/solo.rb +1 -2
  24. data/lib/jobly/jobs.rb +0 -1
  25. data/lib/jobly/log.rb +19 -20
  26. data/lib/jobly/module_functions.rb +23 -28
  27. data/lib/jobly/refinements/argument_converters.rb +2 -2
  28. data/lib/jobly/refinements/convert_to_typed.rb +4 -3
  29. data/lib/jobly/refinements/keyword_args.rb +3 -3
  30. data/lib/jobly/refinements/to_slug.rb +1 -1
  31. data/lib/jobly/server.rb +4 -8
  32. data/lib/jobly/sidekiq.rb +2 -2
  33. data/lib/jobly/templates/full/Gemfile +3 -3
  34. data/lib/jobly/templates/full/app/job.rb +1 -1
  35. data/lib/jobly/templates/full/app/other_class.rb +1 -1
  36. data/lib/jobly/templates/full/config/jobly.rb +1 -1
  37. data/lib/jobly/templates/full/jobs/hello.rb +4 -4
  38. data/lib/jobly/templates/minimal/Gemfile +2 -2
  39. data/lib/jobly/version.rb +2 -2
  40. data/lib/jobly.rb +0 -1
  41. metadata +39 -45
  42. data/lib/jobly/polyfills/hash.rb +0 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b5ba086caf0586dc1f3288e226f43f57ba28489699003aac476d993e16d85a4
4
- data.tar.gz: 2173fdc529c0db42dfb0ecb13ca1cc7db844ae09b58c8c83c89babc4aee5a384
3
+ metadata.gz: 62fba0cb854e3268a518c5779f247f465af83e85caaacb9a4442e907685e336a
4
+ data.tar.gz: d671bae5e151d244c1a901eb3a353be41810bfb9d0e328e471b444ca2f7d9495
5
5
  SHA512:
6
- metadata.gz: f8cef9ac3cb84b61d5106de2025ab4979fc4d5347115fe988f449936999a0e5a6b00e18f593238076299f52eac9194fb03f9e34ff8e37769037a556e12b84e5b
7
- data.tar.gz: 330ef65250ad8375795d4577bfce549ca43499053f445e6c78f442fcb74507a5b74c878497da80c44be17945fedbfbacbc82e7de6e3f923a5b259e05d783bf44
6
+ metadata.gz: 6918115853f589511eb2e3152ecbc45eb62576e76bd82c280a93ff121522d23ec99528a029200cef5d516f7ab3d26bba5c12b80f5976d148c7ec826711cec05e
7
+ data.tar.gz: 592f0f2142e689fcf33b435c39649a170d92cb1c5aec69a4b8b26cbd2ac15028ff261c73c8360f451f220ea222bac4386bc3d574a8fcfc654aaeba668bcd851a
data/bin/jobly CHANGED
@@ -4,11 +4,11 @@ require 'jobly'
4
4
  require 'jobly/boot'
5
5
 
6
6
  PrettyTrace.filter [
7
- %r[mister_bin],
8
- %r[bin/jobly],
9
- %r[bin/ruby],
10
- %r[lib/ruby],
11
- %r[lib/jobly],
7
+ /mister_bin/,
8
+ %r{bin/jobly},
9
+ %r{bin/ruby},
10
+ %r{lib/ruby},
11
+ %r{lib/jobly},
12
12
  ]
13
13
 
14
14
  router = Jobly::CLI.router
data/lib/jobly/api.rb CHANGED
@@ -6,7 +6,6 @@ require 'sinatra/reloader'
6
6
  require 'sinatra/custom_logger'
7
7
 
8
8
  module Jobly
9
-
10
9
  class API < Sinatra::Application
11
10
  helpers Sinatra::CustomLogger
12
11
  using ConvertToTyped
@@ -27,7 +26,7 @@ module Jobly
27
26
  get '/' do
28
27
  {
29
28
  version: Jobly::VERSION,
30
- message: %Q["I'm gonna live till I die" - Frank Sinatra]
29
+ message: %["I'm gonna live till I die" - Frank Sinatra],
31
30
  }.to_json + "\n"
32
31
  end
33
32
 
@@ -45,15 +44,15 @@ module Jobly
45
44
 
46
45
  private
47
46
 
48
- def add_job(job, args={})
47
+ def add_job(job, args = {})
49
48
  job_class = Jobs.get_class job
50
49
 
51
- if !job_class
50
+ unless job_class
52
51
  response = {
53
- status: 'error',
52
+ status: 'error',
54
53
  message: 'No such job',
55
- job: job,
56
- params: args
54
+ job: job,
55
+ params: args,
57
56
  }
58
57
 
59
58
  status 404
@@ -67,15 +66,15 @@ module Jobly
67
66
  else
68
67
  job_class.run_later args
69
68
  end
70
-
69
+
71
70
  response = {
72
71
  status: 'received',
73
- job: job,
72
+ job: job,
74
73
  params: args,
75
74
  }
76
75
 
77
76
  logger.debug "[jobly server] Job received (#{job})"
78
- response.to_json + "\n"
77
+ "#{response.to_json}\n"
79
78
  end
80
79
  end
81
80
  end
data/lib/jobly/cli.rb CHANGED
@@ -1,15 +1,15 @@
1
1
  require 'mister_bin'
2
2
  require 'jobly/version'
3
- requires 'commands/base', 'commands'
3
+ requires 'commands/base'
4
+ requires 'commands'
4
5
 
5
6
  module Jobly
6
-
7
7
  # Command line interface router. This is called by bin/jobly.
8
8
  class CLI
9
9
  def self.router
10
10
  router = MisterBin::Runner.new version: Jobly::VERSION,
11
- header: "Jobly",
12
- footer: "Run !txtpur!jobly COMMAND --help!txtrst! for more information"
11
+ header: 'Jobly',
12
+ footer: 'Run !txtpur!jobly COMMAND --help!txtrst! for more information'
13
13
 
14
14
  router.route 'init', to: Commands::InitCmd
15
15
  router.route 'server', to: Commands::ServerCmd
@@ -22,5 +22,4 @@ module Jobly
22
22
  router
23
23
  end
24
24
  end
25
-
26
25
  end
@@ -8,4 +8,4 @@ module Jobly
8
8
  include Colsole
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -3,16 +3,17 @@ require 'pathname'
3
3
  module Jobly
4
4
  module Commands
5
5
  class ConfigCmd < Base
6
- summary "Show configuration options"
7
- usage "jobly config"
8
- usage "jobly config (-h|--help)"
6
+ summary 'Show configuration options'
7
+ usage 'jobly config'
8
+ usage 'jobly config (-h|--help)'
9
9
 
10
10
  def run
11
- line "custom config file", short_config_path, !Jobly.custom_config?
11
+ line 'custom config file', short_config_path, attention: !Jobly.custom_config?
12
12
  Jobly.options.each do |key, value|
13
13
  next unless value
14
+
14
15
  if key.to_s.end_with? '_path'
15
- line key, value, !Dir.exist?(value)
16
+ line key, value, attention: !Dir.exist?(value)
16
17
  else
17
18
  line key, value
18
19
  end
@@ -25,11 +26,10 @@ module Jobly
25
26
  Jobly.config_file.sub "#{Dir.pwd}/", ''
26
27
  end
27
28
 
28
- def line(key, value, attention=false)
29
+ def line(key, value, attention: false)
29
30
  color = attention ? '!txtred!' : '!txtgrn!'
30
31
  say "#{key.to_s.rjust 20} #{color}#{value.to_s.strip}"
31
32
  end
32
-
33
33
  end
34
34
  end
35
35
  end
@@ -3,25 +3,27 @@ require 'tty-markdown'
3
3
  module Jobly
4
4
  module Commands
5
5
  class InfoCmd < Base
6
- summary "Show workspace info"
7
- usage "jobly info"
8
- usage "jobly info (-h|--help)"
6
+ summary 'Show workspace info'
7
+ usage 'jobly info'
8
+ usage 'jobly info (-h|--help)'
9
9
 
10
10
  def run
11
11
  raise InfoFileNotFound, info_file unless File.exist? info_file
12
+
12
13
  puts TTY::Markdown.parse(info, theme: {
13
- header: [:green, :bold],
14
- em: [:magenta, :bold],
15
- hr: :yellow,
16
- link: [:blue, :underline],
17
- list: :cyan,
18
- strong: [:cyan, :bold],
19
- table: :yellow,
20
- quote: :magenta
14
+ header: %i[green bold],
15
+ em: %i[magenta bold],
16
+ hr: :yellow,
17
+ link: %i[blue underline],
18
+ list: :cyan,
19
+ strong: %i[cyan bold],
20
+ table: :yellow,
21
+ quote: :magenta,
21
22
  })
22
23
  end
23
24
 
24
25
  private
26
+
25
27
  def info
26
28
  @info ||= File.read info_file
27
29
  end
@@ -29,7 +31,6 @@ module Jobly
29
31
  def info_file
30
32
  @info_file ||= File.expand_path 'info.md', Jobly.config_path
31
33
  end
32
-
33
34
  end
34
35
  end
35
36
  end
@@ -3,13 +3,13 @@ require 'fileutils'
3
3
  module Jobly
4
4
  module Commands
5
5
  class InitCmd < Base
6
- summary "Create an initial jobs workspace"
7
- usage "jobly init NAME [--minimal]"
8
- usage "jobly init (-h|--help)"
9
- param "NAME", "The name of the folder to create"
10
- option "-m --minimal", "Create a minimal workspace"
11
- example "jobly init test"
12
- example "jobly init myjobs --minimal"
6
+ summary 'Create an initial jobs workspace'
7
+ usage 'jobly init NAME [--minimal]'
8
+ usage 'jobly init (-h|--help)'
9
+ param 'NAME', 'The name of the folder to create'
10
+ option '-m --minimal', 'Create a minimal workspace'
11
+ example 'jobly init test'
12
+ example 'jobly init myjobs --minimal'
13
13
 
14
14
  def run
15
15
  raise ArgumentError, "#{target_dir} already exists" if File.exist? target_dir
@@ -4,15 +4,15 @@ module Jobly
4
4
  using ArgumentConverters
5
5
  using ConvertToTyped
6
6
 
7
- summary "Run a job locally"
8
- usage "jobly run [--later] JOB [PARAMS...]"
9
- usage "jobly run (-h|--help)"
10
- option "-l --later", "Schedule the job to be executed later by a worker instead of running it immediately"
11
- param "JOB", "Job name"
12
- param "PARAMS", "Parameters to pass to the job as key:value"
13
- example "jobly run Greet name:Bob"
14
- example "jobly run --later Greet name:Bob"
15
- example "jobly run Deploy env:stage branch:master"
7
+ summary 'Run a job locally'
8
+ usage 'jobly run [--later] JOB [PARAMS...]'
9
+ usage 'jobly run (-h|--help)'
10
+ option '-l --later', 'Schedule the job to be executed later by a worker instead of running it immediately'
11
+ param 'JOB', 'Job name'
12
+ param 'PARAMS', 'Parameters to pass to the job as key:value'
13
+ example 'jobly run Greet name:Bob'
14
+ example 'jobly run --later Greet name:Bob'
15
+ example 'jobly run Deploy env:stage branch:master'
16
16
 
17
17
  def run
18
18
  job = args['JOB']
@@ -26,13 +26,12 @@ module Jobly
26
26
  else
27
27
  job_class.run_later params
28
28
  end
29
-
29
+
30
30
  else
31
31
  say "Running !txtgrn!#{job_class}"
32
32
  job_class.run params
33
33
  end
34
34
  end
35
-
36
35
  end
37
36
  end
38
37
  end
@@ -5,13 +5,13 @@ module Jobly
5
5
  class SendCmd < Base
6
6
  using ArgumentConverters
7
7
 
8
- summary "Send a job to the API"
9
- usage "jobly send JOB [PARAMS...]"
10
- usage "jobly send (-h|--help)"
11
- param "JOB", "Job name"
12
- param "PARAMS", "Parameters to pass to the job as key:value"
13
- example "jobly send Greet name:Bob"
14
- example "jobly send Deploy env:stage branch:master"
8
+ summary 'Send a job to the API'
9
+ usage 'jobly send JOB [PARAMS...]'
10
+ usage 'jobly send (-h|--help)'
11
+ param 'JOB', 'Job name'
12
+ param 'PARAMS', 'Parameters to pass to the job as key:value'
13
+ example 'jobly send Greet name:Bob'
14
+ example 'jobly send Deploy env:stage branch:master'
15
15
 
16
16
  def run
17
17
  job = args['JOB']
@@ -43,7 +43,6 @@ module Jobly
43
43
  HTTP
44
44
  end
45
45
  end
46
-
47
46
  end
48
47
  end
49
48
  end
@@ -1,14 +1,14 @@
1
1
  module Jobly
2
2
  module Commands
3
3
  class ServerCmd < Base
4
- summary "Start the server"
5
- usage "jobly server [--port NUMBER]"
6
- usage "jobly server (-h|--help)"
7
- option "-p --port NUMBER", "Set the port number [default: 3000]"
4
+ summary 'Start the server'
5
+ usage 'jobly server [--port NUMBER]'
6
+ usage 'jobly server (-h|--help)'
7
+ option '-p --port NUMBER', 'Set the port number [default: 3000]'
8
8
 
9
9
  def run
10
10
  port = args['--port']
11
- say "Starting server"
11
+ say 'Starting server'
12
12
  exec "rackup --env #{Jobly.environment} --port #{port} --host 0.0.0.0 #{rackup_file}"
13
13
  end
14
14
 
@@ -1,19 +1,20 @@
1
1
  module Jobly
2
2
  module Commands
3
3
  class WorkerCmd < Base
4
- summary "Start a job worker"
5
- usage "jobly worker [-c COUNT -C PATH (-q NAME)...]"
6
- usage "jobly worker (-h|--help)"
7
- option "-c --concurrency COUNT", "Number of parallel jobs [default: 4]"
8
- option "-C --config PATH", "Specify a path to a YAML config file. The provided path should be relative to the global config_path directory and without the yml extension"
9
- option "-q --queue NAME[,WEIGHT]", "Specify one or more queues that this worker should handle"
4
+ summary 'Start a job worker'
5
+ usage 'jobly worker [-c COUNT -C PATH (-q NAME)...]'
6
+ usage 'jobly worker (-h|--help)'
7
+ option '-c --concurrency COUNT', 'Number of parallel jobs [default: 4]'
8
+ option '-C --config PATH',
9
+ 'Specify a path to a YAML config file. The provided path should be relative to the global config_path directory and without the yml extension'
10
+ option '-q --queue NAME[,WEIGHT]', 'Specify one or more queues that this worker should handle'
10
11
 
11
- example "jobly worker --concurrency 10"
12
- example "jobly worker -q critical -q default -q low"
13
- example "jobly worker --config primary"
12
+ example 'jobly worker --concurrency 10'
13
+ example 'jobly worker -q critical -q default -q low'
14
+ example 'jobly worker --config primary'
14
15
 
15
16
  def run
16
- say "Starting sidekiq"
17
+ say 'Starting sidekiq'
17
18
  exec "sidekiq #{options_from_args}"
18
19
  end
19
20
 
@@ -28,9 +29,10 @@ module Jobly
28
29
  if args['--config']
29
30
  config_file = "#{Jobly.config_path}/#{args['--config']}.yml"
30
31
  raise ArgumentError, "Config not found: #{config_file}" unless File.exist? config_file
32
+
31
33
  result << "--config \"#{config_file}\""
32
34
  end
33
-
35
+
34
36
  args['--queue'].each { |q| result << "--queue #{q}" }
35
37
 
36
38
  result.join ' '
@@ -3,4 +3,4 @@ module Jobly
3
3
  class JobNotFound < Error; end
4
4
  class InfoFileNotFound < Error; end
5
5
  class HTTPError < Error; end
6
- end
6
+ end
@@ -2,20 +2,20 @@ class Integer
2
2
  def seconds
3
3
  self
4
4
  end
5
- alias_method :second, :seconds
5
+ alias second seconds
6
6
 
7
7
  def minutes
8
8
  60 * seconds
9
9
  end
10
- alias_method :minute, :minutes
10
+ alias minute minutes
11
11
 
12
12
  def hours
13
13
  60 * minutes
14
14
  end
15
- alias_method :hour, :hours
15
+ alias hour hours
16
16
 
17
17
  def days
18
18
  24 * hours
19
19
  end
20
- alias_method :day, :days
21
- end
20
+ alias day days
21
+ end
@@ -15,7 +15,7 @@ module Jobly
15
15
  Log.new Jobly.log, self.class.name.to_slug
16
16
  end
17
17
 
18
- logger.level = Jobly.log_level if logger and logger.respond_to? :level
18
+ logger.level = Jobly.log_level if logger && logger.respond_to?(:level)
19
19
  logger
20
20
  end
21
21
  end
@@ -11,7 +11,7 @@ module Jobly
11
11
 
12
12
  files = [
13
13
  "#{Jobly.full_config_path}/settings",
14
- "#{Jobly.full_config_path}/settings.#{Jobly.environment}"
14
+ "#{Jobly.full_config_path}/settings.#{Jobly.environment}",
15
15
  ]
16
16
 
17
17
  files.each do |file|
@@ -7,9 +7,9 @@ module Jobly
7
7
  end
8
8
 
9
9
  def shell!
10
- TTY::Command.new output: logger,
10
+ TTY::Command.new output: logger,
11
11
  color: false,
12
- dry_run: !!Jobly.shell_dry_run
12
+ dry_run: Jobly.shell_dry_run
13
13
  end
14
14
  end
15
15
  end
@@ -29,13 +29,13 @@ module Jobly
29
29
  end
30
30
 
31
31
  def slack!
32
- raise ArgumentError, "Slack webhook is not set" unless Jobly.slack_webhook
32
+ raise ArgumentError, 'Slack webhook is not set' unless Jobly.slack_webhook
33
+
33
34
  opts = {
34
- channel: self.class.slack_channel,
35
- username: self.class.slack_user
35
+ channel: self.class.slack_channel,
36
+ username: self.class.slack_user,
36
37
  }
37
38
  ::Slack::Notifier.new Jobly.slack_webhook, opts
38
39
  end
39
-
40
40
  end
41
41
  end
data/lib/jobly/job.rb CHANGED
@@ -31,7 +31,7 @@ module Jobly
31
31
 
32
32
  # This is the method sidekiq will call. We capture this call and convert
33
33
  # the hash argument which was converted to array on sidekiq's side, back
34
- # to a hash so we can forward to the job's `execute` method, which may
34
+ # to a hash so we can forward to the job's `execute` method, which may
35
35
  # implement keyword args.
36
36
  # If the job was marked as isolated, we will run it in its own temporary
37
37
  # directory.
@@ -63,20 +63,17 @@ module Jobly
63
63
  run_actions :after
64
64
  return false
65
65
  end
66
- return true
66
+ true
67
67
  end
68
68
 
69
69
  def run_to_completion
70
70
  params.empty? ? execute : execute(**params.to_kwargs)
71
71
  run_actions :success
72
-
73
72
  rescue
74
73
  run_actions :failure
75
74
  raise
76
-
77
75
  ensure
78
76
  run_actions :after
79
-
80
77
  end
81
78
  end
82
79
  end
@@ -61,7 +61,6 @@ module Jobly
61
61
  end
62
62
  end
63
63
  end
64
-
65
64
  end
66
65
  end
67
66
  end
@@ -15,9 +15,9 @@ module Jobly
15
15
  end
16
16
  end
17
17
 
18
- def in_isolation
18
+ def in_isolation(&block)
19
19
  Dir.mktmpdir 'jobly-' do |dir|
20
- Dir.chdir(dir) { yield }
20
+ Dir.chdir(dir, &block)
21
21
  end
22
22
  end
23
23
 
@@ -1,11 +1,10 @@
1
1
  module Jobly
2
2
  module JobExtensions
3
3
  module OptionAccessors
4
-
5
4
  def self.included(base)
6
5
  base.extend ClassMethods
7
6
  end
8
-
7
+
9
8
  module ClassMethods
10
9
  def options
11
10
  sidekiq_options
@@ -28,7 +27,6 @@ module Jobly
28
27
  # sidekiq_options_hash # is this better?
29
28
  self.class.options
30
29
  end
31
-
32
30
  end
33
31
  end
34
32
  end
@@ -48,7 +48,7 @@ module Jobly
48
48
 
49
49
  def solo_lock(expire = 1.hour)
50
50
  Sidekiq.redis do |redis|
51
- redis.setex(solo_full_key, expire, "1")
51
+ redis.setex(solo_full_key, expire, '1')
52
52
  end
53
53
  end
54
54
 
@@ -57,7 +57,6 @@ module Jobly
57
57
  redis.del solo_full_key
58
58
  end
59
59
  end
60
-
61
60
  end
62
61
  end
63
62
  end
data/lib/jobly/jobs.rb CHANGED
@@ -27,4 +27,3 @@ module Jobly
27
27
  end
28
28
  end
29
29
  end
30
-
data/lib/jobly/log.rb CHANGED
@@ -3,30 +3,29 @@ require 'uri'
3
3
 
4
4
  module Jobly
5
5
  module Log
6
- def self.new(target = nil, tag = nil)
7
- if !target or target.to_sym == :stdout or target == STDOUT
8
- return Logger.new STDOUT
6
+ class << self
7
+ def new(target = nil, tag = nil)
8
+ if !target || (target.to_sym == :stdout) || (target == $stdout)
9
+ return Logger.new $stdout
10
+ end
11
+
12
+ target = target.to_s
13
+ target %= tag if tag && target.include?('%s')
14
+
15
+ if target.start_with? 'syslog://'
16
+ remote_syslog_logger target
17
+ else
18
+ Logger.new File.expand_path(target, Jobly.root)
19
+ end
9
20
  end
10
21
 
11
- target = target.to_s
12
- target %= tag if tag and target.include? "%s"
22
+ private
13
23
 
14
- if target.start_with? 'syslog://'
15
- remote_syslog_logger target
16
- else
17
- Logger.new File.expand_path(target, Jobly.root)
24
+ def remote_syslog_logger(target)
25
+ uri = URI target
26
+ RemoteSyslogLogger.new (uri.host || 'localhost'), (uri.port || 514),
27
+ local_hostname: uri.user, program: uri.password
18
28
  end
19
29
  end
20
-
21
- private
22
-
23
- def self.remote_syslog_logger(target)
24
- uri = URI target
25
- RemoteSyslogLogger.new (uri.host || 'localhost'), (uri.port || 514),
26
- local_hostname: uri.user, program: uri.password
27
- end
28
30
  end
29
31
  end
30
-
31
-
32
-
@@ -1,5 +1,7 @@
1
1
  module Jobly
2
2
  class << self
3
+ attr_reader :logger
4
+
3
5
  def configure
4
6
  yield self
5
7
  end
@@ -10,30 +12,30 @@ module Jobly
10
12
 
11
13
  def default_options
12
14
  {
13
- root: Dir.pwd,
14
- environment: ENV['JOBLY_ENVIRONMENT'] || 'development',
15
- api_url: ENV['JOBLY_API_URL'] || 'http://localhost:3000/do',
16
- app_path: ENV['JOBLY_APP_PATH'] || 'app',
17
- jobs_path: ENV['JOBLY_JOBS_PATH'] || "jobs",
18
- config_path: ENV['JOBLY_CONFIG_PATH'] || "config",
19
- redis_url: ENV['JOBLY_REDIS_URL'] || "redis://localhost:6379/0",
15
+ root: Dir.pwd,
16
+ environment: ENV['JOBLY_ENVIRONMENT'] || 'development',
17
+ api_url: ENV['JOBLY_API_URL'] || 'http://localhost:3000/do',
18
+ app_path: ENV['JOBLY_APP_PATH'] || 'app',
19
+ jobs_path: ENV['JOBLY_JOBS_PATH'] || 'jobs',
20
+ config_path: ENV['JOBLY_CONFIG_PATH'] || 'config',
21
+ redis_url: ENV['JOBLY_REDIS_URL'] || 'redis://localhost:6379/0',
20
22
  status_expiration: ENV['JOBLY_STATUS_EXPIRATION']&.to_i || 30,
21
- jobs_namespace: ENV['JOBLY_JOBS_NAMESPACE'],
22
- slack_webhook: ENV['JOBLY_SLACK_WEBHOOK'],
23
- slack_channel: ENV['JOBLY_SLACK_CHANNEL'] || "#general",
24
- slack_user: ENV['JOBLY_SLACK_USER'] || "Jobly",
25
- log: ENV['JOBLY_LOG'],
26
- log_level: ENV['JOBLY_LOG_LEVEL'] || 'info',
27
- auth: ENV['JOBLY_AUTH'],
28
- secret: ENV['JOBLY_SECRET'] || 'change-this-cookie-secret',
29
- shell_dry_run: ENV['JOBLY_SHELL_DRY_RUN'],
30
- mounts: nil,
23
+ jobs_namespace: ENV['JOBLY_JOBS_NAMESPACE'],
24
+ slack_webhook: ENV['JOBLY_SLACK_WEBHOOK'],
25
+ slack_channel: ENV['JOBLY_SLACK_CHANNEL'] || '#general',
26
+ slack_user: ENV['JOBLY_SLACK_USER'] || 'Jobly',
27
+ log: ENV['JOBLY_LOG'],
28
+ log_level: ENV['JOBLY_LOG_LEVEL'] || 'info',
29
+ auth: ENV['JOBLY_AUTH'],
30
+ secret: ENV['JOBLY_SECRET'] || 'change-this-cookie-secret',
31
+ shell_dry_run: ENV['JOBLY_SHELL_DRY_RUN'],
32
+ mounts: nil,
31
33
  }
32
34
  end
33
35
 
34
- def method_missing(method, args=nil, &_block)
36
+ def method_missing(method, args = nil, &_block)
35
37
  key = method.to_s
36
- assign = key[-1] == "="
38
+ assign = key[-1] == '='
37
39
  key = key.chomp('=') if assign
38
40
  key = key.to_sym
39
41
 
@@ -44,7 +46,7 @@ module Jobly
44
46
  end
45
47
  end
46
48
 
47
- def respond_to_missing?(method, include_private=false)
49
+ def respond_to_missing?(method, include_private = false)
48
50
  key = method.to_s.chomp('=').to_sym
49
51
  options.has_key?(key) ? true : super
50
52
  end
@@ -53,22 +55,15 @@ module Jobly
53
55
  @options ||= default_options.dup
54
56
  end
55
57
 
56
- def logger
57
- @logger
58
- end
59
-
60
58
  def log=(target)
61
59
  options[:log] = target
62
60
  @logger = if target.is_a? Logger
63
61
  target
64
62
  elsif target
65
63
  Log.new target, :jobly
66
- else
67
- nil
68
64
  end
69
65
 
70
- @logger.level = log_level if @logger and @logger.respond_to? :level
71
- @logger
66
+ @logger.level = log_level if @logger && @logger.respond_to?(:level)
72
67
  end
73
68
 
74
69
  def full_app_path
@@ -2,8 +2,8 @@ module Jobly
2
2
  module ArgumentConverters
3
3
  refine Array do
4
4
  def to_params
5
- map { |pair| pair.split ':', 2 }.to_h.transform_keys(&:to_sym)
5
+ to_h { |pair| pair.split ':', 2 }.transform_keys(&:to_sym)
6
6
  end
7
7
  end
8
8
  end
9
- end
9
+ end
@@ -18,10 +18,11 @@ module Jobly
18
18
 
19
19
  refine String do
20
20
  def convert_to_typed
21
- return true if ['true', 'yes'].include? self
22
- return false if ['false', 'no'].include? self
21
+ return true if %w[true yes].include? self
22
+ return false if %w[false no].include? self
23
+
23
24
  Integer self rescue self
24
25
  end
25
26
  end
26
27
  end
27
- end
28
+ end
@@ -2,14 +2,14 @@ module Jobly
2
2
  module KeywordArgs
3
3
  refine Hash do
4
4
  def to_kwargs
5
- to_h.transform_keys &:to_sym
5
+ to_h.transform_keys(&:to_sym)
6
6
  end
7
7
  end
8
8
 
9
9
  refine Array do
10
10
  def to_kwargs
11
- to_h.transform_keys &:to_sym
11
+ to_h.transform_keys(&:to_sym)
12
12
  end
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -6,4 +6,4 @@ module Jobly
6
6
  end
7
7
  end
8
8
  end
9
- end
9
+ end
data/lib/jobly/server.rb CHANGED
@@ -10,8 +10,8 @@ module Jobly
10
10
 
11
11
  def self.app
12
12
  mounts = {
13
- '/' => Sidekiq::Web,
14
- '/do' => Jobly::API
13
+ '/' => Sidekiq::Web,
14
+ '/do' => Jobly::API,
15
15
  }
16
16
  mounts.merge! Jobly.mounts if Jobly.mounts
17
17
 
@@ -21,7 +21,7 @@ module Jobly
21
21
 
22
22
  if Jobly.auth
23
23
  user, pass = Jobly.auth.split ':'
24
- use Rack::Auth::Basic, "Jobly" do |username, password|
24
+ use Rack::Auth::Basic, 'Jobly' do |username, password|
25
25
  username == user && password == pass
26
26
  end
27
27
  end
@@ -29,9 +29,5 @@ module Jobly
29
29
  run Rack::URLMap.new mounts
30
30
  end
31
31
  end
32
- end
32
+ end
33
33
  end
34
-
35
-
36
-
37
-
data/lib/jobly/sidekiq.rb CHANGED
@@ -8,19 +8,19 @@ module Jobly
8
8
  def self.configure
9
9
  Sidekiq.configure_client do |config|
10
10
  config.redis = { url: Jobly.redis_url }
11
+ config.logger = Jobly.logger if Jobly.log
11
12
  Sidekiq::Status.configure_client_middleware config, expiration: 60 * 60
12
13
  end
13
14
 
14
15
  Sidekiq.configure_server do |config|
15
16
  # :nocov:
16
17
  config.redis = { url: Jobly.redis_url }
18
+ config.logger = Jobly.logger if Jobly.log
17
19
 
18
20
  Sidekiq::Status.configure_server_middleware config, expiration: Jobly.status_expiration * 60
19
21
  Sidekiq::Status.configure_client_middleware config, expiration: Jobly.status_expiration * 60
20
22
  # :nocov:
21
23
  end
22
-
23
- Sidekiq.logger = Jobly.logger if Jobly.log
24
24
  end
25
25
  end
26
26
  end
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- gem "foreman"
4
- gem "jobly"
3
+ gem 'foreman'
4
+ gem 'jobly'
@@ -1,3 +1,3 @@
1
1
  class Job < Jobly::Job
2
2
  # Put your common Job methods here
3
- end
3
+ end
@@ -10,4 +10,4 @@ class OtherClass
10
10
  # include Jobly::Slack
11
11
  # include Jobly::Shell
12
12
  # include Jobly::Settings
13
- end
13
+ end
@@ -17,4 +17,4 @@ Jobly.configure do |config|
17
17
  # config.auth = 'admin:secret'
18
18
  # config.secret = 'there is no spoon'
19
19
  # config.shell_dry_run = false
20
- end
20
+ end
@@ -2,15 +2,15 @@
2
2
  class Hello < Job
3
3
  def execute(name: 'Bob')
4
4
  total 2
5
-
6
- at 0, "Initializing"
5
+
6
+ at 0, 'Initializing'
7
7
  sleep rand 3.0..8.0
8
8
 
9
- at 1, "Preparing to say Hi"
9
+ at 1, 'Preparing to say Hi'
10
10
  sleep rand 3.0..8.0
11
11
 
12
12
  logger.info "Hi #{name}!"
13
13
 
14
- at 2, "Done"
14
+ at 2, 'Done'
15
15
  end
16
16
  end
@@ -1,3 +1,3 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- gem "jobly"
3
+ gem 'jobly'
data/lib/jobly/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jobly
2
- VERSION = "0.5.10"
3
- end
2
+ VERSION = '0.5.11'
3
+ end
data/lib/jobly.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'requires'
2
2
  require 'byebug' if ENV['BYEBUG']
3
3
 
4
- requires 'jobly/polyfills'
5
4
  requires 'jobly/extensions'
6
5
  requires 'jobly/refinements'
7
6
  requires 'jobly/job_extensions'
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jobly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.10
4
+ version: 0.5.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-23 00:00:00.000000000 Z
11
+ date: 2023-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colsole
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.7.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.7.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: http
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -25,13 +39,24 @@ dependencies:
25
39
  - !ruby/object:Gem::Version
26
40
  version: '5.0'
27
41
  - !ruby/object:Gem::Dependency
28
- name: pretty_trace
42
+ name: mister_bin
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0.2'
34
- - - ">="
47
+ version: 0.7.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.7.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: pretty_trace
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
35
60
  - !ruby/object:Gem::Version
36
61
  version: 0.2.4
37
62
  type: :runtime
@@ -39,9 +64,6 @@ dependencies:
39
64
  version_requirements: !ruby/object:Gem::Requirement
40
65
  requirements:
41
66
  - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: '0.2'
44
- - - ">="
45
67
  - !ruby/object:Gem::Version
46
68
  version: 0.2.4
47
69
  - !ruby/object:Gem::Dependency
@@ -84,28 +106,28 @@ dependencies:
84
106
  requirements:
85
107
  - - "~>"
86
108
  - !ruby/object:Gem::Version
87
- version: '0.1'
109
+ version: '1.0'
88
110
  type: :runtime
89
111
  prerelease: false
90
112
  version_requirements: !ruby/object:Gem::Requirement
91
113
  requirements:
92
114
  - - "~>"
93
115
  - !ruby/object:Gem::Version
94
- version: '0.1'
116
+ version: '1.0'
95
117
  - !ruby/object:Gem::Dependency
96
118
  name: sidekiq
97
119
  requirement: !ruby/object:Gem::Requirement
98
120
  requirements:
99
121
  - - "~>"
100
122
  - !ruby/object:Gem::Version
101
- version: '6.0'
123
+ version: '6.5'
102
124
  type: :runtime
103
125
  prerelease: false
104
126
  version_requirements: !ruby/object:Gem::Requirement
105
127
  requirements:
106
128
  - - "~>"
107
129
  - !ruby/object:Gem::Version
108
- version: '6.0'
130
+ version: '6.5'
109
131
  - !ruby/object:Gem::Dependency
110
132
  name: sidekiq-status
111
133
  requirement: !ruby/object:Gem::Requirement
@@ -168,14 +190,14 @@ dependencies:
168
190
  requirements:
169
191
  - - "~>"
170
192
  - !ruby/object:Gem::Version
171
- version: '0.4'
193
+ version: 0.5.0
172
194
  type: :runtime
173
195
  prerelease: false
174
196
  version_requirements: !ruby/object:Gem::Requirement
175
197
  requirements:
176
198
  - - "~>"
177
199
  - !ruby/object:Gem::Version
178
- version: '0.4'
200
+ version: 0.5.0
179
201
  - !ruby/object:Gem::Dependency
180
202
  name: tty-command
181
203
  requirement: !ruby/object:Gem::Requirement
@@ -204,34 +226,6 @@ dependencies:
204
226
  - - "~>"
205
227
  - !ruby/object:Gem::Version
206
228
  version: '0.6'
207
- - !ruby/object:Gem::Dependency
208
- name: colsole
209
- requirement: !ruby/object:Gem::Requirement
210
- requirements:
211
- - - "~>"
212
- - !ruby/object:Gem::Version
213
- version: '0.6'
214
- type: :runtime
215
- prerelease: false
216
- version_requirements: !ruby/object:Gem::Requirement
217
- requirements:
218
- - - "~>"
219
- - !ruby/object:Gem::Version
220
- version: '0.6'
221
- - !ruby/object:Gem::Dependency
222
- name: mister_bin
223
- requirement: !ruby/object:Gem::Requirement
224
- requirements:
225
- - - "~>"
226
- - !ruby/object:Gem::Version
227
- version: '0.7'
228
- type: :runtime
229
- prerelease: false
230
- version_requirements: !ruby/object:Gem::Requirement
231
- requirements:
232
- - - "~>"
233
- - !ruby/object:Gem::Version
234
- version: '0.7'
235
229
  description: Execute background jobs and build tasks on this sidekiq-based job server
236
230
  email: db@dannyben.com
237
231
  executables:
@@ -270,7 +264,6 @@ files:
270
264
  - lib/jobly/jobs.rb
271
265
  - lib/jobly/log.rb
272
266
  - lib/jobly/module_functions.rb
273
- - lib/jobly/polyfills/hash.rb
274
267
  - lib/jobly/refinements/argument_converters.rb
275
268
  - lib/jobly/refinements/convert_to_typed.rb
276
269
  - lib/jobly/refinements/keyword_args.rb
@@ -298,6 +291,7 @@ metadata:
298
291
  changelog_uri: https://github.com/DannyBen/jobly/blob/master/CHANGELOG.md
299
292
  documentation_uri: https://jobly.dannyb.co/
300
293
  source_code_uri: https://github.com/dannyben/jobly
294
+ rubygems_mfa_required: 'true'
301
295
  post_install_message:
302
296
  rdoc_options: []
303
297
  require_paths:
@@ -306,14 +300,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
306
300
  requirements:
307
301
  - - ">="
308
302
  - !ruby/object:Gem::Version
309
- version: 2.6.0
303
+ version: '2.7'
310
304
  required_rubygems_version: !ruby/object:Gem::Requirement
311
305
  requirements:
312
306
  - - ">="
313
307
  - !ruby/object:Gem::Version
314
308
  version: '0'
315
309
  requirements: []
316
- rubygems_version: 3.3.14
310
+ rubygems_version: 3.4.3
317
311
  signing_key:
318
312
  specification_version: 4
319
313
  summary: Compact job server with API, CLI, Web UI and a Sidekiq heart
@@ -1,21 +0,0 @@
1
- # :nocov:
2
-
3
- # Required for Ruby < 2.4
4
- if !{}.respond_to? :transform_values
5
- class Hash
6
- def transform_values
7
- self.each { |k, v| self[k] = yield v }
8
- end
9
- end
10
- end
11
-
12
- # Required for Ruby < 2.5
13
- if !{}.respond_to? :transform_keys
14
- class Hash
15
- def transform_keys
16
- self.map { |k, v| [(yield k), v] }.to_h
17
- end
18
- end
19
- end
20
-
21
- # :nocov: