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
Constructor Details
#initialize(tag: Bitferry.tag, modified: DateTime.now) ⇒ Task
Returns a new instance of Task.
533
534
535
536
537
538
|
# File 'lib/bitferry.rb', line 533
def initialize(tag: Bitferry.tag, modified: DateTime.now)
@tag = tag
@generation = 0
@modified = modified
end
|
Instance Attribute Details
#generation ⇒ Object
Returns the value of attribute generation.
495
496
497
|
# File 'lib/bitferry.rb', line 495
def generation
@generation
end
|
#modified ⇒ Object
Returns the value of attribute modified.
498
499
500
|
# File 'lib/bitferry.rb', line 498
def modified
@modified
end
|
#tag ⇒ Object
Returns the value of attribute tag.
492
493
494
|
# File 'lib/bitferry.rb', line 492
def tag
@tag
end
|
Class Method Details
.[](tag) ⇒ Object
587
|
# File 'lib/bitferry.rb', line 587
def self.[](tag) = @@registry[tag]
|
.delete(*tags) ⇒ Object
518
519
520
521
522
523
524
525
526
527
528
529
530
|
# File 'lib/bitferry.rb', line 518
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
615
|
# File 'lib/bitferry.rb', line 615
def self.intact = live.filter { |task| task.intact? }
|
.live ⇒ Object
606
|
# File 'lib/bitferry.rb', line 606
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
591
|
# File 'lib/bitferry.rb', line 591
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
595
596
597
598
599
600
|
# File 'lib/bitferry.rb', line 595
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
504
505
506
507
508
|
# File 'lib/bitferry.rb', line 504
def self.new(*args, **opts)
task = allocate
task.send(:create, *args, **opts)
register(task)
end
|
.register(task) ⇒ Object
TODO settle on task with the latest timestamp
612
|
# File 'lib/bitferry.rb', line 612
def self.register(task) = @@registry[task.tag] = task
|
.registered ⇒ Object
603
|
# File 'lib/bitferry.rb', line 603
def self.registered = @@registry.values
|
.reset ⇒ Object
609
|
# File 'lib/bitferry.rb', line 609
def self.reset = @@registry = {}
|
.restore(hash) ⇒ Object
511
512
513
514
515
|
# File 'lib/bitferry.rb', line 511
def self.restore(hash)
task = allocate
task.send(:restore, hash)
register(task)
end
|
.stale ⇒ Object
618
|
# File 'lib/bitferry.rb', line 618
def self.stale = live.filter { |task| !task.intact? }
|
Instance Method Details
#commit ⇒ Object
579
580
581
582
583
584
|
# File 'lib/bitferry.rb', line 579
def commit
case @state
when :pristine then format
when :removing then @state = nil
end
end
|
#create(*args, **opts) ⇒ Object
541
542
543
544
545
|
# File 'lib/bitferry.rb', line 541
def create(*args, **opts)
initialize(*args, **opts)
@state = :pristine
touch
end
|
#delete ⇒ Object
572
573
574
575
576
|
# File 'lib/bitferry.rb', line 572
def delete
touch
@state = :removing
log.info("marked task #{tag} for removal")
end
|
#externalize ⇒ Object
558
559
560
561
562
563
|
# File 'lib/bitferry.rb', line 558
def externalize
{
task: tag,
modified: @modified
}.compact
end
|
#live? ⇒ Boolean
566
|
# File 'lib/bitferry.rb', line 566
def live? = !@state.nil? && @state != :removing
|
#process_options ⇒ Object
As a mandatory option it should never be nil
501
|
# File 'lib/bitferry.rb', line 501
def process_options = @process_options.nil? ? [] : @process_options
|
#restore(hash) ⇒ Object
548
549
550
551
|
# File 'lib/bitferry.rb', line 548
def restore(hash)
@state = :intact
log.info("restored task #{tag}")
end
|
#restore_endpoint(x) ⇒ Object
FIXME move to Endpoint#restore
555
|
# File 'lib/bitferry.rb', line 555
def restore_endpoint(x) = Endpoint::ROUTE.fetch(x.fetch(:endpoint).intern).restore(x)
|
#touch ⇒ Object
569
|
# File 'lib/bitferry.rb', line 569
def touch = @modified = DateTime.now
|