Google cloud platform 如何为存储桶中的文件更改创建电子邮件通知

Google cloud platform 如何为存储桶中的文件更改创建电子邮件通知,google-cloud-platform,notifications,google-cloud-storage,Google Cloud Platform,Notifications,Google Cloud Storage,如何创建电子邮件地址的电子邮件通知(john。citizen@gmail.com) (当存储桶中的文件发生更改,即添加新文件、追加、覆盖或更新失败时?我只是从GCP开始。GCP在云存储中发生更改时没有“给我发邮件”,但您可以在应用程序中接收通知并从中发送电子邮件 有两种方法可以做到这一点: 将向你的应用程序发送HTTP帖子 (谷歌推荐)-当创建、修改或删除文件时,它会发布发布/订阅消息。发布/订阅可以执行HTTP发布、触发云函数、触发云运行(类似函数,但已停靠)或被轮询 谷歌也有一个教程

如何创建电子邮件地址的电子邮件通知(john。citizen@gmail.com) (当存储桶中的文件发生更改,即添加新文件、追加、覆盖或更新失败时?我只是从GCP开始。

GCP在云存储中发生更改时没有“给我发邮件”,但您可以在应用程序中接收通知并从中发送电子邮件

有两种方法可以做到这一点:

  • 将向你的应用程序发送HTTP帖子

  • (谷歌推荐)-当创建、修改或删除文件时,它会发布发布/订阅消息。发布/订阅可以执行HTTP发布、触发云函数、触发云运行(类似函数,但已停靠)或被轮询

谷歌也有一个教程

您可能会发现一个边缘案例很有帮助:

如果

  • 音量非常低,而且
  • 文件创建/更新/删除会一个接一个地发生,并且
  • 您不介意更改/创建/更新了哪个文件,并且
  • 丢失通知并不重要
然后你可以:


  • 设置一个低保留率的pubsub队列(GCP在云存储发生变化时没有“给我发邮件”,但您可以在应用程序中接收通知并从中发送电子邮件

    有两种方法可以做到这一点:

    • 将向你的应用程序发送HTTP帖子

    • (谷歌推荐)-当创建、修改或删除文件时,它会发布发布/订阅消息。发布/订阅可以执行HTTP发布、触发云函数、触发云运行(类似函数,但已停靠)或被轮询

    谷歌也有一个教程

    您可能会发现一个边缘案例很有帮助:

    如果

    • 音量非常低,而且
    • 文件创建/更新/删除会一个接一个地发生,并且
    • 您不介意更改/创建/更新了哪个文件,并且
    • 丢失通知并不重要
    然后你可以:

    • 设置保留率低的子队列(
      #Only change dataset name
      
      def process_request(event, context):
          try:
          
              # Change the bigquery_dataset Name according to what you have created.
              bigquery_dataset_name = 'Your dataset name'
      
              # Don't Change Anything from here on.
              # When creating the function trigger type event = storage bucket
      
              source_bucket_name = event['bucket']
              blob_name = event['name']
              # call function to notify bucket updates
             #send_text_message_to_teams("{} has been received in {}".format(blob_name, source_bucket_name))
              storage_client = storage.Client()
              bigquery_client = bigquery.Client()
              source_bucket = storage_client.bucket(source_bucket_name) 
              source_blob = source_bucket.blob(blob_name)
              
              #check if file type is csv the define job_config,uri, filename, tablename and table id AND then load the job
              if source_blob.name.split('.')[-1] == 'csv':
                  job_config = bigquery.LoadJobConfig(
                          skip_leading_rows=1,
                          autodetect=True,
                          source_format=bigquery.SourceFormat.CSV,
                          write_disposition=bigquery.WriteDisposition.WRITE_TRUNCATE)
                  uri = 'gs://{}/{}'.format(source_bucket_name, source_blob.name)
                  file_name = '.'.join(source_blob.name.split('/')[-1].split('.')[0:-1])
                  table_name = ''.join([character if character.isalnum() else '_' for character in file_name])
                  table_id = '{}.{}.{}'.format(bigquery_client.project, bigquery_dataset_name, table_name)
                  print('Trasferring {} into {}'.format(source_blob.name, table_id))
                  
              #load job using details above   
                  load_job = bigquery_client.load_table_from_uri(uri, table_id, job_config=job_config)
                  load_job.result()
                  print("table updated")
                  print('{} has been processed.'.format(source_blob.name))
                  # call function to notify table updates
                  #send_text_message_to_teams("{} has been updated".format(table_id))
              else:
                  print('{} is not a csv.'.format(source_blob.name))
          except Exception as e:
               # call function to notify failures
               #send_text_message_to_teams("function-uploadcsv has encoutered an issue. The details are {}".format(e))