怎么样与AGC云数据库端云同步

看文档是支持AGC云数据库端云同步的,可是不是到应该配置些什么,我直接设置分布表为在设备和云端之间分布式的数据库表,然后在初始化云服务后就手动触发云同步

最后报出日志"schedule":2,"code":3,"details":{},不知道是哪有问题,该怎么实现端云同步

async function configureDistributedTables(store: relationalStore.RdbStore): Promise<void> {
  try {
    (store as relationalStore.RdbStore).setDistributedTables(
      ["BILLING_TYPE","BILLING_FORMAT"],
      relationalStore.DistributedType.DISTRIBUTED_CLOUD,
      { autoSync: true }
    );
    LogUtil.info('分布式表设置成功');
  } catch (err) {
    LogUtil.error(`错误码:${err.code},错误信息:${err.message}`)
    throw new Error(`配置失败: ${err.message}`);
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.

export async function syncToCloud() {
  try {
    const store: relationalStore.RdbStore = getStore();

    // 配置网络策略(仅WiFi)
    await cloudData.setCloudStrategy(
      cloudData.StrategyType.NETWORK,
      [cloudData.NetWorkStrategy.WIFI]
    );

    // 手动触发端云同步
    await (store as relationalStore.RdbStore).cloudSync(
      relationalStore.SyncMode.SYNC_MODE_CLOUD_FIRST,
      ["BILLING_TYPE", "BILLING_FORMAT"], // 指定同步表
      (progressDetail) => {
        LogUtil.info(`同步进度: ${JSON.stringify(progressDetail)}`);
      }
    );
    LogUtil.info('同步成功');
  } catch (err) {
    LogUtil.error(`同步失败: ${err.code} - ${err.message}`);
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.

async function initCloudService() {
  try {
    let authProvider = auth.getAuthProvider();
    cloudCommon.init({
      region: cloudCommon.CloudRegion.CHINA,
      authProvider: authProvider,
      functionOptions:{timeout:10*1000},
      storageOptions: {mode:request.agent.Mode.BACKGROUND, network:request.agent.Network.ANY},
      databaseOptions: {
        traceId:`order_sync_$${Date.now()}_$${Math.random().toString(36).substr(2, 8)}`}
    });
    LogUtil.info(`云服务初始化成功`)
  }catch (err) {
    LogUtil.error('初始化失败')
  }
}

//然后进行手动同步
await syncToCloud()
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
鸿蒙开发
20h前
浏览
收藏 0
回答 0
待解决
相关问题
数据库专属集群MyBase和PolarDB区别?
3353浏览 • 1回复 待解决
数据库Redis版提供怎样的服务?
3287浏览 • 1回复 待解决
服务器ECS自带MySQL数据库吗?
3701浏览 • 1回复 待解决
设备同步侧相关问题
9943浏览 • 3回复 待解决
多个数据库同步数据
2368浏览 • 1回复 待解决
数据库操作同步的方法
2334浏览 • 1回复 待解决
应用侧显示华为mqtt数据怎么做?
7560浏览 • 1回复 待解决
隐私中哪些数据不会上
971浏览 • 1回复 待解决
鸿蒙系统怎么样好用吗
7浏览 • 0回复 待解决
HarmonyOS 怎么样使线程休眠
562浏览 • 1回复 待解决
键值型数据库跨设备数据同步demo
1418浏览 • 1回复 待解决
OceanBase是什么数据库?
4104浏览 • 1回复 待解决