parameters: (
      pool,
      plan,
      bucket_name,
      tiles_dir,
      max_zoom,
      raven_client,
      bucket_prefix="tiles/",
      delete_batch_size=100,
  )
return_statement: return result
docstring: Execute the plan to sync the local tiles to S3 bucket objects.
docstring_summary: Execute the plan to sync the local tiles to S3 bucket objects.
docstring_tokens: Execute the plan to sync the local tiles to S3 bucket objects .
function: def sync_tiles(
      pool,
      plan,
      bucket_name,
      tiles_dir,
      max_zoom,
      raven_client,
      bucket_prefix="tiles/",
      delete_batch_size=100,
  ):
      """Execute the plan to sync the local tiles to S3 bucket objects."""
  
      result = {
          "tile_new": 0,
          "tile_changed": 0,
          "tile_deleted": 0,
          "tile_failed": 0,
      }
  
      # Queue the sync plan actions
      jobs = []
      for path in plan["upload"]:
          jobs.append(
              pool.apply_async(upload_file, (path, bucket_name, bucket_prefix, tiles_dir))
          )
      for path in plan["update"]:
          jobs.append(
              pool.apply_async(update_file, (path, bucket_name, bucket_prefix, tiles_dir))
          )
      total = len(plan["upload"]) + len(plan["update"])
  
      # Queue the delete actions in batches
      for paths in chunked(plan["delete"], delete_batch_size):
          total += len(paths)
          jobs.append(pool.apply_async(delete_files, (paths, bucket_name, bucket_prefix)))
  
      # Watch sync jobs until completion
      def on_success(job_result):
          nonlocal result
          tile_result, count = job_result
          result[tile_result] += count
  
      def on_error(exception):
          nonlocal result
          LOG.error(f"Exception while syncing: {exception}")
          result["tile_failed"] += 1  # Would be wrong if a delete fails
  
      def on_progress(jobs_complete, job_total):
          nonlocal result, total
          count = sum(result.values())
          percent = count / total
          LOG.debug(f"  Synced {count:,} file{_s(count)} ({percent:.1%})")
  
      watch_jobs(jobs, on_progress=on_progress, on_success=on_success, on_error=on_error)
      return result
function_tokens: def sync_tiles ( pool , plan , bucket_name , tiles_dir , max_zoom , raven_client , bucket_prefix = "tiles/" , delete_batch_size = 100 , ) : result = { "tile_new" : 0 , "tile_changed" : 0 , "tile_deleted" : 0 , "tile_failed" : 0 , } # Queue the sync plan actions jobs = [ ] for path in plan [ "upload" ] : jobs . append ( pool . apply_async ( upload_file , ( path , bucket_name , bucket_prefix , tiles_dir ) ) ) for path in plan [ "update" ] : jobs . append ( pool . apply_async ( update_file , ( path , bucket_name , bucket_prefix , tiles_dir ) ) ) total = len ( plan [ "upload" ] ) + len ( plan [ "update" ] ) # Queue the delete actions in batches for paths in chunked ( plan [ "delete" ] , delete_batch_size ) : total += len ( paths ) jobs . append ( pool . apply_async ( delete_files , ( paths , bucket_name , bucket_prefix ) ) ) # Watch sync jobs until completion def on_success ( job_result ) : nonlocal result tile_result , count = job_result result [ tile_result ] += count def on_error ( exception ) : nonlocal result LOG . error ( f"Exception while syncing: {exception}" ) result [ "tile_failed" ] += 1 # Would be wrong if a delete fails def on_progress ( jobs_complete , job_total ) : nonlocal result , total count = sum ( result . values ( ) ) percent = count / total LOG . debug ( f"  Synced {count:,} file{_s(count)} ({percent:.1%})" ) watch_jobs ( jobs , on_progress = on_progress , on_success = on_success , on_error = on_error ) return result