@@ -431,15 +431,11 @@ namespace small {
431
431
}
432
432
433
433
//
434
- // inner thread function for executing items (should return if there are more items) (called from thread_pool)
434
+ // get jobs to execute based on the group
435
435
//
436
- friend small::jobsimpl::jobs_engine_thread_pool<JobsGroupT, ThisJobsEngine>;
437
-
438
- inline EnumLock do_action (const JobsGroupT &jobs_group, bool *has_items)
436
+ inline EnumLock get_group_jobs (const JobsGroupT &jobs_group, std::vector<JobsID> &vec_ids, typename JobsConfig::ConfigProcessing &group_config)
439
437
{
440
- *has_items = false ;
441
-
442
- // get bulk_count
438
+ // get bulk_count property
443
439
auto it_cfg_grp = m_config.m_groups .find (jobs_group);
444
440
if (it_cfg_grp == m_config.m_groups .end ()) {
445
441
return small::EnumLock::kExit ;
@@ -448,7 +444,6 @@ namespace small {
448
444
int bulk_count = std::max (it_cfg_grp->second .m_bulk_count , 1 );
449
445
450
446
// delay request
451
- typename JobsConfig::ConfigProcessing group_config{};
452
447
group_config.m_delay_next_request = it_cfg_grp->second .m_delay_next_request ;
453
448
454
449
// get items to process
@@ -457,40 +452,53 @@ namespace small {
457
452
return small::EnumLock::kExit ;
458
453
}
459
454
460
- std::vector<JobsID> vec_ids;
461
- auto ret = q->wait_pop_front_for (std::chrono::nanoseconds (0 ), vec_ids, bulk_count);
455
+ auto ret = q->wait_pop_front_for (std::chrono::nanoseconds (0 ), vec_ids, bulk_count);
456
+ return ret;
457
+ }
458
+
459
+ //
460
+ // inner thread function for executing items (should return if there are more items) (called from thread_pool)
461
+ //
462
+ friend small::jobsimpl::jobs_engine_thread_pool<JobsGroupT, ThisJobsEngine>;
463
+
464
+ inline EnumLock do_action (const JobsGroupT &jobs_group, std::chrono::milliseconds &delay_next_request)
465
+ {
466
+ // get jobs for the group
467
+ typename JobsConfig::ConfigProcessing group_config{}; // for delay request
468
+ std::vector<JobsID> vec_ids;
469
+
470
+ auto ret = get_group_jobs (jobs_group, vec_ids, group_config);
462
471
if (ret != small::EnumLock::kElement ) {
463
472
return ret;
464
473
}
465
474
466
- *has_items = true ;
467
-
468
475
// split by type
469
- std::unordered_map<JobsTypeT, std::vector<std::shared_ptr<JobsItem>>> elems_by_type ;
476
+ std::unordered_map<JobsTypeT, std::vector<std::shared_ptr<JobsItem>>> jobs_in_progress_by_type ;
470
477
{
471
478
// get jobs
472
- std::vector<std::shared_ptr<JobsItem>> jobs_items = m_queue .jobs_get (vec_ids);
479
+ std::vector<std::shared_ptr<JobsItem>> jobs_items = queue () .jobs_get (vec_ids);
473
480
for (auto &jobs_item : jobs_items) {
474
- elems_by_type [jobs_item->m_type ].reserve (jobs_items.size ());
481
+ jobs_in_progress_by_type [jobs_item->m_type ].reserve (jobs_items.size ());
475
482
476
483
// mark the item as in progress
477
484
jobs_item->set_state_inprogress ();
478
- // execute if it is still in progress (may be moved to higher states due to external factors like cancel, timeout, finish early due to other job, etc)
485
+ // execute if it is still in progress
486
+ // (may be moved to higher states due to external factors like cancel, timeout, finish early due to other job, etc)
479
487
if (jobs_item->is_state_inprogress ()) {
480
- elems_by_type [jobs_item->m_type ].push_back (jobs_item);
488
+ jobs_in_progress_by_type [jobs_item->m_type ].push_back (jobs_item);
481
489
}
482
490
}
483
491
}
484
492
485
493
// process specific job by type
486
- for (auto &[jobs_type, jobs] : elems_by_type ) {
494
+ for (auto &[jobs_type, jobs] : jobs_in_progress_by_type ) {
487
495
auto it_cfg_type = m_config.m_types .find (jobs_type);
488
496
if (it_cfg_type == m_config.m_types .end ()) {
489
497
continue ;
490
498
}
491
499
492
500
// process specific jobs by type
493
- typename JobsConfig::ConfigProcessing type_config;
501
+ typename JobsConfig::ConfigProcessing type_config{} ;
494
502
it_cfg_type->second .m_function_processing (jobs, type_config);
495
503
496
504
// get the max for config
@@ -503,13 +511,13 @@ namespace small {
503
511
}
504
512
505
513
// mark the item as in wait for children of finished
506
- // if in callback the state is set to failed, cancelled or timeout setting to finish wont succeed because if less value than those
514
+ // if in callback the state is set to failed, cancelled or timeout
515
+ // setting to finish wont succeed because is less value than those
507
516
jobs_waitforchildren (jobs);
508
517
}
509
518
510
- // TODO group_config.m_delay_next_request
511
- // TODO for delay after requests use worker_thread delay item -> check if has_items should be set properly
512
- // TODO if delay is set set has_items to true to force the sleep, but also a last time sleep so if there too much time and are no items dont continue
519
+ // delay request
520
+ delay_next_request = group_config.m_delay_next_request .value_or (std::chrono::milliseconds (0 ));
513
521
514
522
return ret;
515
523
}
0 commit comments