Scheduled Task App compoent


(mortoza) #1

Hi @stukalov am trying your app component that you posted in your blog but can’t add it. Here is what I did:

  1. added in build.grade
    maven {
    url “https://dl.bintray.com/aleksey-stukalov/cuba-components
    }
  1. tried to add as custom component as follows:
    image

But can’t add. thanks for your help.


(Aleksey Stukalov) #3

Hi @mortozakhan,

Just published a new 0.3 version. Please, use it instead of the 0.1 one, so coordinates will be: com.acc.cuba.tools.scheduler:scheduler-global:0.3. Note that this version is compatible with 6.7.4+ versions.

Regards,
Aleksey


(mortoza) #4

Hi Alexsey
Thank you for the new version, it works.
Now I am trying to use it and I have questions.
It seems the approach is to make it simple by using annotations which is great!

I have a method in a service that converts all the open goods issue to invoice. How can I automate this through scheduled tasks? What will be the steps, pls correct the following:

  1. add your app as App Component in my application
  2. Annotate with @ScheduledBeanMethod

@ScheduledBeanMethod(
code = “test-fixed-delay-scheduler”,
isSingleton = false,
fixedDelay = @FixedDelay(period = 5000, startDate = “01/01/2000 00:00:00”),
methodParams = {
@MethodParam(name = “a”, value = “a-value-1”),
@MethodParam(name = “b”, value = “b-value-1”),
@MethodParam(name = “code”, value = “test-fixed-delay-scheduler”)
}
)

where do I call my method in myService that converts goods issues to invoices? say that method name is myService.convertGoodsIssueToInvoice and parameter used is company

Thanks in advance.


(Aleksey Stukalov) #5

Hi @mortozakhan,

I’m not quite sure what exactly you want to achieve. From what I understand you want to generate an invoice report periodically and somehow access them later. To do so I would create an Invoice entity with a reference to a file descriptor. In an annotated scheduled method of a bean (find an example of using the annotation in tests) I would run report generation programmatically (see this sample which shows how it can be achieved) and then save the resulting file descriptor to the Invoice entity that you can use later in your business logic.

Hope it helps.

Regards,
Aleksey


(mortoza) #6

Hi Aleksey
Thanks for your reply, sorry being late to revert to you.
I am trying to use your app component but need some help. In order to simplify, I have created a sample app as described below and attached.

  1. There are two Entities - AssetProfile and Depreciation.
    I have also prepared a service to calculate depreciation and update both AssetProfile and Depreciation Entities.

  2. I have added your app component with this app (schedulerDemo). When you run the app and display asset profile, 3 assets will be added to the database for testing.

  3. What I want to achieve is, I want to schedule this depreciation calculation (running the service called: calculateDepreciation) daily at 12:30 AM.

Where and How should i use the @annotations in order to execute the service (calculateDepreciation) every nightly, weekly, monthly etc.?

schedulerDemo.zip (87.8 KB)

I look forward for your inputs.


(Aleksey Stukalov) #7

Hi @mortozakhan,

Could you please clarify what exactly is not clear from my previous reply? Did you take a look into the sample I referenced?

Regards,
Aleksey


(mortoza) #8

Hi Aleksey
Of course I have looked into the sample you referenced. Sample refers to programmatic generation of invoice report in PDF format using order parameter which is a very good example, it is very useful. I also have looked into the other reference (tests) that uses the @ScheduledBeanMethod. My question is more related to use of @ScheduledBeanMethod annotation but is not sure how to schedule a service method e.g. generating a payroll calculation, calculating depreciation of assets etc. Sorry that I may have been missing something but any help will be appreciated. I have send you the sample app for a more clear understanding of what I am looking for using your app component that looks promising.


(Aleksey Stukalov) #9

Hi @mortozakhan,

Just add the following annotation to make it works every noon:

...  
@ScheduledBeanMethod(
        code = "AssetServiceBean#calculateDepreciation",
        isSingleton = true,
        isActive = true,
        cron = @Cron(expression = "0 0 12 * * ?")
)
public void calculateDepreciation(){
   ...
} 

Also make sure that you have enabled scheduling by adding the cuba.schedulingActive = true line into the app.properties file in the core module.

Regards,
Aleksey


(mortoza) #10

Thank you Aleksey. I am trying it…
For the frequency to schedule the job e.g. weekly, monthly, yearly etc. what is parameters to be used?


(Aleksey Stukalov) #11

This is a cron expression, see more info here. This is a common thing, not CUBA related, so, just google it.


(mortoza) #12

Hi Aleksey @stukalov
This is a nice add-on that I am using and believe to be useful to many others. Do you have any plan to put this in the Market Place and maintain as current?


(Aleksey Stukalov) #13

Hi @mortozakhan,

I haven’t had this plan, as this component was developed for my personal projects. I’m happy to hear that you find it useful and if this subject will be widely supported I will send a request to publish it.

As for maintaining it - there is no problem to use it with any version of platform higher than 6.7. You are welcome to update it to 6.9 version and contribute.

Regards,
Aleksey


(mortoza) #14

Hi Aleksey
I think this will be a good app Component in the marketplace.
Ok, I can upgrade (compile in 6.9), should i send you the zip file?


(Aleksey Stukalov) #15

@mortozakhan,

Just fork it, update, and send pull request - would appreciate it.

Regards,
Aleksey