24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/cron_to_go_sync/sync_interactor.rb', line 24
def call
unless File.exist? context.input_filename
context.fail!(error: "No such file found", filename: context.input_filename)
end
target_jobs = Parser.parse_toml_file(context.input_filename)
existing_jobs = get_jobs_from_crontogo
context.deleted = (existing_jobs.keys.to_set - target_jobs.keys.to_set).map do |alias_to_remove|
delete_job existing_jobs[alias_to_remove][:id]
end.size
context.created = (target_jobs.keys.to_set - existing_jobs.keys.to_set).map do |alias_to_add|
create_job target_jobs[alias_to_add]
end.size
context.updated = (target_jobs.keys.to_set & existing_jobs.keys.to_set).sum do |alias_to_update|
existing = existing_jobs[alias_to_update]
target = target_jobs[alias_to_update]
if target.merge({id: existing[:id]}) != existing
update_job(target, existing[:id])
1
else
0
end
end
end
|