Back

[SOLVED] Prevent cheater from spam execute function

  • 1
  • Functions
D5
2 Jun, 2023, 14:12

@huylv What's the SDK you're using?

TL;DR
User is seeking help to prevent a cheater from spam executing a function. It is suggested to create a lock collection and use it to ensure only one execution at a time. The user also asks for help with an error related to a missing configuration file. A solution is provided to list executions using the correct syntax. The user is asked about the SDK they are using for further assistance. The issue is marked as solved.
huylv
2 Jun, 2023, 14:15

I used "node-appwrite": "^9.0.0" to write cloud functions

D5
2 Jun, 2023, 14:17

Then you should list executions this way:

TypeScript
const promise = functions.listExecutions('[FUNCTION_ID]');

promise.then(function (response) {
    console.log(response);
}, function (error) {
    console.log(error);
});
huylv
3 Jun, 2023, 01:51

my implementation:

TypeScript
const executions = await Appwrite.functions.listExecutions(createOrderFunctionId, [
      Query.equal("status", "waiting"),
      Query.equal("status", "processing"),
    ])

they are the same @D5

huylv
3 Jun, 2023, 02:02

what wrong with my query?

Guille
3 Jun, 2023, 02:13

Check if there is any log in the container: appwrite-worker-functions

huylv
3 Jun, 2023, 02:46

I found this log about this function

Guille
3 Jun, 2023, 02:55

what about docker compose logs appwrite?

huylv
3 Jun, 2023, 03:04

error no configuration file provided: not found

Guille
3 Jun, 2023, 03:11

can you show the complete log?

huylv
3 Jun, 2023, 03:12

there is no log, docker compose logs appwrite show that error

huylv
3 Jun, 2023, 03:13
huylv
3 Jun, 2023, 04:03

If there is no solution, it's hard to use appwrite on production 😦

D5
3 Jun, 2023, 20:47

Did you have set in your appwrite instance an API key?

D5
3 Jun, 2023, 21:31

I will also need to do a similar implementation

Drake
3 Jun, 2023, 23:17

You essentially need to create a lock. You can do this by creating a locks collection. When a user executes the create order function, it'll create a document in the locks collection with ID of the user. If the document is created successfully, it'll continue to process the order. Before the function finishes, it must delete the document to release the lock.

D5
4 Jun, 2023, 07:10

Seems like the other functions will get executed before the document has been created.

Drake
4 Jun, 2023, 15:57

What do you mean?

D5
4 Jun, 2023, 16:12

The user is checking if an element already exists in database, I think that should not be different from creating a lock collection. The problem is that the first function creates the element so other run simultaneously will not "see" the firstly created document.

Drake
4 Jun, 2023, 16:18

I wasn't suggesting to check for a document. The first execution will create the document. If another execution tries to run at the same time, the create document will fail so the function will exit

D5
4 Jun, 2023, 16:37

@huylv Then try this

D5
4 Jun, 2023, 16:37

I will try too next week

huylv
7 Jun, 2023, 02:05

I tried and it worked as expected. Thanks Steven and D5, but is this a formal way to achieve this. I though Database transaction is the solution for almost project

Drake
7 Jun, 2023, 02:14

feel free to 👍🏼 this issue for transactions: https://github.com/appwrite/appwrite/issues/2788

huylv
7 Jun, 2023, 03:01

[SOLVED] Prevent cheater from spam execute function

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more