ReferenceError: collections is not defined

dear all

I was really happy to finally test collections but on the latest docker 2.12.2 I am getting that message

R/T Error occurred at: get data from OCL
R/T 24:   collections.remove('global-almanach-dhis2', { createdAfter: '202401' });
R/T       ^                                                                       
R/T Run complete with status: crash
ReferenceError: ReferenceError: collections is not defined

Any idea why the collection adaptor is not loaded ?

here is my job where I want to pull from OCL (working) to create a collection,

fn(state => {
  state.configuration.baseUrl = state.configuration.hostUrl;
  console.log(state.configuration.baseUrl);
  return state;
});

get(
  "orgs/SwissTPH/sources/ALM-DHIS2/HEAD/mappings",
  {
    limit: 200
  },
  (state) => {
    state.recievedMappingsList = state.data
    state.mappingsList = state.mappingsList || [];
    return state
  }
);
fn((state) => {
 console.log(state.recievedMappingsList[0].from_concept_url.slice(1));
 
  // Remove existing collection entries
  collections.remove('global-almanach-dhis2', { createdAfter: '202401' });
  // load new entry after getting the datatype from the dhis2 concept
  each(state.recievedMappingsList, (state) => {
      return get(state.data.from_concept_url.slice(1), (state) => {
          const type = state.data.datatype || 'unknown'; // Fallback if datatype is undefined
           
          // Append to mappingsList
         collections.set('global-almanach-dhis2', {
            map_type: item.map_type,
            dhis2_uid: item.from_concept_code,
            name: item.to_concept_code.replace(/[. -]/g, "_"),
            datatype: type,
          });
          return state;
        });
 
      })
      return  state
})

Heyy @delcroip ! Thanks for reaching out. We’ll do our best to get back to you as soon as possible. Apologies if we haven’t responded sooner — we’re currently in our annual team meeting and have limited capacity to reply quickly.

Thanks for your patience!

@delcroip for the job code you pasted above, which adaptor and which adaptor version are you using?

@mtuchi @joe does this job need to use the dedicated collections adaptor or common adaptor in order to reference collections functions?

Hi,

I tied with common too same result.

I used that docker compose Vanilla docker compose configuration? - #4 by delcroip

Hey @delcroip, Thank you for your patience, Just a quick question regarding your configuration. Have you setup WORKER_COLLECTIONS_URL ??

If not can you try to update worker in your docker-compose.yml

worker:
    image: 'openfn/ws-worker:latest'
    ...
    expose:
      - '2222'
    environment:
      WORKER_COLLECTIONS_URL: "http://web:4000/collections"

And let me know if the problem still exist ?

1 Like

thanks you it worked perfectly