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

Set time from config service to decorator #24

Open
grigori-gru opened this issue May 31, 2019 · 7 comments
Open

Set time from config service to decorator #24

grigori-gru opened this issue May 31, 2019 · 7 comments
Labels
question Further information is requested

Comments

@grigori-gru
Copy link

Is it possible to set time to decorator from configService which I use as dependency in my job module, for example this way:

export class JobService extends NestSchedule {
    private readonly logger = new Logger(JobService.name);

    constructor(
        private readonly configSerice: ConfigService,
    ) {
        super();
    }

    @Cron('10 0 * * *')
    async saveVoteResult2Db() {
        this.logger.log('Starting daily cronjob!!!');
    }

    @Interval(this.configSerice.syncInterval)
    async saveToRedis() {
        this.logger.debug('Data is synced with redis');
    }
@issue-label-bot
Copy link

Issue Label Bot is not confident enough to auto-label this issue. See dashboard for more details.

@miaowing
Copy link
Owner

miaowing commented Jun 4, 2019

The this context is different between decorator and function, not use this in decorator

@miaowing miaowing added the question Further information is requested label Jun 4, 2019
@grigori-gru
Copy link
Author

Thanks, but how should I use it in this case?

@grigori-gru
Copy link
Author

That's all about @Cron params of course. For example if I want to test how my schedule job works using less period, I can't do it.

@hiteshjoshi1
Copy link

I have the same question, I want to set enable: true/false based on the environment parameters.

@Nosfistis
Copy link

Environment parameters can be used directly, since they are available already.
However it's not possible to use a service in decorators. I ended up creating tasks manually. However, there are no helper functions for distributed locking there.

@trexguo
Copy link

trexguo commented Nov 29, 2019

I have to create static methods and properties in ConfigService, then we can access them.

@Timeout(1000, {
    key: ConfigService.getString('ABC_KEY'),
    enable: ConfigService.getBoolean('ABC_ENABLE'),
  })

Not sure if this is the best practice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants