cap-js-community / event-queue

An event queue that enables secure multi-tenant enabled transactional processing of asynchronous events, featuring instant event processing with Redis Pub/Sub and load distribution across all application instances.
https://cap-js-community.github.io/event-queue/
Apache License 2.0
11 stars 1 forks source link

Rework activate cds-plugin #110

Closed soccermax closed 5 months ago

soccermax commented 5 months ago

fix https://github.com/cap-js-community/event-queue/issues/106

soccermax commented 5 months ago

Why using now activate?

do be in sync with the feature-toggles. Returning the activate function is the latest and greatest for plugins to execute the activate coding only for active plugins

oklemenz2 commented 5 months ago

Why using now activate?

do be in sync with the feature-toggles. Returning the activate function is the latest and greatest for plugins to execute the activate coding only for active plugins

How can plugins be deactivated?

soccermax commented 5 months ago

Why using now activate?

do be in sync with the feature-toggles. Returning the activate function is the latest and greatest for plugins to execute the activate coding only for active plugins

How can plugins be deactivated?

Why using now activate?

do be in sync with the feature-toggles. Returning the activate function is the latest and greatest for plugins to execute the activate coding only for active plugins

How can plugins be deactivated?

I couldn't find that part anymore. I'll check tmr. But returning an promise is the desired way described by CAP:

/**
 * Load and activate cds-plugins from project's package dependencies.
 * Used in and made available through cds.plugins.
 */
exports.activate = async function () {
  const DEBUG = cds.debug ('plugins', {label:'cds'})
  DEBUG && console.time ('[cds] - loaded plugins in')
  const { plugins } = cds.env, { local } = cds.utils
  await Promise.all (Object.entries(plugins) .map (async ([ plugin, conf ]) => {
    DEBUG?.(`loading plugin ${plugin}:`, { impl: local(conf.impl) })
    // TODO: support ESM plugins. But see cap/cds/pull/1838#issuecomment-1177200 !
    const p = require (conf.impl)
    if(p.activate) {
      cds.log('plugins').warn(`WARNING: \n
  Returning an 'activate' function is deprecated and won't be
  supported in future releases. → Please return a Promise with 'module.exports' instead.
  `)
      await p.activate(conf)
    }
    return p
  }))
  DEBUG && console.timeEnd ('[cds] - loaded plugins in')
  return plugins
}
oklemenz2 commented 5 months ago

But returning an promise is the desired way described by CAP:

Exactly, I guess activate function is legacy, and only a promise shall be returned or nothing if not necessary to have something async...