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


##########
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:
   Ok. Here's what I suggest then. Change the collection code back to how you 
had it first (full collection with no state), and put the state based logic in 
another branch. Then we'll merge this branch without that logic (please address 
the failing github checks first). 
   Go ahead and create another issue and call it "Support incremental 
collection for Opsengie plugin" and link that branch you created to it.



-- 
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