{% set is_logbroker_backup = ferryman_type == 'logbroker_backup' %}

Server: "{{ yt_cluster }}"
RootFolder: "//home/saas/ferryman-{{ suffix }}/{{ service }}"
YtPullFolder: "//home/saas/ferryman-{{ suffix }}/{{ service }}/ytpull"

MainLogPath: "main.log"
ShellLogPath: "current-ferryman_worker.log"

{% if is_logbroker_backup %}
MaxStatesToKeep: 1
{% else %}
MaxStatesToKeep: {{ max_states_to_keep }}
{% endif %}

MaxErrorStatesToKeep: 1
AllowedInputSize: {{ allowed_input_size }}
NamespaceValidatorType: {{ namespace_validator }}
LegacyOutputTimestamps: false

EnableDeltas: true
DropFinalDeltas: true
KeepOldIncomingTables: true

RetryDelays: 60
RetryDelays: 120
RetryDelays: 240

SolomonConfig {
  Url: "http://api.solomon.search.yandex.net/push/json"
  Project: "saas_ferryman"
  Cluster: "{{ solomon_ctype }}"
  Service: "{{ service }}"
}

{% if is_logbroker_backup %}
ServerConfig {
  DefaultNamespace: true
}

SearchStatusConfig {
  AgeQuery: "http://saas-dm-proxy.n.yandex-team.ru/broadcast_age?ctype={{ ctype }}&service={{ service }}"
  IsBackup: true
}
{% else %}
SearchStatusConfig {
  StatusQuery: "http://saas-dm-proxy.n.yandex-team.ru/docfetcher?ctype={{ ctype }}&service={{ service }}"
}
{% endif %}

TaskParams {
  Key: "single_ns"
  Value: "{{ (is_logbroker_backup) | lower }}"
}
TaskParams {
  Key: "calculate_delta_size"
  Value: "{{ (not is_logbroker_backup) | lower }}"
}
TaskParams {
  Key: "config"
  Value: "config.pb.txt"
}
TaskParams {
  Key: "service"
  Value: "{{ service }}"
}
TaskParams {
  Key: "ctype"
  Value: "{{ ctype }}"
}
TaskParams {
  Key: "ytpull_path"
  Value: "//home/saas/ferryman-{{ suffix }}/{{ service }}/ytpull"
}
TaskParams {
  Key: "proxy"
  Value: "{{ yt_cluster }}"
}
TaskParams {
  Key: "sharding_type"
  Value: "url_hash"
}
TaskParams {
  Key: "kps_shift"
  Value: "0"
}
TaskParams {
  Key: "row_processor"
  Value: "{{ row_processor }}"
}
TaskParams {
  Key: "fullstate_cycle"
  Value: "{{ fullstate_cycle }}"
}
TaskParams {
  Key: "ignore_incorrect_docs"
  Value: "{{ is_logbroker_backup | lower }}"
}
TaskParams {
  Key: "nodeadline"
  Value: "{{ (not is_logbroker_backup) | lower }}"
}
TaskParams {
  Key: "write_ytpull"
  Value: "true"
}
TaskParams {
  Key: "remove_expired"
  Value: "true"
}

{% if ferryman_type == 'delta' %}
TaskParams {
  Key: "dish_delta"
  Value: "//home/saas/ferryman-{{ suffix }}/{{ service }}/dish.delta"
}
TaskParams {
  Key: "pan_delta"
  Value: "//home/saas/ferryman-{{ suffix }}/{{ service }}/pan.delta"
}
TaskParams {
  Key: "save_deleted_documents"
  Value: "true"
}
TaskParams {
  Key: "cook_format"
  Value: "delta"
}
TaskParams {
  Key: "delta_count"
  Value: "12"
}
{% endif %}

TaskParams {
  Key: "pan"
  Value: "//home/saas/ferryman-{{ suffix }}/{{ service }}/pan"
}
TaskParams {
  Key: "dish"
  Value: "//home/saas/ferryman-{{ suffix }}/{{ service }}/dishes"
}
TaskParams {
  Key: "dict_path"
  Value: "./dict.dict"
}
TaskParams {
  Key: "cut_includes"
  Value: "false"
}
TaskParams {
  Key: "get_indexer_dir"
  Value: "/gear"
}
TaskParams {
  Key: "add_extra_timestamp"
  Value: "{{ (ferryman_type in ['ytpull', 'delta']) | lower }}"
}

