יצירת תהליך עבודה באמצעות מסוף Google Cloud

במדריך למתחילים הזה נסביר איך ליצור, לפרוס ולהפעיל את זרימת העבודה הראשונה באמצעות מסוף Google Cloud . תהליך העבודה לדוגמה שולח בקשה ל-API ציבורי ומחזיר את התגובה של ה-API.


לחצו על תראו לי איך כדי לקרוא הסבר מפורט על המשימה ישירות במסוף Google Cloud :

תראו לי איך


לפני שמתחילים

יכול להיות שהגבלות אבטחה שהוגדרו בארגון שלכם ימנעו מכם להשלים את השלבים הבאים. מידע לפתרון בעיות זמין במאמר פיתוח אפליקציות בסביבה מוגבלת. Google Cloud

  1. נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  4. Verify that billing is enabled for your Google Cloud project.

  5. Enable the Workflows API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  6. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  7. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

  8. Verify that billing is enabled for your Google Cloud project.

  9. Enable the Workflows API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  10. מגדירים אימות:
    1. מוודאים שיש לכם את תפקיד ה-IAM ‏Create Service Accounts ‏(roles/iam.serviceAccountCreator) ואת תפקיד ה-IAM ‏Project Admin ‏(roles/resourcemanager.projectIamAdmin). איך מקצים תפקידים
    2. במסוף Google Cloud , נכנסים לדף יצירת חשבון שירות.

      כניסה לדף Create service account
    3. בוחרים את הפרויקט הרצוי.
    4. כותבים שם בשדה Service account name. המסוף Google Cloud ממלא את השדה מזהה חשבון שירות בהתאם לשם הזה.

      כותבים תיאור בשדה Service account description. לדוגמה: Service account for quickstart.

    5. לוחצים על Create and continue.
    6. מקצים לחשבון השירות את התפקיד Logging > Logs Writer.

      כדי להקצות את התפקיד, בוחרים באפשרות Logging > Logs Writer מהרשימה Select a role.

    7. לוחצים על Continue.
    8. לוחצים על Done כדי לסיים ליצור את חשבון השירות.

  11. מידע נוסף על תפקידים והרשאות בחשבונות שירות זמין במאמר איך נותנים הרשאה לגישה למשאבי Google Cloud בתהליך עבודה.

התפקידים הנדרשים

כדי לקבל את ההרשאות שדרושות לביצוע ההפעלה המהירה הזו, צריך לבקש מהאדמין להקצות לכם את תפקידי ה-IAM הבאים בפרויקט:

להסבר על מתן תפקידים, ראו איך מנהלים את הגישה ברמת הפרויקט, התיקייה והארגון.

יכול להיות שאפשר לקבל את ההרשאות הנדרשות גם באמצעות תפקידים בהתאמה אישית או תפקידים מוגדרים מראש.

יצירה ופריסה של תהליך עבודה

  1. נכנסים לדף Workflows במסוף Google Cloud :

    כניסה לדף Workflows

  2. בדף Workflows (תהליכי עבודה), לוחצים על Create (יצירה).

  3. מזינים שם לתהליך העבודה החדש, למשל myFirstWorkflow.

  4. בוחרים את האזור us-central1.

  5. בקטע Service account, בוחרים את חשבון השירות שיצרתם קודם.

  6. לוחצים על הבא.

  7. בעורך תהליכי העבודה, מעתיקים ומדביקים את תהליך העבודה הבא:

    YAML

    main:
      params: [input]
      steps:
        - checkSearchTermInInput:
            switch:
              - condition: '${"searchTerm" in input}'
                assign:
                  - searchTerm: '${input.searchTerm}'
                next: readWikipedia
        - getLocation:
            call: sys.get_env
            args:
              name: GOOGLE_CLOUD_LOCATION
            result: location
        - setFromCallResult:
            assign:
              - searchTerm: '${text.split(location, "-")[0]}'
        - readWikipedia:
            call: http.get
            args:
              url: 'https://en.wikipedia.org/w/api.php'
              query:
                action: opensearch
                search: '${searchTerm}'
            result: wikiResult
        - returnOutput:
            return: '${wikiResult.body[1]}'

    JSON

    {
      "main": {
        "params": [
          "input"
        ],
        "steps": [
          {
            "checkSearchTermInInput": {
              "switch": [
                {
                  "condition": "${\"searchTerm\" in input}",
                  "assign": [
                    {
                      "searchTerm": "${input.searchTerm}"
                    }
                  ],
                  "next": "readWikipedia"
                }
              ]
            }
          },
          {
            "getLocation": {
              "call": "sys.get_env",
              "args": {
                "name": "GOOGLE_CLOUD_LOCATION"
              },
              "result": "location"
            }
          },
          {
            "setFromCallResult": {
              "assign": [
                {
                  "searchTerm": "${text.split(location, \"-\")[0]}"
                }
              ]
            }
          },
          {
            "readWikipedia": {
              "call": "http.get",
              "args": {
                "url": "https://en.wikipedia.org/w/api.php",
                "query": {
                  "action": "opensearch",
                  "search": "${searchTerm}"
                }
              },
              "result": "wikiResult"
            }
          },
          {
            "returnOutput": {
              "return": "${wikiResult.body[1]}"
            }
          }
        ]
      }
    }
    

    אלא אם אתם מזינים מונח חיפוש משלכם, בתהליך העבודה הזה נעשה שימוש בGoogle Cloud מיקום שלכם כדי ליצור מונח חיפוש, שמועבר אל Wikipedia API. מוחזרת רשימה של מאמרי ויקיפדיה שקשורים לנושא.

  8. לוחצים על פריסה.

ביצוע תהליך העבודה

אחרי שפורסים את תהליך העבודה בהצלחה, אפשר להריץ אותו בפעם הראשונה. אחרי פריסת תהליך העבודה, תועברו לדף פרטי תהליך העבודה.

  1. בדף פרטי תהליך העבודה, לוחצים על הפעלה.

  2. בדף Execute workflow (הפעלת תהליך עבודה), לוחצים על Execute (הפעלה).

  3. בחלונית פלט מוצגות התוצאות של תהליך העבודה.

הפעלתם את זרימת העבודה הראשונה שלכם.

הסרת המשאבים

כדי לא לצבור חיובים לחשבון Google Cloud על המשאבים שבהם השתמשתם בדף הזה, פועלים לפי השלבים הבאים:

  1. נכנסים לדף Workflows במסוף Google Cloud :

    כניסה לדף Workflows

  2. ברשימת תהליכי העבודה, לוחצים על תהליך עבודה כדי לעבור לדף פרטי תהליך העבודה.

  3. לוחצים על מחיקה.

  4. מקלידים את השם של תהליך העבודה ולוחצים על אישור.

המאמרים הבאים