Elon Report Posted May 2, 2022 Posted May 2, 2022 I'm trying to move away from accessing the custom databases directly since I discovered APIs. I find the API useful for creating a new record, but I need help with the terminology for what I need to do or use for the following scenario. I have a custom table that hosts a schedule. I'd like to be able to request a task from that schedule. Using API I would send off request for all records, calculate the task myself, then send an API back to the schedule to lock it so it's not given again. There may be several parsers accessing this table, so I don't want the same two tasks sent out. Is there a way I can move the process from my parser to the forum? Send off one API that calculates and locks the record, returning the task?
Marc Posted May 2, 2022 Posted May 2, 2022 I will move this to our developer connection forum, which is more appropriate for the request there. I would say however that our API would not interact with your own custom tables.
Elon Report Posted May 2, 2022 Author Posted May 2, 2022 1 hour ago, Marc Stridgen said: I would say however that our API would not interact with your own custom tables. I believe this will work: A GET to https://my.url/api/cms/records/{database_id} pulling a single record sorted by your system. A POST to https://my.url/api/cms/records/{database_id}/{record_id} to lock that record. When completed, a second POST to unlock record and update the record for next sort/get. Is there a way I can POST the lock at the same time I GET the record information?
Hatsu Posted May 2, 2022 Posted May 2, 2022 Do you have your own custom table or a custom table created by the Pages application? The API is for the Pages application and not custom tables you created outside the suite.
Elon Report Posted May 2, 2022 Author Posted May 2, 2022 10 hours ago, Hatsu said: Do you have your own custom table or a custom table created by the Pages application? The API is for the Pages application and not custom tables you created outside the suite. I use the term custom table because that's what I see in the database. But it is created by the Pages application; it has all the standard columns in addition to the ones I need. GO OILERS!
Hatsu Posted May 3, 2022 Posted May 3, 2022 Okay, then it should work. I just asked because Marc refered to my first sentence. For your initial question: this could work if you use the right point to plugin. But I don't know which one this is.
Sonya* Posted May 3, 2022 Posted May 3, 2022 (edited) @MartinLawrence this sounds like something I have made recently. I have created a custom database in Pages, where records are set to be future published. This database is visible for admin only, so no impact on content presented to your users. It is just a schedule. Once the record is published (this is done automatically by IPS via cron), the method onPublish() is executed. You can hook into this method to add your tasks. The hook is executed only, when the records are published, once they are published, the hook is not triggered, so no need to lock something. Probably it helps. Edited May 3, 2022 by Sonya*
Elon Report Posted May 4, 2022 Author Posted May 4, 2022 (edited) 21 hours ago, Sonya* said: @MartinLawrence the record is published (this is done automatically by IPS via cron), the method onPublish() is executed. You can hook into this method to add your tasks. The hook is executed only, when the records are published, once they are published, the hook is not triggered, so no need to lock something. This was not a feature I was aware of either - webhooks. 🙂 But no, that won't work for me. There is a set number of records and I just edit the values in the records. When I say "lock", I mean the record will not be offered to another parser. I need to re-word I guess. I think I have a solution. Parser will GET to https://my.url/api/cms/records/{database_id} pulling all records in the table, not locked(reserved) for another parser. Parser will figure out which record it wants to work on. Parser will POST to https://my.url/api/cms/records/{database_id}/{record_id} locking the record. This will prevent it from being offered to others. My question is: Will the POST return an error if I try to lock it and it is already locked? If it just locks the record a second time, that obviously won't work for me. Edited May 4, 2022 by MartinLawrence
Hatsu Posted May 4, 2022 Posted May 4, 2022 Can you just not check if the record is already locked in step 2 or just get the records which aren't locked?
Elon Report Posted May 4, 2022 Author Posted May 4, 2022 12 hours ago, Hatsu said: Can you just not check if the record is already locked in step 2 or just get the records which aren't locked? How can I do anything with an API other than GET or POST? That's what I'm trying to figure out. I can't allow the system to give out the same record twice.
Hatsu Posted May 5, 2022 Posted May 5, 2022 My guess is no, no error message. That's why I suggested to check beforehand, not with the API but with your own method. I don't know your use case, though. I don't know you many records you pull and how long the process in step 2 takes and if perhaps temporarely locking those records (with a seperate field) is an option.
Elon Report Posted May 8, 2022 Author Posted May 8, 2022 I decided what I am going to do. Parser will GET to https://my.url/api/cms/records/{database_id} pulling all records in the table, not locked(reserved) for another parser. Parser will figure out which record it wants to work on. Parser will GET to https://my.url/api/cms/records//{database_id}/{record_id} to see if the record is still unlocked. Parser will POST to https://my.url/api/cms/records/{database_id}/{record_id} locking the record. This will prevent it from being offered to others. There may be a chance another parser locks the record between step 3/4, but I can code to minimize that. There would be no more than a few parsers running and the tasks can take many minutes. Hatsu 1
Recommended Posts