klesh commented on code in PR #6154:
URL: 
https://github.com/apache/incubator-devlake/pull/6154#discussion_r1349631293


##########
backend/plugins/opsgenie/tasks/incidents_collector.go:
##########
@@ -0,0 +1,89 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package tasks
+
+import (
+       "encoding/json"
+       "fmt"
+       "net/http"
+       "net/url"
+
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/plugin"
+       "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+)
+
+const RAW_INCIDENTS_TABLE = "opsgenie_incidents"
+
+var _ plugin.SubTaskEntryPoint = CollectIncidents
+
+type (
+       collectedIncidents struct {
+               TotalCount int               `json:"totalCount"`
+               Data       []json.RawMessage `json:"data"`
+       }
+)
+
+var CollectIncidentsMeta = plugin.SubTaskMeta{
+       Name:             "collectIncidents",
+       EntryPoint:       CollectIncidents,
+       EnabledByDefault: true,
+       Description:      "Collect Opsgenie incidents",
+       DomainTypes:      []string{plugin.DOMAIN_TYPE_TICKET},
+}
+
+func CollectIncidents(taskCtx plugin.SubTaskContext) errors.Error {
+       data := taskCtx.GetData().(*OpsgenieTaskData)
+
+       collectorWithState, err := 
api.NewStatefulApiCollector(api.RawDataSubTaskArgs{
+               Ctx:     taskCtx,
+               Options: data.Options,
+               Table:   RAW_INCIDENTS_TABLE,
+       })
+       if err != nil {
+               return err
+       }
+
+       err = collectorWithState.InitCollector(api.ApiCollectorArgs{

Review Comment:
   I think @keon94 is proposing to use another `helper`
   
https://github.com/apache/incubator-devlake/blob/62a1e93a2dab358af6b0e2b1eecd21ad70208941/backend/plugins/pagerduty/tasks/incidents_collector.go#L69C24-L69C67
   and I believe he is right unless the Opsgenie API supports filtering by 
`updatedAt`



##########
backend/plugins/opsgenie/tasks/incidents_collector.go:
##########
@@ -45,45 +50,54 @@ var CollectIncidentsMeta = plugin.SubTaskMeta{
        EnabledByDefault: true,
        Description:      "Collect Opsgenie incidents",
        DomainTypes:      []string{plugin.DOMAIN_TYPE_TICKET},
+       ProductTables:    []string{RAW_INCIDENTS_TABLE},
 }
 
 func CollectIncidents(taskCtx plugin.SubTaskContext) errors.Error {
        data := taskCtx.GetData().(*OpsgenieTaskData)
-
-       collectorWithState, err := 
api.NewStatefulApiCollector(api.RawDataSubTaskArgs{
+       args := api.RawDataSubTaskArgs{
                Ctx:     taskCtx,
                Options: data.Options,
                Table:   RAW_INCIDENTS_TABLE,
-       })
-       if err != nil {
-               return err
        }
-
-       err = collectorWithState.InitCollector(api.ApiCollectorArgs{
-               ApiClient:   data.Client,
-               PageSize:    100,
-               UrlTemplate: "v1/incidents",
-               Query: func(reqData *api.RequestData) (url.Values, 
errors.Error) {
-                       query := url.Values{}
-
-                       query.Set("query", fmt.Sprintf("impactedServices:%s", 
data.Options.ServiceId))
-                       query.Set("sort", "createdAt")
-                       query.Set("order", "desc")
-                       query.Set("limit", fmt.Sprintf("%d", 
reqData.Pager.Size))
-                       query.Set("offset", fmt.Sprintf("%d", 
reqData.Pager.Skip))
-                       return query, nil
-               },
-               ResponseParser: func(res *http.Response) ([]json.RawMessage, 
errors.Error) {
-                       rawResult := collectedIncidents{}
-                       err := api.UnmarshalResponse(res, &rawResult)
-
-                       return rawResult.Data, err
+       collector, err := 
api.NewStatefulApiCollectorForFinalizableEntity(api.FinalizableApiCollectorArgs{
+               RawDataSubTaskArgs: args,
+               ApiClient:          data.Client,
+               TimeAfter:          data.TimeAfter,
+               CollectNewRecordsByList: api.FinalizableApiCollectorListArgs{
+                       PageSize:    100,
+                       Concurrency: 10,
+                       FinalizableApiCollectorCommonArgs: 
api.FinalizableApiCollectorCommonArgs{
+                               UrlTemplate: "v1/incidents",
+                               Query: func(reqData *api.RequestData, 
createdAfter *time.Time) (url.Values, errors.Error) {
+                                       query := url.Values{}
+
+                                       query.Set("query", 
fmt.Sprintf("impactedServices:%s", data.Options.ServiceId))

Review Comment:
   According to the doc, I agree with @keon94 and we should be using the same 
`collection helper` as `pagerduty` plugin.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to