Module: Jobly

Defined in:
lib/jobly/api.rb,
lib/jobly/cli.rb,
lib/jobly/job.rb,
lib/jobly/log.rb,
lib/jobly/jobs.rb,
lib/jobly/server.rb,
lib/jobly/helpers.rb,
lib/jobly/sidekiq.rb,
lib/jobly/version.rb,
lib/jobly/exceptions.rb,
lib/jobly/commands/run.rb,
lib/jobly/commands/base.rb,
lib/jobly/commands/info.rb,
lib/jobly/commands/init.rb,
lib/jobly/commands/send.rb,
lib/jobly/helpers/shell.rb,
lib/jobly/helpers/slack.rb,
lib/jobly/commands/config.rb,
lib/jobly/commands/server.rb,
lib/jobly/commands/worker.rb,
lib/jobly/helpers/logging.rb,
lib/jobly/helpers/settings.rb,
lib/jobly/module_functions.rb,
lib/jobly/job_extensions/solo.rb,
lib/jobly/refinements/to_slug.rb,
lib/jobly/job_extensions/actions.rb,
lib/jobly/job_extensions/isolation.rb,
lib/jobly/refinements/keyword_args.rb,
lib/jobly/refinements/convert_to_typed.rb,
lib/jobly/job_extensions/option_accessors.rb,
lib/jobly/refinements/argument_converters.rb

Defined Under Namespace

Modules: ArgumentConverters, Commands, ConvertToTyped, Helpers, JobExtensions, Jobs, KeywordArgs, Log, Logging, Settings, Shell, SidekiqBoot, Slack, ToSlug Classes: API, CLI, Error, HTTPError, InfoFileNotFound, Job, JobNotFound, Server

Constant Summary collapse

VERSION =
'1.0.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject (readonly)

Returns the value of attribute logger.



3
4
5
# File 'lib/jobly/module_functions.rb', line 3

def logger
  @logger
end

Class Method Details

.config_fileObject



81
82
83
# File 'lib/jobly/module_functions.rb', line 81

def config_file
  File.expand_path 'jobly.rb', full_config_path
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Jobly)

    the object that the method was called on



5
6
7
# File 'lib/jobly/module_functions.rb', line 5

def configure
  yield self
end

.custom_config?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/jobly/module_functions.rb', line 85

def custom_config?
  File.exist? config_file
end

.default_optionsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jobly/module_functions.rb', line 13

def default_options
  {
    root:              Dir.pwd,
    environment:       ENV['JOBLY_ENVIRONMENT'] || 'development',
    api_url:           ENV['JOBLY_API_URL'] || 'http://localhost:3000/do',
    app_path:          ENV['JOBLY_APP_PATH'] || 'app',
    jobs_path:         ENV['JOBLY_JOBS_PATH'] || 'jobs',
    config_path:       ENV['JOBLY_CONFIG_PATH'] || 'config',
    redis_url:         ENV['JOBLY_REDIS_URL'] || 'redis://localhost:6379/0',
    status_expiration: ENV['JOBLY_STATUS_EXPIRATION']&.to_i || 30,
    jobs_namespace:    ENV['JOBLY_JOBS_NAMESPACE'],
    slack_webhook:     ENV['JOBLY_SLACK_WEBHOOK'],
    slack_channel:     ENV['JOBLY_SLACK_CHANNEL'] || '#general',
    slack_user:        ENV['JOBLY_SLACK_USER'] || 'Jobly',
    log:               ENV['JOBLY_LOG'],
    log_level:         ENV['JOBLY_LOG_LEVEL'] || 'info',
    auth:              ENV['JOBLY_AUTH'],
    secret:            ENV['JOBLY_SECRET'] || 'change-this-cookie-secret',
    shell_dry_run:     ENV['JOBLY_SHELL_DRY_RUN'],
    mounts:            nil,
  }
end

.full_app_pathObject



69
70
71
# File 'lib/jobly/module_functions.rb', line 69

def full_app_path
  File.expand_path app_path, root
end

.full_config_pathObject



77
78
79
# File 'lib/jobly/module_functions.rb', line 77

def full_config_path
  File.expand_path config_path, root
end

.full_jobs_pathObject



73
74
75
# File 'lib/jobly/module_functions.rb', line 73

def full_jobs_path
  File.expand_path jobs_path, root
end

.load_custom_configObject



9
10
11
# File 'lib/jobly/module_functions.rb', line 9

def load_custom_config
  require config_file if File.exist? config_file
end

.log=(target) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/jobly/module_functions.rb', line 58

def log=(target)
  options[:log] = target
  @logger = if target.is_a? Logger
    target
  elsif target
    Log.new target, :jobly
  end

  @logger.level = log_level if @logger && @logger.respond_to?(:level)
end

.method_missing(method, args = nil, &_block) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/jobly/module_functions.rb', line 36

def method_missing(method, args = nil, &_block)
  key = method.to_s
  assign = key[-1] == '='
  key = key.chomp('=') if assign
  key = key.to_sym

  if options.has_key? key
    assign ? options[key] = args : options[key]
  else
    super
  end
end

.optionsObject



54
55
56
# File 'lib/jobly/module_functions.rb', line 54

def options
  @options ||= default_options.dup
end

.respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/jobly/module_functions.rb', line 49

def respond_to_missing?(method, include_private = false)
  key = method.to_s.chomp('=').to_sym
  options.has_key?(key) ? true : super
end