web47core 3.2.5 → 3.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/app/models/command_job.rb +25 -7
- data/lib/app/models/concerns/archive_able.rb +93 -0
- data/lib/web47core/version.rb +1 -1
- data/lib/web47core.rb +1 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a2f6513fc3ea7307fc8b715807aaeef3ac0c63151bec753ecde3e5233742da5
|
4
|
+
data.tar.gz: 2d27d9d04e23dfd8e71ae2f6fb6080567cbab65f1af0f98ce09c5a34f0e90dfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42801f50f150d8d47db4833cd7c5aff6a7f4743cd6a60797000c331f1815cc57ce6f844933dc7424343962f3363c3b0d9af0a2ac257dd0ff2c6bd1c9ca0a232c
|
7
|
+
data.tar.gz: 8fca8b55c877d788266c5628b59d820b0e147393fd138db16e8bca762dd2a396801fd0701b7a32e0cc56b4fa5c6ae97e45597701f1714787f1892987608378bd
|
@@ -27,26 +27,44 @@ class CommandJob
|
|
27
27
|
field :error_message, type: String
|
28
28
|
field :started_at, type: Time
|
29
29
|
field :finished_at, type: Time
|
30
|
+
field :cancelled_at, type: Time
|
30
31
|
#
|
31
32
|
# Relationships
|
32
33
|
#
|
33
34
|
has_many :logs, class_name: 'CommandJobLog', dependent: :destroy
|
34
|
-
belongs_to :started_by,
|
35
|
+
belongs_to :started_by, polymorphic: true, optional: true, inverse_of: nil
|
36
|
+
belongs_to :cancelled_by, polymorphic: true, optional: true, inverse_of: nil
|
35
37
|
#
|
36
38
|
# Validations
|
37
39
|
#
|
38
40
|
validates :state, inclusion: { in: ALL_STATES }
|
39
41
|
|
40
|
-
#
|
41
|
-
|
42
|
-
|
42
|
+
# @abstract cancel the current job
|
43
|
+
def cancel!(actor)
|
44
|
+
update! cancelled_by: actor, cancelled_at: Time.now.utc, state: STATE_CANCELLED
|
45
|
+
child_jobs.map { |j| j.cancel!(actor) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def child_jobs
|
49
|
+
[]
|
50
|
+
end
|
51
|
+
|
52
|
+
# @abstract duration for the job
|
53
|
+
# @return Integer - How long this job took in milliseconds
|
54
|
+
def duration
|
55
|
+
succeeded? ? finished_at - started_at : 0
|
56
|
+
rescue StandardError
|
57
|
+
0
|
58
|
+
end
|
59
|
+
|
60
|
+
# @abstract Who started this job
|
61
|
+
# @return String - Who started this job if present, otherwise `System`
|
43
62
|
def display_started_by
|
44
63
|
started_by.present? ? started_by.name : 'System'
|
45
64
|
end
|
46
65
|
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
66
|
+
# @abstract Default time to keep a job before auto archiving it
|
67
|
+
# @return Integer - TTL for this job
|
50
68
|
def ttl
|
51
69
|
30
|
52
70
|
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# A module that allows for trash/recycling of an object
|
5
|
+
# it will be deleted in the app, but remain in the database until permanently deleted
|
6
|
+
#
|
7
|
+
module ArchiveAble
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
def self.included(base)
|
11
|
+
base.class_eval do
|
12
|
+
# Fields
|
13
|
+
field :archived, type: Mongoid::Boolean, default: false
|
14
|
+
field :archived_at, type: Time
|
15
|
+
field :archived_by_name, type: String
|
16
|
+
field :archived_by_email, type: String
|
17
|
+
field :restored_at, type: Time
|
18
|
+
field :restored_by_name, type: String
|
19
|
+
field :restored_by_email, type: String
|
20
|
+
# Relationships
|
21
|
+
belongs_to :archived_by, polymorphic: true, optional: true, inverse_of: nil
|
22
|
+
belongs_to :restored_by, polymorphic: true, optional: true, inverse_of: nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# @abstract Display who archived this object
|
27
|
+
# @return String
|
28
|
+
def display_archived_by
|
29
|
+
if archived_by.present?
|
30
|
+
archived_by.display_name
|
31
|
+
elsif archived_by_email.present?
|
32
|
+
"#{archived_by_name} (#{archived_by_email})"
|
33
|
+
else
|
34
|
+
archived_by_name
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# @abstract Display who restored this object
|
39
|
+
# @return String
|
40
|
+
def display_restored_by
|
41
|
+
if restored_by.present?
|
42
|
+
restored_by.display_name
|
43
|
+
elsif restored_by_email.present?
|
44
|
+
"#{restored_by_name} (#{restored_by_email})"
|
45
|
+
else
|
46
|
+
restored_by_name
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def unarchived?
|
51
|
+
!archived?
|
52
|
+
end
|
53
|
+
|
54
|
+
# @abstract Archive the object
|
55
|
+
# @param [Member|User] actor - the thing performing the action
|
56
|
+
def archive(actor)
|
57
|
+
params = if actor.is_a? Cron::Job
|
58
|
+
{ archived: true,
|
59
|
+
archived_at: Time.now.utc,
|
60
|
+
archived_by_name: "System - #{actor.class.name}" }
|
61
|
+
else
|
62
|
+
{ archived: true,
|
63
|
+
archived_by: actor,
|
64
|
+
archived_at: Time.now.utc,
|
65
|
+
archived_by_name: actor.name,
|
66
|
+
archived_by_email: actor.email }
|
67
|
+
end
|
68
|
+
params[:name] = "#{name}-(archived at #{Time.now.utc})" if respond_to?(:name=)
|
69
|
+
update params
|
70
|
+
end
|
71
|
+
|
72
|
+
# @abstract recycle the object
|
73
|
+
# @param [Member|User] actor - the actor performing the action
|
74
|
+
def restore(actor)
|
75
|
+
params = { archived: false,
|
76
|
+
restored_by: actor,
|
77
|
+
restored_at: Time.now.utc,
|
78
|
+
restored_by_name: actor.name,
|
79
|
+
restored_by_email: actor.email }
|
80
|
+
params[:name] = name.split('-(archived at').first if respond_to?(:name=)
|
81
|
+
update params
|
82
|
+
end
|
83
|
+
|
84
|
+
def days_to_deletion
|
85
|
+
archived? ? ((archived_at + retention_days.days - Time.now.utc) / 86_400).to_i : 0
|
86
|
+
rescue StandardError
|
87
|
+
archived? ? retention_days : 0
|
88
|
+
end
|
89
|
+
|
90
|
+
def retention_days
|
91
|
+
30
|
92
|
+
end
|
93
|
+
end
|
data/lib/web47core/version.rb
CHANGED
data/lib/web47core.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'web47core/config'
|
2
2
|
require 'app/models/concerns/app47_logger'
|
3
3
|
require 'app/models/concerns/api_tokenable'
|
4
|
+
require 'app/models/concerns/archive_able'
|
4
5
|
require 'app/models/concerns/aws_configuration'
|
5
6
|
require 'app/models/concerns/core_system_configuration'
|
6
7
|
require 'app/models/concerns/core_account'
|
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: 3.2.
|
4
|
+
version: 3.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Schroeder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11
|
11
|
+
date: 2024-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -501,7 +501,7 @@ dependencies:
|
|
501
501
|
- !ruby/object:Gem::Version
|
502
502
|
version: '0'
|
503
503
|
- !ruby/object:Gem::Dependency
|
504
|
-
name:
|
504
|
+
name: simplecov_lcov_formatter
|
505
505
|
requirement: !ruby/object:Gem::Requirement
|
506
506
|
requirements:
|
507
507
|
- - ">="
|
@@ -645,6 +645,7 @@ files:
|
|
645
645
|
- lib/app/models/command_job_log.rb
|
646
646
|
- lib/app/models/concerns/api_tokenable.rb
|
647
647
|
- lib/app/models/concerns/app47_logger.rb
|
648
|
+
- lib/app/models/concerns/archive_able.rb
|
648
649
|
- lib/app/models/concerns/aws_configuration.rb
|
649
650
|
- lib/app/models/concerns/cdn_url.rb
|
650
651
|
- lib/app/models/concerns/cipher_able.rb
|
@@ -712,7 +713,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
712
713
|
- !ruby/object:Gem::Version
|
713
714
|
version: '0'
|
714
715
|
requirements: []
|
715
|
-
rubygems_version: 3.
|
716
|
+
rubygems_version: 3.5.13
|
716
717
|
signing_key:
|
717
718
|
specification_version: 4
|
718
719
|
summary: App47 Web Core Library.
|