web47core 0.0.10 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,71 @@
1
+ require 'test_helper'
2
+ require 'notification_test_helper'
3
+ module Cron
4
+ class TrimFailedDelayedJobsTest < ActiveSupport::TestCase
5
+ include NotificationTestHelper
6
+ context 'Execute with no jobs' do
7
+ should 'run with no issue' do
8
+ assert_nothing_raised { Cron::TrimFailedDelayedJobs.perform_now }
9
+ end
10
+ end
11
+ context 'handle failed job' do
12
+ setup do
13
+ SystemConfiguration.configuration.update slack_api_url: 'https://slack.test.com'
14
+ stub_request(:post, "https://slack.test.com/").to_return(status: 200, body: "", headers: {})
15
+ Delayed::Worker.delay_jobs = true
16
+ # Create the job that should be deleted
17
+ o = TestBGJob.create!
18
+ o.update_name
19
+ o.destroy!
20
+ Delayed::Backend::Mongoid::Job.first.set failed_at: Time.now.utc
21
+ end
22
+ teardown do
23
+ Delayed::Worker.delay_jobs = false
24
+ end
25
+ should 'remove one job' do
26
+ assert_nothing_raised { Cron::TrimFailedDelayedJobs.perform_now }
27
+ assert_empty Delayed::Backend::Mongoid::Job.all
28
+ assert_slacks_count nil, 1
29
+ assert_slacks_includes ['*Delayed Jobs Failed* due to missing document, ~removing from queue!~',
30
+ '*Object:* ```',
31
+ '*Method:* `',
32
+ '*Arguments:* ``']
33
+ end
34
+ should 'remove two jobs' do
35
+ o = TestBGJob.create!
36
+ o.update_name
37
+ o.destroy!
38
+ Delayed::Backend::Mongoid::Job.each { |d| d.set failed_at: Time.now.utc }
39
+ assert_nothing_raised { Cron::TrimFailedDelayedJobs.perform_now }
40
+ assert_empty Delayed::Backend::Mongoid::Job.all
41
+ assert_slacks_count nil, 2
42
+ end
43
+ should 'only remove one' do
44
+ o = TestBGJob.create!
45
+ o.update_name
46
+ o.destroy!
47
+ assert_nothing_raised { Cron::TrimFailedDelayedJobs.perform_now }
48
+ assert_equal 1, Delayed::Backend::Mongoid::Job.all.count
49
+ assert_slacks_count nil, 1
50
+ end
51
+ should 'only remove one failed missing doc job' do
52
+ o = TestBGJob.create!
53
+ o.update_name
54
+ assert_nothing_raised { Cron::TrimFailedDelayedJobs.perform_now }
55
+ assert_equal 1, Delayed::Backend::Mongoid::Job.all.count
56
+ assert_slacks_count nil, 1
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ class TestBGJob
63
+ include StandardModel
64
+ field :name, type: String
65
+
66
+ def update_name
67
+ set name: 'bg'
68
+ end
69
+
70
+ handle_asynchronously :update_name
71
+ end
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ class JobCronTabTest < ActiveSupport::TestCase
4
+
5
+ #
6
+ # Temp class for testing
7
+ #
8
+ class EmailModel
9
+ include Mongoid::Document
10
+ include Mongoid::Timestamps
11
+ include EmailAble
12
+ field :once, type: String
13
+ end
14
+
15
+
16
+ context 'ensure_cron_tabs' do
17
+ should 'start out with no cron tabs' do
18
+ assert_empty Cron::JobTab.all
19
+ end
20
+ should 'load everything in the cron tab' do
21
+ Cron::JobTab.ensure_cron_tabs
22
+ assert_not_empty Cron::JobTab.all
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ class Web47coreTest < ActiveSupport::TestCase
4
+ context 'models' do
5
+ should 'email able be empty by default then able to add to it' do
6
+ assert_empty Web47core.config.email_able_models
7
+ Web47core.config.email_able_models += [Account]
8
+ assert_equal 1, Web47core.config.email_able_models.count
9
+ assert_equal Account, Web47core.config.email_able_models.first
10
+ end
11
+ should 'Switchboard able be empty by default then able to add to it' do
12
+ assert_empty Web47core.config.switchboard_able_models
13
+ Web47core.config.switchboard_able_models += [Account]
14
+ assert_equal 1, Web47core.config.switchboard_able_models.count
15
+ assert_equal Account, Web47core.config.switchboard_able_models.first
16
+ end
17
+ end
18
+ end
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.0.10'
11
+ spec.version = '0.1.0'
12
12
  spec.authors = ['Chris Schroeder']
13
13
  spec.email = ['chris@app47.com']
14
14
  spec.summary = 'App47 Web Core Library.'
@@ -16,6 +16,8 @@ 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
+
19
21
  spec.files = `git ls-files -z`.split("\x0")
20
22
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
23
  spec.test_files = spec.files.grep(%r{^(test)/})
@@ -25,6 +27,7 @@ Gem::Specification.new do |spec|
25
27
  spec.add_runtime_dependency 'activesupport', '~> 5.0'
26
28
  spec.add_runtime_dependency 'aws-sdk-ec2', '> 1.140', '<= 1.160'
27
29
  spec.add_runtime_dependency 'delayed_job_mongoid', '~> 2.3'
30
+ spec.add_runtime_dependency 'daemons'
28
31
  spec.add_runtime_dependency 'email_format'
29
32
  spec.add_runtime_dependency 'haml'
30
33
  spec.add_runtime_dependency 'jwt'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web47core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Schroeder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-27 00:00:00.000000000 Z
11
+ date: 2020-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -58,6 +58,20 @@ dependencies:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '2.3'
61
+ - !ruby/object:Gem::Dependency
62
+ name: daemons
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
61
75
  - !ruby/object:Gem::Dependency
