Class: Bitferry::Task
Constant Summary
collapse
- ROUTE =
{
copy: Rclone::Copy,
update: Rclone::Update,
synchronize: Rclone::Synchronize,
equalize: Rclone::Equalize,
backup: Restic::Backup,
restore: Restic::Restore
}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Logging
log, log, log=
Constructor Details
#initialize(tag: Bitferry.tag, modified: DateTime.now, include: [], exclude: []) ⇒ Task
Returns a new instance of Task.
554
555
556
557
558
559
560
561
|
# File 'lib/bitferry.rb', line 554
def initialize(tag: Bitferry.tag, modified: DateTime.now, include: [], exclude: [])
@tag = tag
@generation = 0
@include = include
@exclude = exclude
@modified = modified.is_a?(DateTime) ? modified : DateTime.parse(modified)
end
|
Instance Attribute Details
#exclude ⇒ Object
Returns the value of attribute exclude.
519
520
521
|
# File 'lib/bitferry.rb', line 519
def exclude
@exclude
end
|
#generation ⇒ Object
Returns the value of attribute generation.
513
514
515
|
# File 'lib/bitferry.rb', line 513
def generation
@generation
end
|
#include ⇒ Object
Returns the value of attribute include.
519
520
521
|
# File 'lib/bitferry.rb', line 519
def include
@include
end
|
#modified ⇒ Object
Returns the value of attribute modified.
516
517
518
|
# File 'lib/bitferry.rb', line 516
def modified
@modified
end
|
#tag ⇒ Object
Returns the value of attribute tag.
510
511
512
|
# File 'lib/bitferry.rb', line 510
def tag
@tag
end
|
Class Method Details
.[](tag) ⇒ Object
622
|
# File 'lib/bitferry.rb', line 622
def self.[](tag) = @@registry[tag]
|
.delete(*tags) ⇒ Object
539
540
541
542
543
544
545
546
547
548
549
550
551
|
# File 'lib/bitferry.rb', line 539
def self.delete(*tags)
process = []
tags.each do |tag|
case (tasks = Task.lookup(tag)).size
when 0 then log.warn("no tasks matching (partial) tag #{tag}")
when 1 then process += tasks
else
tags = tasks.collect { |v| v.tag }.join(', ')
raise ArgumentError, "multiple tasks matching (partial) tag #{tag}: #{tags}"
end
end
process.each { |task| task.delete }
end
|
.intact ⇒ Object
658
|
# File 'lib/bitferry.rb', line 658
def self.intact = live.filter { |task| task.intact? }
|
.live ⇒ Object
641
|
# File 'lib/bitferry.rb', line 641
def self.live = registered.filter { |task| task.live? }
|
.lookup(*tags) ⇒ Object
Return list of registered tasks whose tags match at least one of specified partial tags
626
|
# File 'lib/bitferry.rb', line 626
def self.lookup(*tags) = match(tags, registered)
|
.match(tags, tasks) ⇒ Object
Return list of specified tasks whose tags match at least one of specified partial tags
630
631
632
633
634
635
|
# File 'lib/bitferry.rb', line 630
def self.match(tags, tasks)
rxs = tags.collect { |x| Regexp.new(x) }
tasks.filter do |task|
rxs.any? { |rx| !(rx =~ task.tag).nil? }
end
end
|
.new(*args, **opts) ⇒ Object
525
526
527
528
529
|
# File 'lib/bitferry.rb', line 525
def self.new(*args, **opts)
task = allocate
task.send(:create, *args, **opts)
register(task)
end
|
.register(task) ⇒ Object
647
648
649
650
651
652
653
654
655
656
|
# File 'lib/bitferry.rb', line 647
def self.register(task)
if (xtag = @@registry[task.tag]).nil?
@@registry[task.tag] = task
elsif xtag.modified < task.modified
@@registry[task.tag] = task
else
xtag
end
end
|
.registered ⇒ Object
638
|
# File 'lib/bitferry.rb', line 638
def self.registered = @@registry.values
|
.reset ⇒ Object
644
|
# File 'lib/bitferry.rb', line 644
def self.reset = @@registry = {}
|
.restore(hash) ⇒ Object
532
533
534
535
536
|
# File 'lib/bitferry.rb', line 532
def self.restore(hash)
task = allocate
task.send(:restore, hash)
register(task)
end
|
.stale ⇒ Object
661
|
# File 'lib/bitferry.rb', line 661
def self.stale = live.filter { |task| !task.intact? }
|
Instance Method Details
#commit ⇒ Object
606
607
608
609
610
611
|
# File 'lib/bitferry.rb', line 606
def commit
case @state
when :pristine then format
when :removing then @state = nil
end
end
|
#create(*args, **opts) ⇒ Object
564
565
566
567
568
|
# File 'lib/bitferry.rb', line 564
def create(*args, **opts)
initialize(*args, **opts)
@state = :pristine
touch
end
|
#delete ⇒ Object
599
600
601
602
603
|
# File 'lib/bitferry.rb', line 599
def delete
touch
@state = :removing
log.info("marked task #{tag} for removal")
end
|
#externalize ⇒ Object
583
584
585
586
587
588
589
590
|
# File 'lib/bitferry.rb', line 583
def externalize
{
task: tag,
modified: modified,
include: include.empty? ? nil : include,
exclude: exclude.empty? ? nil : exclude
}.compact
end
|
#live? ⇒ Boolean
593
|
# File 'lib/bitferry.rb', line 593
def live? = !@state.nil? && @state != :removing
|
#process_options ⇒ Object
As a mandatory option it should never be nil
522
|
# File 'lib/bitferry.rb', line 522
def process_options = @process_options.nil? ? [] : @process_options
|
#restore(hash) ⇒ Object
571
572
573
574
575
576
|
# File 'lib/bitferry.rb', line 571
def restore(hash)
@include = hash.fetch(:include, [])
@exclude = hash.fetch(:exclude, [])
@state = :intact
log.info("restored task #{tag}")
end
|
#restore_endpoint(x) ⇒ Object
FIXME move to Endpoint#restore
580
|
# File 'lib/bitferry.rb', line 580
def restore_endpoint(x) = Endpoint::ROUTE.fetch(x.fetch(:endpoint).intern).restore(x)
|
#show_filters ⇒ Object
614
615
616
617
618
619
|
# File 'lib/bitferry.rb', line 614
def show_filters
xs = []
xs << 'include: ' + include.join(',') unless include.empty?
xs << 'exclude: ' + exclude.join(',') unless exclude.empty?
xs.join(' ').to_s
end
|
#touch ⇒ Object
596
|
# File 'lib/bitferry.rb', line 596
def touch = @modified = DateTime.now
|