Jump to content
ussrlongbow

[RELEASE] Cron manager for Arma 3 - less loops, more performance

Recommended Posts

Hello,
this script has been refactored and proven for 1 year already
 
Current version: 1.0
 
What is it?
 
This is a cron manager for Arma 3. It is a similar for crontab in Linux or Task Scheduler in Windows.
It allows you to execute code at a scheduled time, repetitive or not.
Script will help to avoid endless loops and make performance optimized missions with greater flexibility
in terms of managing your code execution. This script is designed for server-side execution, but also works in SP
 
What's inside?
Script contains of 4 functions:
RWT_fnc_cronInit - initializes cron manager, executed on postIinit
RWT_fnc_cronJobAdd - adds jobs to cron manager
RWT_fnc_cronJobRemove - remove job from cron manager
RWT_fnc_cronJobRun - function that runs the code, when its time comes
 
Example use case?

  •  
  • Make an explosion in 30 minutes
  • Periodically run garbage clean up code, say every 2 minutes
  • Any other usecase which requires higher time lags (minutes, hours)

How to start using it?
Script is packaged according to guidelines of Arma 3 Mission Skeleton, so if you are using it,
just download it to your mission's addons folder and run build script.
If you are more experienced mission maker or scripter - grab the source from github.
 
To add a task:

[{hint str time},[],0,20,0] call RWT_fnc_cronJobAdd;
// will display time every 20 seconds

Please read the comments and description to functions

 

Source - https://github.com/ussrlongbow/rwt_cron

Package - https://github.com/ussrlongbow/rwt_cron/releases/download/v1.0/rwt_cron_a3ms.zip

Edited by ussrlongbow
  • Like 10

Share this post


Link to post
Share on other sites

Script has been updated to version 1.0

Source moved to github, example mission will come a bit later.

Share this post


Link to post
Share on other sites

I think using your work for the development of my framework. I'm creating a reference implementation and in this I use a cronjob using infinite loop, which is not great.

 

Framework implementation

https://github.com/RedBelette/TGV_MissionFramework_Template

Reference implementation

https://github.com/RedBelette/RED_co9_op_anger_of_the_west.Kunduz 

 

To be honest, I am a little surprised that there is no more information about the community's opinion about your work. I would like to know if this tool has been popularized or not? I will certainly have some questions also during the implementation, is this subject always followed?

Thanks for reading me.

Share this post


Link to post
Share on other sites

@RedBelette

You are free and welcome to use this script according to MIT license terms. I did not work on marketing this script, as it was developed for internal projects, so I am not sure how widely it was adopted. If you have any question or suggestion you may open an issue on github or drop a PM to me - I will try to help with what I can.

 

Share this post


Link to post
Share on other sites

hi :)

 

just read your code by curiosity, dont know the real interest of the functions, but it should if you write it

 

two points :)

 

1- you can write in a oriented object way

2- not sure call compile format is the best way, but i just read it quickly

 

  • Like 1

Share this post


Link to post
Share on other sites
22 minutes ago, code34 said:

hi :)

 

just read your code by curiosity, dont know the real interest of the functions, but it should if you write it

 

two points :)

 

1- you can write in a oriented object way

2- not sure call compile format is the best way, but i just read it quickly

 

hey code34!

 

just being curious myself - by OO way, what do you mean exactly? using your own abstractions set to make SQL a OO scripting language? do you have any examples? :)

I remember there was someone that made a OO version of SQL. wasn't that guy... you, by any chance?

  • Like 1

Share this post


Link to post
Share on other sites

i only wrote a OO mapper on the extdb sql driver :)

 

but you have several way to do it, like :

 

 

  • Like 1

Share this post


Link to post
Share on other sites
On 9/29/2017 at 0:42 PM, code34 said:

hi :)

 

just read your code by curiosity, dont know the real interest of the functions, but it should if you write it

 

two points :)

 

1- you can write in a oriented object way

2- not sure call compile format is the best way, but i just read it quickly

 

1. If I manage to update this code, I would do it in functional way :)

2. I know, I should use missionnamespace set/get variable, but it is not very critical at the moment.

 

Anyway you are welcome to offer a merge request with your enhancements ;)

Share this post


Link to post
Share on other sites

hi

 

just send the merge request to fix call compile. I cant test it cause i dont have test mission for this :)

Share this post


Link to post
Share on other sites

@ussrlongbow

For the moment, I got away with a trigger. Do you think this solution is equivalent? Where do I run into performance concerns?

https://github.com/RedBelette/TGV_MissionFramework_Template/blob/master/library/function/server/cronjob/TGV_fnc_cronjob.sqf

 

@code34

It seems to me that the object oriented is not native in SQF, right?

Share this post


Link to post
Share on other sites
1 hour ago, RedBelette said:

@ussrlongbow

For the moment, I got away with a trigger. Do you think this solution is equivalent? Where do I run into performance concerns?

https://github.com/RedBelette/TGV_MissionFramework_Template/blob/master/library/function/server/cronjob/TGV_fnc_cronjob.sqf

 

@code34

It seems to me that the object oriented is not native in SQF, right?

 

yes, that's right. OOP uses the native macro syntax of arma engine. The code is transformed at the pre compilation from OO similar langage to native sqf before the execution of the SQF.

Share this post


Link to post
Share on other sites
7 hours ago, RedBelette said:

@ussrlongbow

For the moment, I got away with a trigger. Do you think this solution is equivalent? Where do I run into performance concerns?