{% if ferryman_type in ['ytpull', 'logbroker_backup', 'delta'] %}
TaskParams {
  Key: "backup_table_name"
  Value: "full"
}
TaskParams {
  Key: "snapshot_count"
  Value: "3"
}
{% endif %}
TaskParams {
  Key: "sky_share"
  Value: "true"
}

Tasks {
  Name: "json_convert"
  Command: "./ferryman_json_worker json_convert"
  Input: "input_json"
  Output: "input_proto"
  Params: "workspace"
  Params: "proxy"
  Params: "sharding_type"
  Params: "kps_shift"
  Params: "row_processor"
  Params: "nodeadline"
  Params: "single_ns"
  Params: "ignore_incorrect_docs"
}
Tasks {
  Name: "json_merge"
  Command: "./ferryman_json_worker json_merge"
  Input: "state_prev"
  Input: "input_proto"
  Output: "state"
  Output: "delta"
  Output: "reverse"
  Output: "ytpull_tmp"
  Params: "workspace"
  Params: "proxy"
  Params: "sharding_type"
  Params: "kps_shift"
  Params: "remove_expired"
  Params: "calculate_delta_size"
  Params: "config"
  Params: "single_ns"
  Params: "write_ytpull"
  Params: "timestamp"
  Params: "ytpull_path"
  Params: "oldest"
  Params: "fullstate_cycle"
}

{% if ferryman_type == 'delta' %}
Tasks {
  Name: "cook_delta"
  Command: "./ferryman_cooker"
  Input: "ytpull_tmp"
  Output: "cook_out"
  Params: "add_extra_timestamp"
  Params: "cook_format"
  Params: "ctype"
  Params: "cut_includes"
  Params: "dict_path"
  Params: "dish:dish_delta"
  Params: "get_indexer_dir"
  Params: "snapshot_count:delta_count"
  Params: "pan:pan_delta"
  Params: "proxy"
  Params: "save_deleted_documents"
  Params: "service"
  Params: "timestamp"
  Params: "workspace"
  Params: "ytpull_path"
  Params: "sky_share"
}

{% endif %}

{% if ferryman_type == 'snapshot' %}
Tasks {
  Name: "cook"
  Command: "./ferryman_cooker"
  Input: "ytpull_tmp"
  Output: "cook_out"
  Params: "workspace"
  Params: "proxy"
  Params: "timestamp"
  Params: "oldest"
  Params: "ytpull_path"
  Params: "pan"
  Params: "dish"
  Params: "get_indexer_dir"
  Params: "service"
  Params: "ctype"
  Params: "cut_includes"
  Params: "dict_path"
  Params: "sky_share"
}
{% else %}
CustomTaskConfig {
  Folders {
    Name: "custom_input_folder"
    RelativePath: "backup_input"
  }
  Folders {
    Name: "cook_lock"
  }
  Timers {
    Name: "backup_timer"
    LoopParams {
      IntervalSeconds: 14400
    }
  }
  Tasks {
    Name: "builtin#copy_table"
    Command: ""
    Input: "ytpull_tmp"
    Output: "custom_input_folder"
    Params: "table:backup_table_name"
  }
  Tasks {
    Name: "backup_cook"
    Command: "./ferryman_cooker"
    Input: "timer#backup_timer"
    Input: "custom_input_folder"
    Output: "cook_out:cook_lock"
    Params: "proxy"
    Params: "timestamp"
    Params: "ytpull_path"
    Params: "pan"
    Params: "dish"
    Params: "snapshot_count"
    Params: "get_indexer_dir"
    Params: "service"
    Params: "ctype"
    Params: "add_extra_timestamp"
    Params: "cut_includes"
    Params: "dict_path"
    Params: "sky_share"
  }
}
{% endif %}

LoopRenamings {
  From: "state"
  To: "state_prev"
}

{% if not is_logbroker_backup %}
FinalStateMerge {
    IntervalSeconds: 3600
}
{% endif %}
