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

Run task delay for an hour in UTC mode #36

Closed
rts-gordon opened this issue Feb 8, 2022 · 6 comments
Closed

Run task delay for an hour in UTC mode #36

rts-gordon opened this issue Feb 8, 2022 · 6 comments

Comments

@rts-gordon
Copy link

Describe the bug
Run task delay for an hour in UTC mode

To Reproduce
There are three task in a DelayTimerBuilder, two tasks run in time, but the first one task run delay for an hour.

code:

        //delay_timer
        let delay_timer = DelayTimerBuilder::default()
            .tokio_runtime_by_default()
            .build();

        //Task1: renew symbols
        let body_renew_sym = create_async_fn_tokio_body!({
            if let Err(err) = base::init_symbol_list().await {
                error!("Initial symbols list error: {}", err);
            }
        });
        let task_builder_renew_sym = TaskBuilder::default()
            .set_frequency_repeated_by_cron_str(&dotenv::var("50 00 22 * * * *").unwrap())
            .set_schedule_iterator_time_zone(ScheduleIteratorTimeZone::Utc)
            .set_task_id(1)
            //.set_maximum_running_time(600)
            .spawn(body_renew_sym)?;
        delay_timer.add_task(task_builder_renew_sym)?;

        //Task2: calculate D1 data and save to D1.csv file
        let body_d1 = create_async_fn_tokio_body!({
            csv::calculate_all_d1_ohlc();
        });
        let task_builder_d1 = TaskBuilder::default()
            .set_frequency_repeated_by_cron_str(&dotenv::var("0 10 22 * * Monday,Tuesday,Wednesday,Thursday,Friday *").unwrap())
            .set_schedule_iterator_time_zone(ScheduleIteratorTimeZone::Utc)
            .set_task_id(2)
            .spawn(body_d1)?;
        delay_timer.add_task(task_builder_d1)?;

        //Task4: calculate historical ohlc
        let body_ohlc = create_async_fn_tokio_body!((db_pool){
            if let Err(err) = csv::cron_sync_ohlc_to_db(&db_pool_ref).await {
                error!("Cron sync ohlc to database error: {}", err);
            }
        });
        let task_builder_ohlc = TaskBuilder::default()
            .set_frequency_repeated_by_cron_str(&dotenv::var("0 20 22 * * Monday,Tuesday,Wednesday,Thursday,Friday *").unwrap())
            .set_schedule_iterator_time_zone(ScheduleIteratorTimeZone::Utc)
            .set_task_id(4)
            .spawn(body_ohlc)?;
        delay_timer.add_task(task_builder_ohlc)?;

Info logs:

2022-02-08T01:00:51.690533645+02:00 INFO sync::base::base - Get active symbol from http api, len= 870

2022-02-08T00:20:00.484920457+02:00 INFO sync::csv::csv_file - Begin to sync cron calculate ohlc data and send to database...

2022-02-08T00:10:00.484385080+02:00 INFO sync::csv::csv_file - Calculate D1 file from tick data file
@BinChengZhao
Copy link
Owner

Your question is on my mind, and I'm using my rest time to look at it,

I have a point of confusion
dotenv::var("0 10 22 * * Monday,Tuesday,Wednesday,Thursday,Friday *")

I'm not quite sure why you're passing a cron string for the var function, which is supposed to pass a key (https://docs.rs/dotenv/0.15.0/dotenv/fn.var.html), are you sure the value you're getting through that function is reasonable and as expected for a cron-str?

@rts-gordon
Copy link
Author

Hi @BinChengZhao
Sorry for that, it is just a example. Actually, there are some cron string define in a .env file, the code is:

let task_builder_renew_sym = TaskBuilder::default()
            .set_frequency_repeated_by_cron_str(&dotenv::var("RENEW_SYMBOLS_CRON").unwrap())
            .set_schedule_iterator_time_zone(ScheduleIteratorTimeZone::Utc)
            .set_task_id(1)
            //.set_maximum_running_time(600)
            .spawn(body_renew_sym)?;

.env file

RENEW_SYMBOLS_CRON = "50 00 22 * * * *"

@BinChengZhao
Copy link
Owner

Hi @BinChengZhao Sorry for that, it is just a example. Actually, there are some cron string define in a .env file, the code is:

let task_builder_renew_sym = TaskBuilder::default()
            .set_frequency_repeated_by_cron_str(&dotenv::var("RENEW_SYMBOLS_CRON").unwrap())
            .set_schedule_iterator_time_zone(ScheduleIteratorTimeZone::Utc)
            .set_task_id(1)
            //.set_maximum_running_time(600)
            .spawn(body_renew_sym)?;

.env file

RENEW_SYMBOLS_CRON = "50 00 22 * * * *"

My friend, I have received your reply. I have realized the minimum recurrence case through your logic code and observed the situation in the last 48 hours, which is still normal at present.

I will continue to pay attention to the information on the server, a total of 7 days of sampling, to give you a feedback result.

BinChengZhao added a commit that referenced this issue Feb 21, 2022
@BinChengZhao
Copy link
Owner

Hi @Chcp

I have found the root cause of the problem and implemented the fix, the unit test has passed now, you can try it in your test environment.

You can use the latest version:
delay_timer = "0.11.1"

@rts-gordon
Copy link
Author

Thanks, it is work now.

@BinChengZhao
Copy link
Owner

Thanks, it is work now.
Thanks, you too, if you have any problems, please just open the issue and I will fix it carefully.

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

No branches or pull requests

2 participants