Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to find a BatchJob strategy with the type #9089

Open
grandpaSam opened this issue Sep 10, 2024 · 1 comment
Open

Unable to find a BatchJob strategy with the type #9089

grandpaSam opened this issue Sep 10, 2024 · 1 comment

Comments

@grandpaSam
Copy link

Custom batch job starts with an error "Unable to find a BatchJob strategy with the type X" in the notifications of the admin page. I can tell through logging that the constructor of my batch job runs but the preProcessBatchJob and the processJob functions never get called.

System information

Medusa version (including plugins): 1.20.9
Node.js version: 16.13.1
Database: postgres
Operating system: ubuntu
Browser (if relevant): chrome

Steps to reproduce the behavior

  1. Use batchjob below with file key in the request using the medusa admin UI

Expected behavior

Batch job should preprocess and run

Code snippets

import { 
    AbstractBatchJobStrategy, 
    BatchJobService,
    CustomerService,
    IFileService,
  } from "@medusajs/medusa"
import * as csv from "csv-parser"
import { EntityManager } from "typeorm"
import { Logger } from "@medusajs/medusa";
  
  class VolusionCustomerImport extends AbstractBatchJobStrategy {
    static identifier = "volusion-customer-import-strategy";
    static batchType = "volusion-customer-import";
    protected batchJobService_: BatchJobService;
    protected customerService_: CustomerService;
    protected fileService_: IFileService
    protected manager_: EntityManager;
    protected transactionManager_: EntityManager;
    protected logger_: Logger

    constructor({customerService,
      batchJobService,
      fileService,
      logger,
    }) {
      super(arguments[0]);
      this.customerService_ = customerService;
      this.batchJobService_ = batchJobService;
      this.fileService_ = fileService;
      this.logger_ = logger
    }
  
    async preProcessBatchJob(batchJobId: string): Promise<void> {
      return await this.atomicPhase_(
          async (transactionManager) => {
            const batchJob = (await this.batchJobService_
              .withTransaction(transactionManager)
              .retrieve(batchJobId))
            const fileKey: string = batchJob.context.fileKey as string;
            const stream = await this.fileService_.getDownloadStream({fileKey:fileKey})
            const count = await new Promise<number>((resolve, reject) => {
              const customerTransactionTx = this.customerService_.withTransaction(transactionManager);
              let count = 0;
              stream.pipe(csv.default())
              stream.on('data', (data) => {
                count++;
              })
              stream.on('end', () => {
                this.logger_.info("" + count + "entries");
                resolve(count);
              })
            })
            await this.batchJobService_.withTransaction(transactionManager)
            .update(batchJobId, {result:
              {count: count,
                advancement_count: 0,
              }
            })
        }
      )
    }

    async processJob(batchJobId: string): Promise<void> {
      return await this.atomicPhase_(
        async (transactionManager) => {
          const job = await this.batchJobService_.withTransaction(transactionManager).retrieve(batchJobId);
          await this.batchJobService_
          .withTransaction(transactionManager)
          .update(batchJobId, {
            result: {
              advancement_count: job.result.count
            },
          })
        }
      )
    }

    async buildTemplate(): Promise<string> {
      return ""
    }
  }
  
  export default VolusionCustomerImport
@voronovmaksim
Copy link

I have the same issue on the same enviroment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants