Raised This Month: $32 Target: $400
 8% 

Solved Stopping/pausing plugin execution & threaded queries


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GPhoenix97
Member
Join Date: Oct 2012
Location: Poland
Old 05-01-2019 , 01:22   Stopping/pausing plugin execution & threaded queries
Reply With Quote #1

Hi there!

Is there any way I can stop plugin from going forward if condition was not met?
Like for example I'm connecting to database using threaded method and inside it's callback I'm just throwing error if database handle is null. But the problem is that plugin is still running and there are plenty of functions querying database throwing errors because connection was not established.
So what would be considered a good practice here? Stop the plugin from execution and if so - how, or just wrap queries in a control block testing whether database handle is not null?

The other question, is there any way plugin can pause it's execution so it can wait for a response from query callback (and yes I know, that neither query or callback doesn't return anything)? That wouldn't be a such a big problem for me because I could just call the query and do a proper handling of things inside of callback, right? But the thing is I wanted to create a native that would query the database and other plugins that would use that native could handle things differently rather than one and only callback.

PS.
Although I said that callback wasn't a big problem it kinda was. I was calling query from a command callback and I had to pass a Replysource data to query and then to query callback and there setting reply source so i could use ReplyToCommand. Was that a good way of dealing with that problem?
__________________

Last edited by GPhoenix97; 05-01-2019 at 10:47. Reason: PS
GPhoenix97 is offline
Kolapsicle
Senior Member
Join Date: Oct 2014
Old 05-01-2019 , 06:58   Re: Stopping/pausing plugin execution & threaded queries
Reply With Quote #2

You can use SetFailState to stop your plugin if an important component fails such as a database. In regards to your second question, if you are looking to run additional logic alongside your base plugin then I'd suggest looking into forwards.

Edit: I haven't dealt with forwards much at all, but I thought I'd give "overriding" a go and it seems to work well. I'm not sure if this is the best way to go about it, though.
Spoiler

Last edited by Kolapsicle; 05-01-2019 at 07:36. Reason: Added forward example
Kolapsicle is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 05-01-2019 , 07:50   Re: Stopping/pausing plugin execution & threaded queries
Reply With Quote #3

PHP Code:

Database hDatabase
;

public 
void OnPluginStart()
{
    
Database.Connect(OnDatabaseConnection"time");
}

public 
void OnDatabaseConnection(Database db, const char[] errorany data)
{
    if (
db)
    {
        
hDatabase db// or delete db if you dont need a global variable with this db
    
}
    else
    {
        
LogError("Could not connect to the database: %s"error);
        
SetFailState("Could not connect to the database.");
    }

once connected, you are always connected to that db, even if your sql server is down for certain time.
__________________

Last edited by Ilusion9; 05-01-2019 at 07:51.
Ilusion9 is offline
GPhoenix97
Member
Join Date: Oct 2012
Location: Poland
Old 05-01-2019 , 10:45   Re: Stopping/pausing plugin execution & threaded queries
Reply With Quote #4

Quote:
Originally Posted by Kolapsicle View Post
You can use SetFailState to stop your plugin
Wow. Thank you. That's embarrassing for me not to know such an elementary thing.
Quote:
Originally Posted by Kolapsicle View Post
I'd suggest looking into forwards.
Yeah, I was thinking about using forwards but it didn't go well for me. I'll give it a second try, thanks.
Quote:
Originally Posted by Ilusion9 View Post
once connected, you are always connected to that db, even if your sql server is down for certain time.
Oh my, didn't know about that. That can cause some problems. Gotta make a fail-safe for that. Thanks.
__________________
GPhoenix97 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:07.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode