Skip to content

Commit

Permalink
Merge pull request #370 from sni/improve-store-queue-on-shutdown
Browse files Browse the repository at this point in the history
Skip removing entries upon job completion and truncate the jobs database table after restart if --store-queue-on-shutdown is used on SQLite
  • Loading branch information
esabol authored Jun 19, 2023
2 parents a6c5ad7 + 120fb35 commit 15bd982
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions libgearman-server/plugins/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ class Context {
_store_on_shutdown= store_on_shutdown_;
}

bool is_store_on_shutdown()
{
return _store_on_shutdown;
}

bool has_error()
{
return _error_string.size();
Expand Down
18 changes: 16 additions & 2 deletions libgearman-server/plugins/queue/sqlite/instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ gearmand_error_t Instance::done(gearman_server_st*,
const char *function_name,
size_t function_name_size)
{
if (is_store_on_shutdown())
{
return GEARMAND_SUCCESS;
}

gearmand_log_debug(GEARMAN_DEFAULT_LOG_PARAM,
"sqlite done: unique_key: %.*s, function_name: %.*s",
int(unique_size), (char*)unique,
Expand Down Expand Up @@ -593,6 +598,17 @@ gearmand_error_t Instance::replay_loop(gearman_server_st *server)
"failed to reset REPLAY prep statement: %s", sqlite3_errmsg(_db));
}

/* truncate database now if in store_on_shutdown mode */
if (is_store_on_shutdown())
{
std::string query("DELETE FROM ");
query+= _table;
if (_sqlite_dispatch(query) == false) {
return gearmand_log_gerror(GEARMAN_DEFAULT_LOG_PARAM, GEARMAND_QUEUE_ERROR,
"failed to truncate table: %s", sqlite3_errmsg(_db));
}
}

if (row_count == 0)
{
return GEARMAND_SUCCESS;
Expand All @@ -603,5 +619,3 @@ gearmand_error_t Instance::replay_loop(gearman_server_st *server)

} // namespace queue
} // namespace gearmand


2 changes: 1 addition & 1 deletion libgearman-server/plugins/queue/sqlite/queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Sqlite::Sqlite() :
{
command_line_options().add_options()
("libsqlite3-db", boost::program_options::value(&schema), "Database file to use.")
("store-queue-on-shutdown", boost::program_options::bool_switch(&_store_on_shutdown)->default_value(false), "Store queue on shutdown.")
("store-queue-on-shutdown", boost::program_options::bool_switch(&_store_on_shutdown)->default_value(false), "Store queue on shutdown only.")
("libsqlite3-table", boost::program_options::value(&table)->default_value(GEARMAND_QUEUE_SQLITE_DEFAULT_TABLE), "Table to use.")
;
}
Expand Down

0 comments on commit 15bd982

Please sign in to comment.