https://github.com/RedBelette/TGV_MissionFramework_Template/blob/master/library/function/server/cronjob/TGV_fnc_cronjob.sqf

It does not look like my approach, at least I see no other files under cronjob, so I am not sure where are you going to maintain the list of jobs scheduled.

 

Wehn I say about performance I mean that cronjob provides a good performance gain vs say 1000 loops in background

 

1000 jobs in cron will cost just one trigger.

Share this post


Link to post
Share on other sites
22 hours ago, code34 said:

hi

 

just send the merge request to fix call compile. I cant test it cause i dont have test mission for this :)

Thanks!

 

The change is pretty straightforward, merged

Share this post


Link to post
Share on other sites

Indeed, I miss a register of tasks to be able to stop them, restart, kill them etc ... I will consider if this is necessary for the complexity of our missions.
I also understand the need to run on a single trigger.

Thank you for your answer.

Share this post


Link to post
Share on other sites

I have taken into account these remarks concerning the maintenance of the list of jobs. I used cod24's hashmap to manage the job list. This evolution does not take into account the execution of all jobs in a single thread. For now, I do not use your tool yet, I will look for the built-in framework in case we have a lot of thread to use. (As a backup solution in short)

You can find the implementation in this directory:
https://github.com/RedBelette/TGV_MissionFramework_Template/tree/master/library/function/server/cronjob

(For now, the following two functions are deprecated TGV_fnc_cronjob.sqf and TGV_fnc_actionTrigger.sqf, old implementation).

The steps of use are:

1. Init of register
2. Creating the repeated action or one shot action (trigger)
3. Adding the action to the register
4. Ability to stop or start action
5. Remove the action from the register

Do you think it's enough to manage performance?

Share this post


Link to post
Share on other sites
On 10/7/2017 at 10:51 AM, RedBelette said:

I have taken into account these remarks concerning the maintenance of the list of jobs. I used cod24's hashmap to manage the job list. This evolution does not take into account the execution of all jobs in a single thread. For now, I do not use your tool yet, I will look for the built-in framework in case we have a lot of thread to use. (As a backup solution in short)

You can find the implementation in this directory:
https://github.com/RedBelette/TGV_MissionFramework_Template/tree/master/library/function/server/cronjob

(For now, the following two functions are deprecated TGV_fnc_cronjob.sqf and TGV_fnc_actionTrigger.sqf, old implementation).

The steps of use are:

1. Init of register
2. Creating the repeated action or one shot action (trigger)
3. Adding the action to the register
4. Ability to stop or start action
5. Remove the action from the register

Do you think it's enough to manage performance?

I would assume it will be near the same, but thorough test is needed.

 

Regarding the hashmap - it might be an option, but I avoided using it, because I store the code and its params as is, and this provides me with some sort of flexibility, for example if I want to change the job options, without re-creating it. Also I had some more ideas about practical usage of cron, but unfortunately I have no time to play with scripts at the moment.

Share this post


Link to post
Share on other sites

Hey guys,

since @ussrlongbow is not present in forum for a year now maybe someone else can answer this.

 

I tried to implement longbows script to my function library but it failed. 

 

For installation I just put the longbow folder into my mission root and added this to the CfgFunctions class of my description.ext:

 

	// longbows cron manager
	#include "longbow\cron\functions.hpp"

but now if I try to use one of his functions in my initServer.sqf it just fails because the function name is not known:

 

initServer.sqf

//add cron job for checking day/night each 30 seconds
[{
  if (sunOrMoon > 0) then 
   {setTimeMultiplier paramTimeMultiplierDay}
  else
   {setTimeMultiplier paramTimeMultiplierNight};
 }, [], 0, 30, 0] call RWT_fnc_cronJobAdd;

error report:

23:58:29 Error in expression <(25 + random 10);}, [], 0, 30, 0] call RWT_fnc_cronJobAdd;_d = [] sp>
23:58:29   Error position: <RWT_fnc_cronJobAdd;_d = [] sp>
23:58:29   Error Nicht definierte Variable in Ausdruck: rwt_fnc_cronjobadd
23:58:29 File E:\win10user\Documents\Arma 3\missions\Operation%20Noname%20-%20Megamission.Malden\initServer.sqf, line 128

 

I really like to get longbows script run because I love the idea of having just one loop run on server for doing all necessary checks.

But I guess it's hard to solve it in the forum alone. therefore I add my mission folder and I would appreciate if someone could dig in and give me a hint 🙂

 

https://www.dropbox.com/s/ejmk6j36xuege41/Operation_Noname.rar?dl=0

pure vanilla mission folder, no mods needed...

Share this post


Link to post
Share on other sites

okay I got it working now. I don't know how it was thought by OP but my Solution is to modify his functions.hpp to this:

 

class RWT
{
	 class cron
	{
		class cronInit
		{
			file = "longbow\cron\functions\fn_cronInit.sqf";
			postInit = 1;
		};
		class cronJobAdd
		{
			file = "longbow\cron\functions\fn_cronJobAdd.sqf";
		};
		class cronJobRemove
		{
			file = "longbow\cron\functions\fn_cronJobRemove.sqf";
		};
		class cronJobRun
		{
			file = "longbow\cron\functions\fn_cronJobRun.sqf";
		};
	};
};

 

EDIT:

to get removing of jobs working I had to change one line in fn_cronJobRemove.sqf from this

private "_id";
_id = _this;
.
.
.

to this:

private "_id";
_id = _this select 0;

.
.
.

 

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×