62
76
  name: email_format
63
77
  requirement: !ruby/object:Gem::Requirement
@@ -483,7 +497,8 @@ dependencies:
483
497
  description: Common core components used in all our web products.
484
498
  email:
485
499
  - chris@app47.com
486
- executables: []
500
+ executables:
501
+ - cron_server
487
502
  extensions: []
488
503
  extra_rdoc_files: []
489
504
  files:
@@ -495,7 +510,21 @@ files:
495
510
  - LICENSE
496
511
  - README.md
497
512
  - Rakefile
513
+ - bin/cron_server
498
514
  - config/locales/en.yml
515
+ - lib/app/jobs/application_job.rb
516
+ - lib/app/jobs/cron/command.rb
517
+ - lib/app/jobs/cron/job.rb
518
+ - lib/app/jobs/cron/job_tab.rb
519
+ - lib/app/jobs/cron/server.rb
520
+ - lib/app/jobs/cron/switchboard_sync_configuration.rb
521
+ - lib/app/jobs/cron/switchboard_sync_models.rb
522
+ - lib/app/jobs/cron/tab.rb
523
+ - lib/app/jobs/cron/trim_collection.rb
524
+ - lib/app/jobs/cron/trim_cron_servers.rb
525
+ - lib/app/jobs/cron/trim_failed_delayed_jobs.rb
526
+ - lib/app/jobs/cron/trim_notifications.rb
527
+ - lib/app/jobs/cron/worker.rb
499
528
  - lib/app/models/concerns/app47_logger.rb
500
529
  - lib/app/models/concerns/cdn_url.rb
501
530
  - lib/app/models/concerns/core_account.rb
@@ -503,7 +532,9 @@ files:
503
532
  - lib/app/models/concerns/email_able.rb
504
533
  - lib/app/models/concerns/search_able.rb
505
534
  - lib/app/models/concerns/standard_model.rb
535
+ - lib/app/models/concerns/switchboard_able.rb
506
536
  - lib/app/models/concerns/time_zone_able.rb
537
+ - lib/app/models/delayed_job.rb
507
538
  - lib/app/models/email_notification.rb
508
539
  - lib/app/models/email_template.rb
509
540
  - lib/app/models/notification.rb
@@ -516,6 +547,7 @@ files:
516
547
  - lib/templates/email/notification_failure.liquid
517
548
  - lib/templates/email/notification_failure.subject.liquid
518
549
  - lib/templates/slack/error_message.liquid
550
+ - lib/templates/slack/failed_delayed_job.liquid
519
551
  - lib/web47core.rb
520
552
  - test/factories/account_factories.rb
521
553
  - test/factories/notification_factories.rb
@@ -524,7 +556,10 @@ files:
524
556
  - test/fixtures/redis/options.yml
525
557
  - test/fixtures/redis/sentinel.yml
526
558
  - test/fixtures/redis/url.yml
527
- - test/models/app47_logger_test.rb
559
+ - test/jobs/cron/switchboard_sync_configuration_test.rb
560
+ - test/jobs/cron/trim_cron_servers_test.rb
561
+ - test/jobs/cron/trim_failed_delayed_jobs_test.rb
562
+ - test/models/concerns/app47_logger_test.rb
528
563
  - test/models/concerns/cdn_url_test.rb
529
564
  - test/models/concerns/email_able_test.rb
530
565
  - test/models/concerns/search_able_test.rb
@@ -532,11 +567,13 @@ files:
532
567
  - test/models/concerns/system_configuration_test.rb
533
568
  - test/models/concerns/time_zone_able_test.rb
534
569
  - test/models/email_notification_test.rb
570
+ - test/models/job_cron_tab_test.rb
535
571
  - test/models/notification_test.rb
536
572
  - test/models/redis_configuration_test.rb
537
573
  - test/models/slack_notification_test.rb
538
574
  - test/models/sms_notification_test.rb
539
575
  - test/models/smtp_configuration_test.rb
576
+ - test/models/web47core_test.rb
540
577
  - test/notification_test_helper.rb
541
578
  - test/rails_setup.rb
542
579
  - test/shoulda_macros/mongoid.rb
@@ -574,7 +611,10 @@ test_files:
574
611
  - test/fixtures/redis/options.yml
575
612
  - test/fixtures/redis/sentinel.yml
576
613
  - test/fixtures/redis/url.yml
577
- - test/models/app47_logger_test.rb
614
+ - test/jobs/cron/switchboard_sync_configuration_test.rb
615
+ - test/jobs/cron/trim_cron_servers_test.rb
616
+ - test/jobs/cron/trim_failed_delayed_jobs_test.rb
617
+ - test/models/concerns/app47_logger_test.rb
578
618
  - test/models/concerns/cdn_url_test.rb
579
619
  - test/models/concerns/email_able_test.rb
580
620
  - test/models/concerns/search_able_test.rb
@@ -582,11 +622,13 @@ test_files:
582
622
  - test/models/concerns/system_configuration_test.rb
583
623
  - test/models/concerns/time_zone_able_test.rb
584
624
  - test/models/email_notification_test.rb
625
+ - test/models/job_cron_tab_test.rb
585
626
  - test/models/notification_test.rb
586
627
  - test/models/redis_configuration_test.rb
587
628
  - test/models/slack_notification_test.rb
588
629
  - test/models/sms_notification_test.rb
589
630
  - test/models/smtp_configuration_test.rb
631
+ - test/models/web47core_test.rb
590
632
  - test/notification_test_helper.rb
591
633
  - test/rails_setup.rb
592
634
  - test/shoulda_macros/mongoid.rb