project-flogo / core

Flogo Core is the core flogo library used create and extend Flogo applications.
BSD 3-Clause "New" or "Revised" License
109 stars 55 forks source link

Trigger and Activity Close method in interface #201

Closed reidlai closed 4 years ago

reidlai commented 4 years ago

Current behavior:

No Close method in Activity or Trigger interface. Developer has no way to clean up connection of backend service before microservice is terminated.

Expected behavior:

What is the motivation / use case for changing the behavior?

Most of backend service is expected golang developer to implement Close method and use defer statement to make sure all connections will be closed before end of service.

Additional information you deem important (e.g. I need this tomorrow):

lixingwang commented 4 years ago

@reidlai We do have a cleanup mechanism in our activity and trigger.

  1. Trigger Stop() method which will be called when engine terminates
  2. Activity Cleanup() method will be called when the engine terminates.

Example:

// Stop implements util.Managed.Stop
func (t *Trigger) Stop() error {
    return t.server.Stop()
}
func (a *Activity) Cleanup() error {
    if a.stmt != nil {
        err := a.stmt.Close()
        log.RootLogger().Warnf("error cleaning up SQL Query activity: %v", err)
    }

    log.RootLogger().Tracef("cleaning up SQL Query activity")

    return a.db.Close()
}
lixingwang commented 4 years ago

@reidlai We also have connection management which manages the connections per engine. Take an example here: https://github.com/project-flogo/datastore-contrib/blob/master/mongodb/connection/connection.go

skothari-tibco commented 4 years ago

Closing this one.

reidlai commented 4 years ago

@reidlai We do have a cleanup mechanism in our activity and trigger.

  1. Trigger Stop() method which will be called when engine terminates
  2. Activity Cleanup() method will be called when the engine terminates.

Example:

// Stop implements util.Managed.Stop
func (t *Trigger) Stop() error {
  return t.server.Stop()
}
func (a *Activity) Cleanup() error {
  if a.stmt != nil {
      err := a.stmt.Close()
      log.RootLogger().Warnf("error cleaning up SQL Query activity: %v", err)
  }

  log.RootLogger().Tracef("cleaning up SQL Query activity")

  return a.db.Close()
}

Thanks a lot... i don't know there is Stop method of trigger. Thanks.