Created
July 30, 2014 17:25
-
-
Save pedrokoblitz/24b9795623debb51fc01 to your computer and use it in GitHub Desktop.
mysql queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table jobs( | |
id auto_increment not null primary key, | |
message text not null, | |
process_id varbinary(255) null default null, | |
key jobs_key(process_id) | |
); | |
# queue | |
insert into jobs(message) values('blah blah'); | |
# dequeue | |
begin; | |
select * from jobs where process_id is null order by id asc limit 1; | |
update jobs set process_id = ? where id = ?; -- whatever i just got | |
commit; | |
# return (id, message) to application, cleanup after done | |
# OR | |
# queue | |
UPDATE jobs SET process_id = ? WHERE process_id IS NULL ORDER BY ID ASC LIMIT 1; | |
# dequeue | |
SELECT * FROM jobs WHERE process_id = ? [ORDER BY ID LIMIT 1]; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment