web47core 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +4 -1
- data/bin/cron_server +1 -2
- data/lib/app/jobs/cron/command.rb +5 -19
- data/lib/app/jobs/cron/job_tab.rb +14 -14
- data/lib/web47core.rb +0 -1
- data/web47core.gemspec +1 -3
- metadata +1 -2
- data/lib/app/jobs/cron/worker.rb +0 -70
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00d13c9db9f30f83dae32f68e402d1916193c73628c430694834b47c4893475e
|
4
|
+
data.tar.gz: 2d91396fa1a980ed68347d801fbf9c3149669823d44b23ffd730e7344cb4ff0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f1049f2332a61a551a403b8a20d2f6fb8e697305cb7b13dedff4ee28cfb0f3cb2bcadd000c0b9a3ee9bd5a397052930f659d67bd5567263773c01992e8b2302
|
7
|
+
data.tar.gz: cafe990fbe4618b188f62ea4da75309342abd2155b47ef1983ce1a63eb6600735ea624682d7c0757857f087d589ee23df12e49177620d080561be24fc047c320
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
web47core (0.1.
|
4
|
+
web47core (0.1.4)
|
5
5
|
activesupport (~> 5.0)
|
6
6
|
aws-sdk-autoscaling
|
7
7
|
daemons
|
@@ -113,7 +113,7 @@ GEM
|
|
113
113
|
email_regex (0.0.1)
|
114
114
|
erubi (1.9.0)
|
115
115
|
execjs (2.7.0)
|
116
|
-
factory_bot (5.1.
|
116
|
+
factory_bot (5.1.2)
|
117
117
|
activesupport (>= 4.2.0)
|
118
118
|
factory_bot_rails (5.1.1)
|
119
119
|
factory_bot (~> 5.1.0)
|
@@ -248,7 +248,7 @@ GEM
|
|
248
248
|
shoulda-context (~> 1.0, >= 1.0.1)
|
249
249
|
shoulda-matchers (~> 3.0)
|
250
250
|
shoulda-context (1.2.2)
|
251
|
-
shoulda-matchers (3.1.
|
251
|
+
shoulda-matchers (3.1.3)
|
252
252
|
activesupport (>= 4.0.0)
|
253
253
|
simplecov (0.16.1)
|
254
254
|
docile (~> 1.1)
|
data/README.md
CHANGED
@@ -139,4 +139,7 @@ Allowed values of cron_tab_entry are
|
|
139
139
|
* :monthly - run every month on the first day of the month
|
140
140
|
* '*/5 1,3 * 2 *' - Run according to unix crontab entry format. This would run every tuesday on the 1st and 3rd hour, for any minute divisable by 5, so 0, 5, 10, 15, etc..
|
141
141
|
|
142
|
-
4.
|
142
|
+
4. Before starting the server, you need to run the database command
|
143
|
+
```mongo
|
144
|
+
db.cron_tabs.updateMany({_type: 'JobCronTab'}, {$set: {_type: 'Cron::JobTab'}});
|
145
|
+
```
|
data/bin/cron_server
CHANGED
@@ -10,11 +10,11 @@ require 'optparse'
|
|
10
10
|
require 'pathname'
|
11
11
|
|
12
12
|
module Cron
|
13
|
-
class Command
|
13
|
+
class Command
|
14
14
|
|
15
15
|
DIR_PWD = Pathname.new Dir.pwd
|
16
16
|
|
17
|
-
def initialize(args)
|
17
|
+
def initialize(args)
|
18
18
|
@options = { pid_dir: "#{root}/tmp/pids", log_dir: "#{root}/log", monitor: false }
|
19
19
|
|
20
20
|
opts = OptionParser.new do |opt|
|
@@ -46,30 +46,16 @@ module Cron
|
|
46
46
|
@args = opts.parse!(args) + (@daemon_options || [])
|
47
47
|
end
|
48
48
|
|
49
|
-
def daemonize
|
49
|
+
def daemonize
|
50
50
|
dir = @options[:pid_dir]
|
51
51
|
FileUtils.mkdir_p(dir) unless File.exist?(dir)
|
52
52
|
|
53
53
|
Cron::JobTab.ensure_cron_tabs
|
54
|
-
|
55
|
-
|
56
|
-
dir: options[:pid_dir],
|
57
|
-
dir_mode: :normal,
|
58
|
-
monitor: @options[:monitor],
|
59
|
-
ARGV: @args) do
|
60
|
-
run @options
|
54
|
+
Daemons.run_proc('cron_server', dir: @options[:pid_dir], monitor: @options[:monitor], ARGV: @args) do
|
55
|
+
loop { sleep Cron::Server.find_or_create_server.execute }
|
61
56
|
end
|
62
57
|
end
|
63
58
|
|
64
|
-
def run(options = {})
|
65
|
-
Dir.chdir(root)
|
66
|
-
|
67
|
-
Cron::Worker.new(options).start
|
68
|
-
rescue StandardError => error
|
69
|
-
App47Logger.log_error 'Unable to start Cron Server', error
|
70
|
-
exit 1
|
71
|
-
end
|
72
|
-
|
73
59
|
private
|
74
60
|
|
75
61
|
def root
|
@@ -5,10 +5,7 @@
|
|
5
5
|
#
|
6
6
|
module Cron
|
7
7
|
class JobTab < Tab
|
8
|
-
unless defined? FRAMEWORK_CLASSES
|
9
|
-
FRAMEWORK_CLASSES = %w[job trim_collection command server tab job_tab worker].freeze
|
10
|
-
end
|
11
|
-
cattr_accessor :jobs
|
8
|
+
FRAMEWORK_CLASSES = %w[Job TrimCollection Command Server Tab JobTab].freeze unless defined? FRAMEWORK_CLASSES
|
12
9
|
#
|
13
10
|
# Validations
|
14
11
|
#
|
@@ -28,14 +25,7 @@ module Cron
|
|
28
25
|
end
|
29
26
|
|
30
27
|
def ensure_cron_tabs
|
31
|
-
|
32
|
-
Cron.constants.each do |job|
|
33
|
-
job_name = job.to_s.underscore
|
34
|
-
next if FRAMEWORK_CLASSES.include?(job_name) ||
|
35
|
-
job_name.end_with?('_test') ||
|
36
|
-
job_name.start_with?('base_')
|
37
|
-
|
38
|
-
jobs << job_name
|
28
|
+
job_names.each do |job_name|
|
39
29
|
klass = "cron/#{job_name}".camelize.constantize
|
40
30
|
tab = JobTab.find_or_initialize_by name: job_name
|
41
31
|
next if tab.persisted?
|
@@ -45,6 +35,16 @@ module Cron
|
|
45
35
|
purge_cron_tabs
|
46
36
|
end
|
47
37
|
|
38
|
+
def job_names
|
39
|
+
@job_names ||= Cron.constants.collect do |job|
|
40
|
+
job_name = job.to_s
|
41
|
+
next if FRAMEWORK_CLASSES.include?(job_name) ||
|
42
|
+
job_name.end_with?('Test') ||
|
43
|
+
job_name.start_with?('Base')
|
44
|
+
|
45
|
+
job_name.underscore
|
46
|
+
end.compact
|
47
|
+
end
|
48
48
|
|
49
49
|
private
|
50
50
|
|
@@ -68,7 +68,7 @@ module Cron
|
|
68
68
|
|
69
69
|
def purge_cron_tabs
|
70
70
|
JobTab.all.each do |tab|
|
71
|
-
tab.destroy unless
|
71
|
+
tab.destroy unless job_names.include?(tab.name)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
@@ -120,7 +120,7 @@ module Cron
|
|
120
120
|
# Test the name is the list of jobs discovered
|
121
121
|
#
|
122
122
|
def valid_name
|
123
|
-
errors.add(:name, 'Invalid Tab') unless
|
123
|
+
errors.add(:name, 'Invalid Tab') unless JobTab.job_names.include?(name)
|
124
124
|
end
|
125
125
|
end
|
126
126
|
end
|
data/lib/web47core.rb
CHANGED
@@ -25,7 +25,6 @@ require 'app/jobs/cron/job'
|
|
25
25
|
require 'app/jobs/cron/tab'
|
26
26
|
require 'app/jobs/cron/job_tab'
|
27
27
|
require 'app/jobs/cron/command'
|
28
|
-
require 'app/jobs/cron/worker'
|
29
28
|
require 'app/jobs/cron/server'
|
30
29
|
require 'app/jobs/cron/trim_collection'
|
31
30
|
require 'app/jobs/cron/switchboard_sync_configuration'
|
data/web47core.gemspec
CHANGED
@@ -8,7 +8,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
8
8
|
Gem::Specification.new do |spec|
|
9
9
|
spec.required_ruby_version = '~> 2.4.1'
|
10
10
|
spec.name = 'web47core'
|
11
|
-
spec.version = '0.1.
|
11
|
+
spec.version = '0.1.4'
|
12
12
|
spec.authors = ['Chris Schroeder']
|
13
13
|
spec.email = ['chris@app47.com']
|
14
14
|
spec.summary = 'App47 Web Core Library.'
|
@@ -16,8 +16,6 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.homepage = 'https://app47.com'
|
17
17
|
spec.license = 'MIT'
|
18
18
|
|
19
|
-
spec.executables << 'cron_server'
|
20
|
-
|
21
19
|
spec.files = `git ls-files -z`.split("\x0")
|
22
20
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
21
|
spec.test_files = spec.files.grep(%r{^(test)/})
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web47core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Schroeder
|
@@ -534,7 +534,6 @@ files:
|
|
534
534
|
- lib/app/jobs/cron/trim_cron_servers.rb
|
535
535
|
- lib/app/jobs/cron/trim_failed_delayed_jobs.rb
|
536
536
|
- lib/app/jobs/cron/trim_notifications.rb
|
537
|
-
- lib/app/jobs/cron/worker.rb
|
538
537
|
- lib/app/models/concerns/app47_logger.rb
|
539
538
|
- lib/app/models/concerns/cdn_url.rb
|
540
539
|
- lib/app/models/concerns/core_account.rb
|
data/lib/app/jobs/cron/worker.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'timeout'
|
2
|
-
require 'active_support/dependencies'
|
3
|
-
require 'active_support/core_ext/numeric/time'
|
4
|
-
require 'active_support/core_ext/class/attribute_accessors'
|
5
|
-
require 'active_support/hash_with_indifferent_access'
|
6
|
-
require 'active_support/core_ext/hash/indifferent_access'
|
7
|
-
require 'logger'
|
8
|
-
require 'benchmark'
|
9
|
-
|
10
|
-
module Cron
|
11
|
-
class Worker # rubocop:disable ClassLength
|
12
|
-
DEFAULT_LOG_LEVEL = 'info'.freeze
|
13
|
-
|
14
|
-
cattr_accessor :logger, :default_log_level
|
15
|
-
|
16
|
-
def self.reset
|
17
|
-
self.default_log_level ||= DEFAULT_LOG_LEVEL
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.reload_app?
|
21
|
-
defined?(ActionDispatch::Reloader) && Rails.application.config.cache_classes == false
|
22
|
-
end
|
23
|
-
|
24
|
-
def initialize(options = {})
|
25
|
-
super()
|
26
|
-
@exit = options[:exit_on_complete].presence
|
27
|
-
end
|
28
|
-
|
29
|
-
# Every worker has a unique name which by default is the pid of the process. There are some
|
30
|
-
# advantages to overriding this with something which survives worker restarts: Workers can
|
31
|
-
# safely resume working on tasks which are locked by themselves. The worker will assume that
|
32
|
-
# it crashed before.
|
33
|
-
def name
|
34
|
-
@name ||= "CronServer:#{Socket.gethostname} pid:#{Process.pid}"
|
35
|
-
end
|
36
|
-
|
37
|
-
def start # rubocop:disable CyclomaticComplexity, PerceivedComplexity
|
38
|
-
trap('TERM') { stop }
|
39
|
-
trap('INT') { stop }
|
40
|
-
|
41
|
-
say 'Starting cron jobs server'
|
42
|
-
|
43
|
-
self.class.lifecycle.run_callbacks(:execute, self) do
|
44
|
-
loop do
|
45
|
-
sleep Cron::Server.find_or_create_server.execute
|
46
|
-
break if stop?
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
say 'Exiting cron jobs server...'
|
51
|
-
end
|
52
|
-
|
53
|
-
def stop
|
54
|
-
@exit = true
|
55
|
-
end
|
56
|
-
|
57
|
-
def stop?
|
58
|
-
!!@exit
|
59
|
-
end
|
60
|
-
|
61
|
-
def say(text, level = default_log_level)
|
62
|
-
text = "[CronServer(#{name})] #{text}"
|
63
|
-
return if logger.blank?
|
64
|
-
|
65
|
-
logger.send(level, "#{Time.now.strftime('%FT%T%z')}: #{text}")
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
Cron::Worker.reset
|